Introduction
We use INSERT with specific columns to add new data to only certain parts of a table, not all columns. This helps when we don't have values for every column.
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com');
INSERT INTO products (product_name, price) VALUES ('Book', 9.99);
INSERT INTO employees (first_name, last_name) VALUES ('John', 'Doe');
CREATE TABLE students ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50), age INT, city VARCHAR(50) DEFAULT 'Unknown' ); INSERT INTO students (name, age) VALUES ('Emma', 20); SELECT * FROM students;
INSERT INTO employees (name, age) VALUES ('Alice', 30); do?id and email into a table users?products(id INT, name VARCHAR, price DECIMAL DEFAULT 0), what will be the result of this query?INSERT INTO products (id, name) VALUES (101, 'Pen');INSERT INTO orders (order_id, customer) VALUES (123);students(id INT PRIMARY KEY, name VARCHAR, grade CHAR DEFAULT 'F'). You want to insert a new student with id=5 and name='John', but leave grade as default. Which query is correct?INSERT INTO students (id, name) VALUES (5, 'John'); omits grade, using default. INSERT INTO students (id, name, grade) VALUES (5, 'John', 'F'); sets it explicitly. INSERT INTO students VALUES (5, 'John'); has value count mismatch. INSERT INTO students (name, grade) VALUES ('John', 'F'); misses id primary key.Pass the test and this pattern moves unknown