To create a table in SQL, you use the CREATE TABLE statement followed by the table name and the list of columns and their data types.
Here is the syntax:
CREATE TABLE table_name ( column1 datatype(size), column2 datatype(size), column3 datatype(size), ... );
For example, if you want to create a table named
students with columns
gender, you can use the following SQL statement:
CREATE TABLE students ( id INT PRIMARY KEY, name VARCHAR(50), age INT, gender CHAR(1) );
id column is defined as an
INT data type with a
PRIMARY KEY constraint, which means it will be the unique identifier for each record in the table.
name column is defined as a
VARCHAR with a size of 50 characters,
CHAR with a size of 1 character.
It’s important to carefully choose the data types for each column, as this will affect how data is stored and retrieved in the table. You can use different data types such as
DECIMAL, etc. based on the type of data you need to store.
Once you have executed the CREATE TABLE statement, a new table with the specified columns and data types will be created in the database. You can then use INSERT statements to add data to the table.