Lessons › SQL › Deep Dive: Database Admin & ETL
SQL lesson
Multi-row INSERT
A multi-row INSERT adds several rows to a table in one statement instead of repeating the same command over and over.
Try this lesson free →Example
Inserting many rows in one statement
INSERT INTO products (product_id, brand, category) VALUES
('P3001', 'NovaTech', 'Electronics'),
('P3002', 'UrbanThreads', 'Clothing'),
('P3003', 'GlowUp', 'Beauty'),
('P3004', 'HomeNest', 'Home'),
('P3005', 'FitZone', 'Fashion')| affected |
|---|
| 5 |
Step by step
- Start with INSERT INTO and the name of the table you want to add rows to.
INSERT INTO products; - Inside parentheses, list the columns you're providing values for, comma-separated.
INSERT INTO products (product_id, brand, category); - VALUES followed by a tuple of values - one value per listed column, in the same order.
INSERT INTO products (product_id, brand, category) VALUES ('P3001', 'NovaTech', 'Electronics');
Practice
1. Three products just arrived at the warehouse. Add them to the products table: - P2001, NovaTech, Electronics - P2002, UrbanThreads, Clothing - P2003, GlowUp, Beauty Use a single INSERT with one VALUES list.
INSERT INTO products (product_id, brand, category) VALUES ('P2001', 'NovaTech', 'Electronics'), ('P2002', 'UrbanThreads', 'Clothing'), ('P2003', 'GlowUp', 'Beauty')2. Register three new customers in the customers table: - C101, Alice Chen, alice.chen@shopmail.com - C102, Bob Tanaka, bob.tanaka@retail.net - C103, Carol White, carol.white@home.org Use a single INSERT with one VALUES list.
INSERT INTO customers (customer_id, full_name, email) VALUES ('C101', 'Alice Chen', 'alice.chen@shopmail.com'), ('C102', 'Bob Tanaka', 'bob.tanaka@retail.net'), ('C103', 'Carol White', 'carol.white@home.org')3. Add three orders to the orders table. Columns are order_id, customer_id, and category. Orders placed today: - Order O2001 from customer C101 for Electronics - Order O2002 from customer C102 for Electronics - Order O2003 from customer C101 for Clothing
INSERT INTO orders (order_id, customer_id, category) VALUES ('O2001', 'C101', 'Electronics'), ('O2002', 'C102', 'Electronics'), ('O2003', 'C101', 'Clothing')4. Stock has been counted across two warehouses. Add the counts to the inventory table: - Product P2001: 120 units in the East warehouse - Product P2002: 45 units in West - Product P2003: 200 units in East Columns: product_id, warehouse, stock_count. Numbers do not need quotes.
INSERT INTO inventory (product_id, warehouse, stock_count) VALUES ('P2001', 'East', 120), ('P2002', 'West', 45), ('P2003', 'East', 200)5. Three new suppliers have been onboarded. Add them to the suppliers table using the column names supplier_id, supplier_name, country: - SUP001: Nordic Electronics, based in Norway - SUP002: Atlantic Apparel, based in USA - SUP003: Mediterranean Beauty, based in Italy
INSERT INTO suppliers (supplier_id, supplier_name, country) VALUES ('SUP001', 'Nordic Electronics', 'Norway'), ('SUP002', 'Atlantic Apparel', 'USA'), ('SUP003', 'Mediterranean Beauty', 'Italy')Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →