The SQL INSERTO Statement:

The INSERT INTO SQL statement is used to insert a new row into a table.

Syntax:

INSERT INTO table name VALUES (value1, value2,…….)

You can also select specify columns for which you want to insert data:

Syntax:

INSERT INTO table name (column1, column2,…..)

VALUES (value1, value2,…….)

Example:

Using ‘UserInfo’ Table

LastName FirstName Address City Year
Hansen Ola Timoteivn 10 Sandnes 1951
Svendson Tove Borgvn 23 Sandnes 1978

Query:
INSERT INTO UserInfo VALUES (‘Hetland’, ‘Camilla’, ‘Hagabakka 24’, ‘Sandnes’,1980)

The Result:

LastName FirstName Address City Year
Hansen Ola Timoteivn 10 Sandnes 1951
Svendson Tove Borgvn 23 Sandnes 1978
Hetland Camilla Hagabakka 24 Sandnes 1980

INSERT Data in Specified Column:

You can also insert data in a particular column.

Example:

Using ‘UserInfo’ Table

LastName FirstName Address City Year
Hansen Ola Timoteivn 10 Sandnes 1951
Svendson Tove Borgvn 23 Sandnes 1978

Query:

INSERT INTO UserInfo (LastName, Address) VALUES (‘Rasmussen’, ‘Storgt 67’)

The Result:

LastName FirstName Address City Year
Hansen Ola Timoteivn 10 Sandnes 1951
Svendson Tove Borgvn 23 Sandnes 1978
Rasmussen Storgt 67

Leave a Reply

Your email address will not be published. Required fields are marked *