SQL: Practice Exercises for INSERT Statement
If you want to test your skills using the SQL INSERT statement, try some of our practice exercises.
These practice exercises allow you to test your skills with the INSERT statement. You will be given questions that you need to solve. After each exercise, we provide the solution so you can check your answer.
Get started!
Practice Exercise #1:
Based on the employees table, insert an employee record whose employee_number is 1005, employee_name is Sally Johnson, salary is $58,000, and dept_id is 500.
CREATE TABLE employees ( employee_number int NOT NULL, last_name char(50) NOT NULL, first_name char(50) NOT NULL, salary int, dept_id int, CONSTRAINT employees_pk PRIMARY KEY (employee_number) ); INSERT INTO employees (employee_number, last_name, first_name, salary, dept_id) VALUES (1001, 'Smith', 'John', 62000, 500); INSERT INTO employees (employee_number, last_name, first_name, salary, dept_id) VALUES (1002, 'Anderson', 'Jane', 57500, 500); INSERT INTO employees (employee_number, last_name, first_name, salary, dept_id) VALUES (1003, 'Everest', 'Brad', 71000, 501); INSERT INTO employees (employee_number, last_name, first_name, salary, dept_id) VALUES (1004, 'Horvath', 'Jack', 42000, 501);
Solution for Practice Exercise #1:
The following INSERT statement would insert this record into the employees table:
Try ItINSERT INTO employees (employee_number, last_name, first_name, salary, dept_id) VALUES (1005, 'Johnson', 'Sally', 58000, 500);
The employees table would now look like this:
employee_number | last_name | first_name | salary | dept_id |
---|---|---|---|---|
1001 | Smith | John | 62000 | 500 |
1002 | Anderson | Jane | 57500 | 500 |
1003 | Everest | Brad | 71000 | 501 |
1004 | Horvath | Jack | 42000 | 501 |
1005 | Johnson | Sally | 58000 | 500 |
Practice Exercise #2:
Based on the suppliers table populated with the following data, insert a supplier record whose supplier_id is 1000 and supplier_name is Apple:
CREATE TABLE suppliers ( supplier_id int NOT NULL, supplier_name char(50) NOT NULL, city char(50), state char(50), CONSTRAINT suppliers_pk PRIMARY KEY (supplier_id) ); INSERT INTO suppliers (supplier_id, supplier_name, city, state) VALUES (100, 'Microsoft', 'Redmond', 'Washington'); INSERT INTO suppliers (supplier_id, supplier_name, city, state) VALUES (200, 'Google', 'Mountain View', 'California'); INSERT INTO suppliers (supplier_id, supplier_name, city, state) VALUES (300, 'Oracle', 'Redwood City', 'California'); INSERT INTO suppliers (supplier_id, supplier_name, city, state) VALUES (400, 'Kimberly-Clark', 'Irving', 'Texas'); INSERT INTO suppliers (supplier_id, supplier_name, city, state) VALUES (500, 'Tyson Foods', 'Springdale', 'Arkansas'); INSERT INTO suppliers (supplier_id, supplier_name, city, state) VALUES (600, 'SC Johnson', 'Racine', 'Wisconsin'); INSERT INTO suppliers (supplier_id, supplier_name, city, state) VALUES (700, 'Dole Food Company', 'Westlake Village', 'California'); INSERT INTO suppliers (supplier_id, supplier_name, city, state) VALUES (800, 'Flowers Foods', 'Thomasville', 'Georgia'); INSERT INTO suppliers (supplier_id, supplier_name, city, state) VALUES (900, 'Electronic Arts', 'Redwood City', 'California');
Solution for Practice Exercise #2:
The following SQL INSERT statement would insert this record into the suppliers table:
Try ItINSERT INTO suppliers (supplier_id, supplier_name) VALUES (1000, 'Apple');
The suppliers table would now look like this:
supplier_id | supplier_name | city | state |
---|---|---|---|
100 | Microsoft | Redmond | Washington |
200 | Mountain View | California | |
300 | Oracle | Redwood City | California |
400 | Kimberly-Clark | Irving | Texas |
500 | Tyson Foods | Springdale | Arkansas |
600 | SC Johnson | Racine | Wisconsin |
700 | Dole Food Company | Westlake Village | California |
800 | Flowers Foods | Thomasville | Georgia |
900 | Electronic Arts | Redwood City | California |
1000 | Apple | NULL | NULL |
Advertisements