The INSERT clause is to allows you insert a single record or multiple records into a table. INSERT clause is used together with INTO.
The INSERT clause syntax will look like this:
INSERT INTO [TABLE NAME]
VALUES ([VALUE 1], [VALUE 2], ...)
Or we can state out the columns that you want to enter the data to. like:
INSERT INTO [TABLE NAME] ([COLUMN 1], [COLUMN 2], �.)
VALUES ([VALUE 1], [VALUE 2] , ...)
EXAMPLE :
We can try to insert data to the table below.
Table GameScores
PlayerName | Department | Scores |
Jason | IT | 3000 |
Irene | IT | 1500 |
Jane | Marketing | 1000 |
David | Marketing | 2500 |
Paul | HR | 2000 |
James | HR | 2000 |
SQL statement :
INSERT INTO GameScores
VALUES ('Vivian','Marketing',2500)
After execute the SQL command. The table will look like like this. Row which is highlighted with Yellow is the data that been inserted.
Table GameScores
PlayerName | Department | Scores |
Jason | IT | 3000 |
Irene | IT | 1500 |
Jane | Marketing | 1000 |
David | Marketing | 2500 |
Paul | HR | 2000 |
James | HR | 2000 |
Vivian | Marketing | 2500 |
Let's try with specified the column to insert:
SQL statement :
INSERT INTO GameScores (PlayerName,Department)
VALUES ('Kenny','HR')
After execute the SQL command. The table will look like like this. Row which is highlighted with Yellow is the data that been inserted.
Table GameScores
PlayerName | Department | Scores |
Jason | IT | 3000 |
Irene | IT | 1500 |
Jane | Marketing | 1000 |
David | Marketing | 2500 |
Paul | HR | 2000 |
James | HR | 2000 |
Vivian | Marketing | 2500 |
Kenny | HR | 0 |
Column that never stated when using the INSERT Statement, It will automatically insert the default value to that column. with this Example, the DEFAULT value for Scores is 0.