articles

Home / DeveloperSection / Articles / How to create table in SQL Server

How to create table in SQL Server

Sachindra Singh4757 12-Feb-2011

As a user, you need to create tables to store data in database. While creating the tables in database, you have to follow specify certain rules and constraints for columns that specify the kind of data to be stored.

You can create table by using the CREATE TABLE statement as well as GUI MODE as shown below:
CREATE TABLE statement
 Create table "tablename"
(
 "ColumnName1" "data type",
 "ColumnName2" "data type",
 "ColumnName3" "data type"
);
 
Createtable EmplyoeeDetail
(
      Id char(4),
      Name varchar(20),
      City varchar(20),
      Age varchar(20)
)

Before executing Create table statement you have to specify in which database you want to create your table as shown below:

How to create table in SQL Server

In screen shot you can see table is creating in Detail database, it means you have to specify database before executing create table statement.

After database selection select all table statement and then press F5 and also can click on Execute button as shown below:

How to create table in SQL Server

After click on Execute button “Command(s) completed successfully”message will display on Message window and table has created in Detail database as show below:

How to create table in SQL Server

When we want to see the table columns and records you have to select database from database list where table is stored and write simple query and result will display in result window as shown below:

select*from EmplyoeeDetail

How to create table in SQL Server

In screen shot Result window showing only column name because table has no record this time.

GUI MODE
Step:

Open the SQL Server in  the Object Explorer Click on the  Databases folder Then click on the  System Databases folder Select database where table want to create Right click on the  Tables folder Select New Table as shown below:

How to create table in SQL Server

When clicked on the New Table, table creation window will be visible as shown below:

How to create table in SQL Server

In Column Name you have to pass column name as well as you have to specify Data Type of field, in Allow Nulls column if click on the check box it will allow null in specify column than right click on the tab menu and click on the Save Table_1 and pass your table name.

 

 


Updated 07-Sep-2019

Leave Comment

Comments

Liked By