0
0
SQLquery~30 mins

INSERT INTO single row in SQL - Mini Project: Build & Apply

Choose your learning style9 modes available
Insert a Single Row into a Database Table
📖 Scenario: You are managing a small bookstore database. You need to add new books to the books table to keep the inventory updated.
🎯 Goal: Learn how to insert a single row into the books table using the INSERT INTO statement.
📋 What You'll Learn
Create a table named books with columns id, title, and author
Add a configuration variable for the new book's id
Write an INSERT INTO statement to add a single row with the new book's details
Complete the insertion by committing the transaction
💡 Why This Matters
🌍 Real World
Adding new records to a database is a common task in managing inventories, customer data, or any information system.
💼 Career
Database administrators and developers frequently insert data into tables to keep databases current and accurate.
Progress0 / 4 steps
1
Create the books table
Write a SQL statement to create a table called books with three columns: id as an integer primary key, title as text, and author as text.
SQL
Need a hint?

Use CREATE TABLE books (id INTEGER PRIMARY KEY, title TEXT, author TEXT); to create the table.

2
Set the new book's ID
Create a variable called new_book_id and set it to 101 to represent the ID of the book you want to add.
SQL
Need a hint?

Assign 101 to new_book_id like new_book_id = 101;

3
Insert a single row into books
Write an INSERT INTO statement to add a new book with id equal to new_book_id, title as 'The Great Gatsby', and author as 'F. Scott Fitzgerald' into the books table.
SQL
Need a hint?

Use INSERT INTO books (id, title, author) VALUES (new_book_id, 'The Great Gatsby', 'F. Scott Fitzgerald');

4
Commit the transaction
Add the SQL statement to commit the transaction so the new row is saved permanently.
SQL
Need a hint?

Use COMMIT; to save the changes.