Create Table in SQL Server Syntax MS SQL

Create table in SQL server database and insert data, learn Create SQL Table syntax, in this tutorial will learn Table in SQL Database, Here we learn database with a practical example.

So, just think of some business requirement, and you will learn how to develop SQL Table and manipulate data as per business requirement.

CREATE TABLE [schemaName].[tableName](            
    [IdColumnName] [bigint] IDENTITY(1,1) NOT NULL,
    [Columnname2] [varchar](50)  NOT NULL,    
    [Columnname3] [datetime] NULL    
)
Recruitment:

We want to create a SQL Table where all students’ data will be stored, so whenever a student joins this training course their Name, email, date of birth, contact number, joining date, address, and course complete date will be captured

How to ceate table in SQL Database

Here we have written a create table sql query, notice the illustration , you can see how to write table name, column name, data type of column, null or not null, identity column and primary key etc.

how to ceate table in sql database

Create table query same as above

CREATE TABLE [dbo].[tbStudent](            
    [studentId] [bigint] IDENTITY(1,1) NOT NULL,
    [FullName] [varchar](50)  NOT NULL,
    [Address] [varchar](150)  NULL,
    [email] [varchar](100)  NULL,
    [contactnumber] [varchar](50)  NULL,
    [DOB] [datetime] NULL,
    [updatedon] [datetime] NULL,
    [courseCompleteDate] [datetime] NULL,
    [joiningDate] [datetime] NULL,
    CONSTRAINT [PK_tbStudent] PRIMARY KEY CLUSTERED            
    (
    [studentId] ASC
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

If you want to create table under different schema, other than default dbo, you need to specify the schema name, for example if I want the table to be created under student schema, then write query like CREATE TABLE [student].[tbStudent]( [studentId] [bigint] IDENTITY(1,1) NOT NULL ) , but make sure you have appropriate right on that schema.

Things to remember while creating a table
  • Table name must be unique; you can't have two tables with same name.
  • Column name in a table must be unique; two columns name cannot be same.
  • One table can have single or composite primary key
  • Primary key not necessarily will have IDENTITY (1, 1) seed, (but most of the time have)
How to insert data into SQL table
INSERT INTO [tableName] (columnName1, columnName2) values (value1, value2)
INSERT INTO [tbStudent]
([FullName]
,[Address]
,[email]
,[contactnumber]
,[DOB]
,[updatedon]
,[courseCompleteDate]
,[joiningDate])
VALUES
    ('Bill Zuckerberg'
    ,'Mumbai, India'
    ,'webtrainingroom@gmail.com'
    ,'9800000012'
    ,'09/10/1990'
    ,getdate()
    ,'10/10/2019'
    ,getdate())
SQL Temp Table

While working with data manipulation, we sometimes need a table that can hold some temporary data, so instead of creating a physical table, we create a temp table or temporary table.

You may learn more about SQL Temp Table and Table variable

 
Hire SQL Developer
Create SQL Table in SQL Database
SQL Training: For any group or corporate training, please contact us at webtrainingroom(at)gmail.
SQL job Interview Questions Answers
Course in Demand
SQL database development tutorials for learning sql query, data manipulation language, working with MS SQL Server.
MS SQL Examples | Join MS SQL Course