How to create a table in SQL?
In order to create a table, you can use the “CREATE TABLE” command in SQL.
Here is a simple example showing how to create a table named “students” with two columns, “id” and “name”:
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(50)
);
In the example above, the first line specifies the name of the table as “students”. The next two lines each specify a column in the table. The first column is named “id”, the data type is INT, and it also includes a PRIMARY KEY constraint, indicating that this column is the primary key of the table. The second column is named “name”, the data type is VARCHAR(50), indicating that this column stores strings with a maximum length of 50 characters.
When actually creating tables, you can specify additional columns and constraints as needed, such as adding FOREIGN KEY constraints or setting default values for columns. The specific syntax and available options may vary depending on the database system, so you can refer to the documentation of the particular database for more details.