Thuta Learning
IntermediateData & Databasesbeginner

INSERT INTO

Relax. We'll talk through this in plain words — no textbook voice.

INSERT INTO is used to add a new row into a table. You'll use it for things like saving a new user from a signup form, adding a new order, or storing a message from a contact form.

How to write it

Write out the column list, then put VALUES in the same order as the columns.

sql
INSERT INTO Customers (CustomerName, ContactName, City, Country)
VALUES ('Cardinal Market', 'Tom B. Erichsen', 'Stavanger', 'Norway');
You should see
What this code does: Adds one new customer into the Customers table. Important things to notice: The order of the columns has to match the order of the values. If you accidentally put a country value where CustomerName should go, your data ends up malformed. Common mistake: Leaving out a required column, using the wrong quotes on a string, or inserting a duplicate primary key will all cause errors.