The SQL CREATE TABLE statement is used to create a new table. Creating a table involves providing a name to the table and defining name and data type (e.g. varchar, integer, date, etc.) of each column.
The syntax of the CREATE TABLE statement is given below:
CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, ..... PRIMARY KEY(one or more columns) );
The below mentioned SQL code creates a table called Employee which contains five columns: EmpID, Name, City, Age and Salary.
CREATE TABLE Employee ( EmpID INT NOT NULL, Name VARCHAR(255) NOT NULL, City VARCHAR(100), Age INT, Salary DECIMAL(18,2), PRIMARY KEY(EmpID) );
This will create a empty table named Employee containing five columns as shown below:
When the table is created successfully it displays a message. Along with this, it can also be checked using DESC command as follows:
This indicates that the Employee is now available in the database which can be used to store information related to employee.