SQL Insert Into
SQL INSERT INTO
The INSERT INTO statement is used to add new records to a table.
Basic Syntax
INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3);
Insert a Single Row
Insert one new customer into the customers table:
INSERT INTO customers (name, email, country)
VALUES ('John Smith', 'john@example.com', 'USA');
Insert Without Specifying Columns
If you provide values for all columns in the correct order, you can omit the column list. However, specifying columns is strongly recommended for clarity and safety.
INSERT INTO customers VALUES (1, 'John Smith', 'john@example.com', 'USA');
Insert Multiple Rows
You can insert multiple records in a single statement (supported in most modern database systems):
INSERT INTO customers (name, email, country)
VALUES
('Alice Brown', 'alice@example.com', 'Canada'),
('David Lee', 'david@example.com', 'UK');
Insert with NULL Values
If a column allows NULL, you can explicitly insert NULL:
INSERT INTO customers (name, email, country)
VALUES ('Maria Rossi', NULL, 'Italy');
Insert and AUTO_INCREMENT
If a table has an AUTO_INCREMENT primary key, you usually do not include it in the INSERT statement. The database will generate the value automatically.
INSERT INTO customers (name, email, country)
VALUES ('Emma White', 'emma@example.com', 'USA');
Insert Using DEFAULT Values
If a column has a DEFAULT value defined, it will be used when no value is provided.
Common Mistakes
- Forgetting to match the number of columns and values
- Not specifying column names and relying on column order
- Inserting text without quotes
Next Step
Continue with SQL NULL Values to understand how NULL behaves in comparisons and filtering.