SQL INSERT INTO

The SQL INSERT INTO statement allows us to add new row(s) into a table. The INSERT INTO Statement consists of two clauses: INSERT clause and VALUES clause.INSERT clause is used to specify the name of the table and columns to which data to be inserted and VALUES clause is used to specify the data values to be inserted into the table.


Consider the following table structure of the table Item.

SQL INSERT INTO

There are two basic forms are available for INSERT INTO statement in SQL.

Syntax-1: INSERT INTO table_name values(Value1, Value2, Value3,………… ValueN)
To insert a row into a table with all column values.

Example: INSERT INTO Item values('I1','RAM', 500,40)

Syntax-2: INSERT INTO table_name(Column1, Column 2, Column 3,………… Column N)  values(Value1, Value2, Value3,………… ValueN)
To insert a row into a table with the column name specified in the INSERT clause.

Example: INSERT INTO Item(ItemCode,ItemName,Price,QOH) values('I2','Printer', 4000,20)

SQL Server allows us to insert partial data into a table, for a column that allows NULL or has a DEFAULT assigned to it. Use following INSERT statement to insert partial data into the Item table:

INSERT INTO Item(ItemCode,Price,QOH) values('I3', 4500,10)

Finally, we will get following output by executing the SELECT statement: SELECT * from Item.

SQL INSERT INTO