0
0
SQLquery~30 mins

DEFAULT values in SQL - Mini Project: Build & Apply

Choose your learning style9 modes available
Using DEFAULT Values in SQL Tables
📖 Scenario: You are creating a simple database table to store information about books in a library. Some books may not have all details provided when they are added.
🎯 Goal: Create a table called Books with columns for BookID, Title, Author, and Available. Use a DEFAULT value for the Available column so that if no value is given, it is set to TRUE.
📋 What You'll Learn
Create a table named Books
Include columns BookID (integer), Title (text), Author (text), and Available (boolean)
Set the Available column to have a DEFAULT value of TRUE
Use standard SQL syntax
💡 Why This Matters
🌍 Real World
DEFAULT values are used in databases to automatically fill in missing data, making data entry easier and more reliable.
💼 Career
Knowing how to use DEFAULT values is important for database design and helps ensure data quality in real applications.
Progress0 / 4 steps
1
Create the Books table with basic columns
Write a SQL statement to create a table called Books with columns BookID as an integer, Title as text, and Author as text.
SQL
Need a hint?

Use CREATE TABLE Books (column_name data_type, ...); syntax.

2
Add the Available column with DEFAULT value
Modify the Books table creation statement to add a column called Available of type boolean with a DEFAULT value of TRUE.
SQL
Need a hint?

Add Available BOOLEAN DEFAULT TRUE as a new column.

3
Insert a book without specifying Available
Write a SQL INSERT statement to add a book with BookID 1, Title 'The Great Gatsby', and Author 'F. Scott Fitzgerald' without specifying the Available column.
SQL
Need a hint?

Use INSERT INTO Books (BookID, Title, Author) VALUES (...); without Available.

4
Insert a book specifying Available as FALSE
Write a SQL INSERT statement to add a book with BookID 2, Title '1984', Author 'George Orwell', and set Available explicitly to FALSE.
SQL
Need a hint?

Include Available in the column list and set it to FALSE.