SQL Strategy - A site to master SQL while executing it on the Web
Home >> SQL Strategy - Adding a record INSERT statement

Adding a record INSERT statement

The INSERT statement is used to add new rows to a Table.

1. add a record with a specified value

--INSERT statement syntax (1)
INSERT INTOTable Name (column name,column name...)
VALUES(value,value...)

When using the INSERT statement, the Table Name is listed after INSERT INTO and the column names are separated by commas in the parentheses after the INSERT INTO. The values to be added to the record are listed in parentheses after VALUES, with the values separated by commas. If the value is a string, it must be enclosed in quotation marks.

INSERT INTOEMP (EMPNO,NAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES(9999,'SAN','SALESMAN',7698,1981-09-28,1000,500,10)

When adding values to all items in a Table, column names can be omitted and are written as follows.

INSERT INTOEMP
VALUES(9999,'SAN','SALESMAN',7698,2004-06-24,1000,500,10)

To set values for some items, enter the name of the item to store the value to be added after the Table Name as shown below, and enter the value to be added in VALUES.

INSERT INTOEMP (EMPNO,ENAME)
VALUES(9999,'SAN')

2. Add selected records from another Table

--■INSERT statement syntax (2)
INSERT INTOEMP_TEMP
SELECT *
FROM EMP
WHERE JOB = 'SALESMAN'

By changing the VALUES keyword into a SELECT statement, it is possible to add selected records from another Table to the Table.

This completes the [ ADD RECORD INSERT statement ].