SQL INSERT INTO Statement

INSERT INTO

SQL INSERT INTO statement is used to add new records in a table.

Syntax 1

You can sequentially insert values into columns according to table structure without mentioning column names.

INSERT INTO TableName

VALUES (value1, value2, …, valueN)

Syntax 2

You can mention specific columns and their values to insert in table.

INSERT INTO TableName (column1, column2, …, columnN)

VALUES (value1, value2, …, valueN)

You can use specific syntax according to your business requirements. We will see couple of examples how to use INSERT INTO statements.

We will use Student table to insert records. You can refer Student table as given below.

StudentTable

SQL query to insert record in Student table is:

INSERT INTO Student 
VALUES (9999, 'Mr.', 'Brian', 'T', 'Lee', 'China')

INSERT INTO

As mentioned above record number 16 is inserted in Student table.

We will take one more example where we will try to insert specific column values for RollNumber, FirstName and LastName.

INSERT INTO Student (RollNumber, FirstName, LastName)
VALUES (8888, 'Chin', 'Xing')

INSERT INTO2

Here we have inserted record number 17, make sure while inserting specific columns, remaining columns are allowing NULL values or constraint is not referencing other table(s).

Reference: Manzoor Siddiqui [www.SQLServerLog.com]

CLICK HERE to watch live practical.

You may also like...

Leave a Reply

Your email address will not be published.