SQL INSERT INTO Statement

The SQL INSERT INTO statement is used to insert new records into a table or specific rows of a table.

SQL INSERT INTO statement

INSERT INTO table_name
VALUES (value(s))

SQL INSERT INTO statement with specific column names

INSERT INTO table_name (column_name(s))
VALUES (value(s))

Database Table “Members”

Id FirstName LastName Email City Phone
1 Gilbert Duncan [email protected] Newark 973-600-3300
2 Elvis Daniels [email protected] Piscataway 862-600-3050
3 Michael Green [email protected] Detroit 732-500-5050
4 Kelvin Graham [email protected] Detroit 732-555-5050

SQL INSERT INTO Example

INSERT INTO Members
VALUES (5,’Arthur’, ‘Owen’, ‘[email protected]’, ‘Toronto’, ‘416-300-0685’)

Note: Notice how the value 5 has no quote wrapped around it because it is a numeric field and the phone number has quote because it is more than just a numeric value; it has – between some numbers. If the phone numbers has no – then we can treat as numeric value and need to quotes.

RESULT of SQL INSERT INTO statement above will be

Id FirstName LastName Email City Phone
1 Gilbert Duncan [email protected] Newark 973-600-3300
2 Elvis Daniels [email protected] Piscataway 862-600-3050
3 Michael Green [email protected] Detroit 732-500-5050
4 Kelvin Graham [email protected] Detroit 732-555-5050
5 Arthur Owen [email protected] Toronto 416-300-0685

Now that we have learnt an example to insert records into a table, lets now try an example to insert records into specific columns of a table.

INSERT INTO Members (Id, FirstName, LastName, Email)
VALUES (5,’Helsinko’, ‘Getauchi’, ‘[email protected]’)

RESULT of SQL INSERT INTO statement above will be

Id FirstName LastName Email City Phone
1 Gilbert Duncan [email protected] Newark 973-600-3300
2 Elvis Daniels [email protected] Piscataway 862-600-3050
3 Michael Green [email protected] Detroit 732-500-5050
4 Kelvin Graham [email protected] Detroit 732-555-5050
5 Helsinko Getauchi [email protected]

SQL INSERT INTO Example

INSERT INTO Members
VALUES (5,’Arthur’, ‘Owen’, ‘[email protected]’, ‘Toronto’, ‘416-300-0685’)

Note: Notice how the value 5 has no quote wrapped around it because it is a numeric field and the phone number has quote because it is more than just a numeric value; it has – between some numbers. If the phone numbers has no – then we can treat as numeric value and need to quotes.

RESULT of SQL INSERT INTO statement above will be

Id FirstName LastName Email City Phone
1 Gilbert Duncan [email protected] Newark 973-600-3300
2 Elvis Daniels [email protected] Piscataway 862-600-3050
3 Michael Green [email protected] Detroit 732-500-5050
4 Kelvin Graham [email protected] Detroit 732-555-5050
5 Arthur Owen [email protected] Toronto 416-300-0685

Now that we have learnt an example to insert records into a table, l