SQL Server Insert Query

INSERT Statement

INSERT Statement is used to insert rows in the database table.

INSERT Statement Syntax

INSERT [INTO]{table_name} [(column1, column2, ...)]
VALUES {DEFAULT | (value1, value2, ...) | SELECT Statement

INTO is optional keyword.

table_name is the name of the database table into which data is to be inserted.

column names are optional parameter which can be used when inserting partial data for rows.

DEFAULT is the clause that can be used to insert the default value is specified for the column.

Value list is the values for the table columns that have to be inserted as a row in the table.

SELECT Statement can be used to insert a row(s) into the table. SELECT Statement can be nested here.

Insert row in the table

here row is inserted with specified values of all the columns for Department table.
INSERT Department
VALUES (1, 'Department1', 'head1')

Insert row with columns

Insert a row into the Department table with columns name specified in the INSERT Statement.
INSERT Department (Id, Name, Head)
VALUES (2, 'Department2', 'head2')
Insert a row into the Department table with columns sequence and the column values in the INSERT and VALUES clause respectively.
INSERT Department (Name, Head, Id)
VALUES ('Department3', 'head3', 3)
Insert a row into the Department table with columns name specified with specifying NULL or DEFAULT value.
INSERT Department (Id, Name, Head)
VALUES (4, 'Department4', NULL)
INSERT Department (Id, Name, Head)
VALUES (5, 'Department5', DEFAULT)

Insert Partial Row Data

SQL Server supports to insert data for some columns in the row.
INSERT Department (Id, Name)
VALUES (5, 'Department5')
here Head column is not specified because which can be NULL.

Insert Row with IDENTITY Column

if any column is IDENTITY then no need to specify that column and value in INSERT statement.
INSERT Employee (Name, DeptId, Email)
VALUES ('Employee2', 2, 'employee2@test.com')

Insert Row Guidelines

  • Number of values must be same as number of columns in the table or columns specified in the insert statement.
  • Order of columns and values specified in INSERT Statement must be same.
  • Data type must be same value specified for corresponding column.

Few More INSERT Queries

INSERT INTO Employee (Name, DeptId, Email, Salary, City, Country)
VALUES ('Employee1', 1, 'employee1@test.com', 8000, 'BOSTAN', 'US')

INSERT INTO Employee (Name, DeptId, Email, Salary, City, Country)
VALUES ('Employee2', 1, 'employee2@test.com', 5000, 'NEYWORK', 'US')

INSERT INTO Employee (Name, DeptId, Email, Salary, City, Country)
VALUES ('Employee3', 2, 'employee3@test.com', 9000, 'CHENNAI', 'INDIA')

INSERT INTO Employee (Name, DeptId, Email, Salary, City, Country)
VALUES ('Employee4', 1, 'employee4@test.com', 6000, 'BANGALORE', 'INDIA')



Python installation

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^