You are currently viewing How To Create Alter and Drop Table in SQL Server

How To Create Alter and Drop Table in SQL Server

A table is just like a container of data in the form of rows and columns. Tables are database objects that contain data in the database.

The rows run horizontally and represent each record. The columns run vertically and represent a specificĀ field. The rows and columns intersect, forming a grid. The intersection of the rows and columns definesĀ each cell in the table.

A standard user-defined table can have up to 1,024 columns. The number of rows in the table is limited only by the storage capacity of the server.

How to Create TABLE in SQL Server?

A table can be created in a database by using SQL Server Management Studio GUI(Graphical User Interface) or by using T-SQL.

CREATE TABLE Using T-SQL

CREATE TABLE is used to create the table, tblEmplyee is the name of the table, then we enclose all the fields/columns along with data type and constraints(optional) within round braces.
EmpID INT PRIMARY KEY is the first column, INT is the data type and PRIMARY KEY is the constraint,
EmpFirstName is the second column, NVARCHAR(20) is the data type and NOT NULL is the constraint

EmpLastName is the third column, NVARCHAR(20) is the data type and in this column constraint is NULL, which is default constraint
and so on…

CREATE TABLE Using SQL Server GUI(Graphical User Interface)

  • Open SQL Server Management Studio and click on connect.
  • Expand Databases, Expand HR database(for this demo) and right click on Tables go to New and click on Table.
  • A table design will open with three columns (Column Name, Data Type and Allow Nulls), Where you fill it with required fields as shown in the image below.
  • Now to make the EmpID as the Primary Key, right-click on the arrow button on the left side of EmpID column and select Set Primary Key.
  • Now, to save the table, right-click on the dbo. Table_1 tab and click on Save Table_1.
  • Change the table name, tblEmployee and click on OK button.
  • Table name will be changed and saved, now you can see in the Object explorer in HR database under Tables.

Recommended Readings