Receive all updates via Facebook. Just Click the Like Button Below

Blogger Widgets
/

Watch Intro About My Website ! ! !

Sunday, 3 November 2013



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

SQL INSERT INTO Syntax

It is possible to write the INSERT INTO statement in two forms.
The first form doesn't specify the column names where the data will be inserted, only their values:


INSERT INTO table_name
VALUES (value1, value2, value3,...)

The second form specifies both the column names and the values to be inserted:


INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

SQL INSERT INTO Example


We have the following "Persons" table:


Id
LastName
FirstName
Address
City
1
Navis
Anto
Madras
TVL
2
Ji
Bala
Bombay
TVL
3
Christopher
Franklin
America
KK

Now we want to insert a new row in the "Persons" table.

We use the following SQL statement:


INSERT INTO Persons
VALUES (4,'Nilsen', 'Johan', 'Bakken 2', 'KK')

The "Persons" table will now look like this:


Id
LastName
FirstName
Address
City
1
Navis
Anto
Madras
TVL
2
Ji
Bala
Bombay
TVL
3
Christopher
Franklin
America
KK
4
Nilsen
Johan
Bakken 2
KK

Insert Data Only in Specified Columns

It is also possible to only add data in specific columns.
The following SQL statement will add a new row, but only add data in the "Id", "LastName" and the "FirstName" columns:


INSERT INTO Persons (Id, LastName, FirstName)
VALUES (5, 'Tjessem', 'Jakob')

The "Persons" table will now look like this:


Id
LastName
FirstName
Address
City
1
Navis
Anto
Madras
TVL
2
Ji
Bala
Bombay
TVL
3
Christopher
Franklin
America
KK
4
Nilsen
Johan
Bakken 2
KK
5
Tjessem
Jakob



Tagged:

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...