Home     SQL Basic     Contact Us     Site Map    

SQL BASIC

SQL SELECT

SQL WHERE

SQL DISTINCT

SQL AND

SQL OR

SQL NOT

SQL ORDER BY

SQL IN

SQL BETWEEN

SQL LIKE

SQL ALIAS

SQL AGGREGATE

>SQL COUNT

>SQL SUM

>SQL MAX

>SQL MIN

>SQL AVG

SQL GROUP BY

SQL HAVING

SQL INSERT

SQL UPDATE

SQL DELETE

SQL SELECT INTO

SQL CREATE DATABASE

SQL CREATE TABLE

SQL DROP TABLE

SQL DROP DATABASE

SQL CREATE INDEX

SQL PRIMARY KEY

SQL FOREIGN KEY

SQL ALTER TABLE

SQL TRUNCATE TABLE

SQL JOIN

SQL INNER JOIN

SQL OUTER JOIN

SQL CROSS JOIN

SQL UNION

SQL UNION ALL

SQL INTERSECT



SQL INSERT

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

PlayerNameDepartmentScores
JasonIT3000
IreneIT1500
JaneMarketing1000
DavidMarketing2500
PaulHR2000
JamesHR2000

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

PlayerNameDepartmentScores
JasonIT3000
IreneIT1500
JaneMarketing1000
DavidMarketing2500
PaulHR2000
JamesHR2000
VivianMarketing2500


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

PlayerNameDepartmentScores
JasonIT3000
IreneIT1500
JaneMarketing1000
DavidMarketing2500
PaulHR2000
JamesHR2000
VivianMarketing2500
KennyHR0

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.