2015. 6. 7. 19:19

http://www.w3schools.com/


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


The SQL INSERT INTO Statement

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

SQL INSERT INTO Syntax

It is possible to write the INSERT INTO statement in two forms.

The first form does not 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,...);

INSERT INTO Example

Assume we wish to insert a new row in the "Customers" table.

We can use the following SQL statement:

Example

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal','Tom B. Erichsen','Skagen 21','Stavanger','4006','Norway');

Try it yourself »


NoteDid you notice that we did not insert any number into the CustomerID field?
The CustomerID column is automatically updated with a unique number for each record in the table.

Insert Data Only in Specified Columns

It is also possible to only insert data in specific columns.

The following SQL statement will insert a new row, but only insert data in the "CustomerName", "City", and "Country" columns (and the CustomerID field will of course also be updated automatically):

Example

INSERT INTO Customers (CustomerName, City, Country)
VALUES ('Cardinal', 'Stavanger', 'Norway');

Try it yourself »

The selection from the "Customers" table will now look like this:

'SQL' 카테고리의 다른 글

DELETE  (0) 2015.06.07
UPDATE  (0) 2015.06.07
ORDER BY  (0) 2015.06.07
ND & OR Operators  (0) 2015.06.07
WHERE Clause  (0) 2015.06.07
Posted by Name_null