← Back
LESSON 13
SQL (Core) - Inserting rows
Prereq: None | Progress: 0%
Course Syllabus
Lesson 0 📖 What is SQL? Lesson 1 📖 SELECT queries 101 Lesson 2 📖 Queries with constraints (Pt. 1) Lesson 3 📖 Queries with constraints (Pt. 2) Lesson 4 📖 Filtering & sorting results Review 1 📖 Simple SELECT Queries Lesson 6 📖 Multi-table queries with JOINs Lesson 7 📖 OUTER JOINs Lesson 8 📖 A short note on NULLs Lesson 9 📖 Queries with expressions Lesson 10 📖 Queries with aggregates (Pt. 1) Lesson 11 📖 Queries with aggregates (Pt. 2) Lesson 12 📖 Order of execution of a Query Lesson 13 📖 Inserting rows Lesson 14 📖 Updating rows Lesson 15 📖 Deleting rows Lesson 16 📖 Creating tables Lesson 17 📖 Altering tables Lesson 18 📖 Dropping tables Lesson 19 📖 Subqueries & Nested Queries Lesson 20 📖 Set Operations Summary 🎓 Course Completion
SQL Lesson 13: Inserting rows
So far, we have only queried existing data from database tables. In this lesson, we will learn how to add brand new records using the INSERT INTO statement.
Insert Statement Syntax
To insert new rows into a database table, you specify the target table name, optionally list column names, and provide corresponding values:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...); If you supply values for every single column in the exact order specified by the table schema, you can omit the explicit column list:
INSERT INTO table_name
VALUES (val1, val2, val3, ...); 💡
Inserting Multiple Rows
INSERT INTO movies (title, director, year, length_minutes)
VALUES ('Toy Story 4', 'Josh Cooley', 2019, 100);
🗄️ Schema Explorer SELECTABLE
› movies
|
🎯 Exercises Checklist:
☐ 1. Add the studio's new movie Toy Story 4 directed by Josh Cooley released in 2019 (length 100 min)
☐ 2. Add the boxoffice record for movie_id 15 with rating 8.7, domestic sales 340000000 and international sales 730000000
⚡ Practice Console
💡 Hint:
Loading hint...
🔑 Solution SQL:
SELECT * FROM movies; Data Output
No results. Run query to fetch data.