Home » T-SQL Create Table

T-SQL Create Table

by Online Tutorials Library

T-SQL Create Table

In T-SQL, we create a table, which has the name of the table and defines the columns and data type of each column.

The CREATE TABLE statement is used to generate the table.


Syntax of CREATE TABLE is below:

In this case, we create a new table. The identifier of the table following the CREATE TABLE statement after that syntax becomes easy to understand.

The copy of existing table creates the combination of CREATE TABLE statement and generate the SELECT statements.


In this example, we are creating an EMPLOYEES table with ID as a primary key and NOT NULL are the constraints showing that these fields cannot be NULL while creating records in the table-

We can verify if our table has been created successfully by looking at the message generated by the SQL server. Otherwise, we can use the below command-

The command produces the given output.

TABLE_QUALIFIER    TABLE_OWNER    TABLE_NAME    COLUMN_NAME    DATA_TYPE    TYPE_NAME  PRECISION   LENGTH   RADIX   SCALE   NULLABLE   REMARKS   COLUMN_DEF   SQL_DATA_TYPE  SQL_DATETIME_SUB    CHAR_OCTET_LENGTH    ORDINAL_POSITION    IS_NULLABLE    SS_DATA_TYPE  TestDBdbo    CUSTOMERS   ID        4    int      10   4    0      10     0     NULL   NULL     4   NULL        NULL   1    NO      56     TestDBdbo    CUSTOMERS   NAME      12   varchar  20   20   NULL   NULL   0     NULL   NULL      12   NULL         20          2    NO          39    TestDBdbo    CUSTOMERS   AGE       4    int      10   4    0      10     0     NULL   NULL        4   NULL     NULL      3    NO     56     TestDBdbo    CUSTOMERS   ADDRESS   1    char     25   25   NULL   NULL   1     NULL   NULL         1   NULL         25           4     YES     39      TestDBdbo    CUSTOMERS   SALARY    3    decimal  18   20   2      10     1     NULL   NULL         3   NULL       NULL      5       YES      106  

We can see that the CUSTOMERS table is available in our database, which we can be used to store the required information related to the customers.

Next TopicT-SQL Drop-Table

You may also like