Sunday, October 2, 2016

Create table in SQL Server - Syntax

Create table in SQL Server - Syntax

It is very simple to create table in sql server. Create table syntax is used to create table in sql server. Tables in sql server contains columns an rows which contains records. 

Syntax - 

Create Table TableName
(
ColumnName1 data_type(size) Primary Key,
ColumnName2 data_type(size) NOT NULL,
ColumnName3 data_type(size) NOT NULL,
ColumnName4 data_type(size) NOT NULL,
......
......
);

Here, the ColumnName1ColumnName2 , ColumnName3 and  ColumnName4 specifies the name of column in table, data_type specifies the type of  the record that column holds, size specifies the maximum length of the column in table and NOT NULL means column does not hold null value.

For example -

CREATE TABLE Employees
(
  Emp_Id  INT PRIMARY KEY,
  First_Name VARCHAR(50),
  Last_Lame VARCHAR(50) NOT NULL,
  Salary MONEY
);