CodeBlanks Logo Icon CodeBlanks

Inserting into specific columns

Insert values into only some columns.

Insert into all columns

If you give values for every column you can skip the column list; values follow the table order.

INSERT INTO products
VALUES (2, 'Defter', 12, 50, 'kırtasiye');

This query gives values for all columns in table order.

The values given with VALUES are inserted into products as new rows.

Insert into all columns — details

Skipping the column list is risky; if the table changes the query breaks. In production always list columns for safety.

Practice Insert into all columns

Insert id=3 into products giving values for all columns.

Starter code

query.sql
-- insert all columns
INSERT INTO products
VALUES

Sample solution

query.sql
INSERT INTO products
VALUES (3, 'Silgi', 2, 100, 'kırtasiye')

Expected output

1 satır eklendi

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 All columns

Question
INSERT INTO products
____ (3, 'Silgi', 2, 100, 'kırtasiye');
Answer
INSERT INTO products
VALUES (3, 'Silgi', 2, 100, 'kırtasiye');

Explanation: Without a column list, VALUES must contain a value for every column in order.

2 When is skipping columns safe?

  • In production
  • Only when deleting
  • In a quick test Correct answer
  • Never

Explanation: Skip columns in tests, list them in production.

3 Inserting into specific columns: match the terms

Term Meaning
INSERT insert
VALUES values
INTO into
SELECT read

All lessons in Beginner