[24] SQL CREATE TABLE Statement
The CREATE TABLE statement is used for creating tables in the database.
Tables consist of rows and columns, and each table must have a table name.
SQL CREATE TABLE Syntax
CREATE TABLE table_name (column_name1 data_type (size), column_name2 data_type (size), Column_name3 data_type (size),....);
The column_name parameter specifies the name of the column in the table.
The Data_type parameter specifies the data type of the column (for example, varchar, integer, decimal, date, and so on).
The size parameter specifies the maximum length of the column in the table.
SQL CREATE TABLE Instance
Now we want to create a table called "Persons" that contains five columns: PersonID, LastName, FirstName, Address, and city.
We use the following CREATE TABLE statement:
Instance
CREATE TABLE the intvarchar(255varchar(255 varchar (255varchar(255));
The data type of the PersonID column is int, which contains integers.
The data types of the LastName, FirstName, Address, and city columns are varchar and contain characters, and the maximum length of these fields is 255 characters.
The empty "Persons" table looks like this:
[24] SQL CREATE TABLE Statement