SQL INSERT INTO Keyword
The INSERT INTO command is used to add new rows of data into a table. You can either insert values into all columns or only specific columns of a table.
SQL INSERT INTO Syntax
SQL
x
1
-- Insert into all columns
2
INSERT INTO table_name
3
VALUES (value1, value2, ...);
4
5
-- Insert into specific columns
6
INSERT INTO table_name (column1, column2, ...)
7
VALUES (value1, value2, ...);
SQL INSERT INTO Students Table Example
This query adds a new student with a name only. The id will auto-increment.
SQL
1
1
INSERT INTO Students (name)
2
VALUES ('Chloe');

SQL INSERT INTO Doctors Table Example
This query inserts a full record into the Doctors
table with a first name, last name, specialty, and contact number.
SQL
1
1
INSERT INTO Doctors (first_name, last_name, specialty, contact_number)
2
VALUES ('Dr. Anna', 'Lee', 'Radiology', '555-1010');

SQL INSERT INTO Insert with Only Selected Columns Example
This query adds a new doctor, only filling the first and last name. Other columns will be NULL.
SQL
1
1
INSERT INTO Doctors (first_name, last_name)
2
VALUES ('Dr. Kyle', 'Mendoza');
