(
cot1 kieu_du_lieu [ NULL | NOT NULL ],
cot2 kieu_du_lieu [ NULL | NOT NULL ],
…
);
ten_bang
The name of the table you want to create.
cot1, cot2
The column you want to create in the table. Each column has 1 data type. The column must be defined as NULL or NOT NULL, if left blank, the database will default to NULL.
For example
CREATE TABLE nhanvien
( nhanvien_id INT NOT NULL,
ho VARCHAR(50) NOT NULL,
ten VARCHAR(50),
luong MONEY
);
The CREATE TABLE command above will create a table named nhanvien with 4 columns:
The only problem with this CREATE TABLE statement is that the primary key has not been defined for the table. It is possible to edit a bit and define it as the primary key as follows.
CREATE TABLE nhanvien
( nhanvien_id INT PRIMARY KEY,
ho VARCHAR(50) NOT NULL,
ten VARCHAR(50),
luong MONEY
);
By using the keyword PRIMARY KEY after the nhanvien_id field, SQL Server will retrieve the username as the primary key for the table.
Previous article: Data types in SQL Server
Lesson: Main key PRIMARY KEY in SQL Server