A basic Employees
table, containing an ID, and the employee's first and last name along with their phone number can be created using
CREATE TABLE Employees(
Id int identity(1,1) primary key not null,
FName varchar(20) not null,
LName varchar(20) not null,
PhoneNumber varchar(10) not null
);
This example is specific to Transact-SQL
CREATE TABLE
creates a new table in the database, followed by the table name, Employees
This is then followed by the list of column names and their properties, such as the ID
Id int identity(1,1) not null
Value | Meaning |
---|---|
Id | the column's name. |
int | is the data type. |
identity(1,1) | states that column will have auto generated values starting at 1 and incrementing by 1 for each new row. |
primary key | states that all values in this column will have unique values |
not null | states that this column cannot have null values |