INSERT (T-SQL)

Insert Statement in SQL SERVER adds one or more rows to a table or a view.

Syntax 1:
INSERT INTO TableName(Column1 , Column2 , Column3….)
VALUES (Column1Value , Column2Value , Column3Value);
Here Column1, Column2, Column3 etc… represents the column name in the table into which we want to insert the data.
Example: Let say I want to add Employee’s Id, Name, Date Of Birth and Salary into table called dbo.Employee.

INSERT dbo.Employee(Id , Name , DateOfBirth , Salary)
VALUES(1 , ‘John Smith’ , ‘1998-12-24’ , 50000);

Syntax 2:
INSERT INTO TableName(Column1 , Column2, Column3….)
SELECT SourceColumn1 , SourceColumn2, SourceColumn3
From SourceTableName
According to syntax 2, we can insert all or certain columns from SourceTableName.


Leave a comment