Create Table in SQL Server using Query or Management Studio

  Total Views : 447
  Comments : 0
 
  Keywords : How to create table in sql server using query, Create table statement in sql server, Create tables using sql server management studio, MS sql server create table using create table statement

Here we will learn how to create tables in sql server databases. Generally we can create tables in sql server using queries and sql server management studio.

SQL Server Create Table using Query or Management Studio

To create SQL Table we have two different methods one is using Query like “CREATE TABLE TABLENAME etc…” and another one is directly using SQL Server Management Studio

Using Query to Create SQL Table

By using “Create TABLE” statement we can create SQL TABLE. Generally to create table in SQL our syntax will be like as shown below

Syntax to Create SQL TABLE using Query

Following sql statement is the syntax to create table in sql server

 

CREATE TABLE tablename(

columnname1 datatype NOT NULL,

columnname2 datatype(size) NULL,

columname3 datatype(size) NULL,

.......

.......

columnnameN datatype(size) NULL

)

If you observe above syntax we have different type of parameters. 

 

tablename: It means name of the table which we are going to create in database

 

columnname: it means name of the column which we are going to create 

 

datatype: it is used to specify type of data which are we going to insert in columns (Ex: int, varchar, datetime, float, etc…) 

 

size: It means maximum size of data which we can insert in columns

 

NULL: It means allow users to insert null values in column

 

NOT NULL: It means it will not allow user to insert null values in column 

Create SQL Table using Query Example

The following SQL statement will create new table “EmployeeDetails” with columns empid, empname, designation, salary, location and joineddate

 

CREATE TABLE EmployeeDetails

(

empid int NOT NULL,

empname varchar(50) NULL,

designation varchar(50) NULL,

salary int NOT NULL,

location varchar(50) NULL,

joineddate datetime NULL

)

Here empid and salary columns are int datatype and it will expect only integer values and empname, designation, location columns are varchar datatype it will expect maximum of 50 characters and joineddate column is datetime datatype it will expect datetime format values.

 

Once we create table try to run following SQL select query to get details from “EmployeeDetails” table

 

SELECT * FROM EmployeeDetails

Now our sql table will be like as shown below

 

Crete New table in SQL Server Database using Query Result

 

You can check this “EmployeeDetails” table in SQL Server management studio under your database section like as shown below

 

SQL Server Newly Created Table in Database Output

Create SQL Table using SQL Server Management Studio

To create new table in database open SQL Server Management Studio --> Open Databases section --> Select Required Database to create table --> Right click on Tables section and Select New Table like as shown below 

 

Create new table using sql server management studio

 

Whenever we click on “New Table” it will open new window in that create table by entering column name, datatype and allow null options like as shown below

 

SQL Create new table by entering column name, datatype and null values

Once we enter all the fields click save option available on top or press Ctrl + S to save table details whenever we press save or Ctrl + S option it will ask you for table name give your table name and click OK to create new table in database. 

 

To check newly created table open databases --> select your database --> Right Click and Select Refresh Option to refresh database --> Now check it in Tables section that would be like as shown below

 

SQL Server Newly Created Table in Database using SQL Management Studio Output

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User