Whenever we want to store our data into the database the initial step involves creating a table. The CREATE TABLE statement in SQL is used to create a new table. As already discussed, a table consists of rows and columns, while creating a new table we need to provide all the details like Table name, name of the columns, type of data to be stored in columns, size of the data etc.
CREATE TABLE : keyword used to create a table in a database.
Tablename : The name of the table which we are going to create.
Column1Name, Column2Name : The name of the columns to be added to the table.
Datatypes : Data types specify the type of data that should be used for a column.
Ø Example1 : If a column called "Address", is to be used to hold addresses, then that column should have a "varchar" (variable-length character) data
Ø Example2 : If a column called "CustomerId", is to be used to hold unique CustomerIds, then that column should have an "INT" (Integer) data type.
[NULL/NOTNULL] : A column can have NULL or NOTNULL Values; this can be specified whenever we are creating a table. If we don't specify, SQL Server will take NULL as the default.
Let’s understand the concept of “Create Table” by creating a simple table Persons.
On executing this query, we get the following result set:
Want More SQL Deep Dives