0
0
SQLquery~30 mins

CREATE VIEW syntax in SQL - Mini Project: Build & Apply

Choose your learning style9 modes available
Create a Simple SQL View
📖 Scenario: You work at a bookstore that keeps track of books and their authors in a database. You want to create a simple view to easily see the book titles along with their authors' names.
🎯 Goal: Build a SQL view named BookAuthorView that shows the title of each book and the author_name from the existing tables.
📋 What You'll Learn
Create a table called Books with columns book_id (integer), title (text), and author_id (integer).
Create a table called Authors with columns author_id (integer) and author_name (text).
Insert the exact data into Books: (1, 'The Great Gatsby', 101), (2, '1984', 102), (3, 'To Kill a Mockingbird', 103).
Insert the exact data into Authors: (101, 'F. Scott Fitzgerald'), (102, 'George Orwell'), (103, 'Harper Lee').
Create a view named BookAuthorView that shows title and author_name by joining Books and Authors on author_id.
💡 Why This Matters
🌍 Real World
Views help simplify complex queries by creating a virtual table that users can query easily without writing joins every time.
💼 Career
Database developers and analysts often create views to provide clean, reusable data access layers for applications and reports.
Progress0 / 4 steps
1
Create the Books and Authors tables
Write SQL statements to create a table called Books with columns book_id (integer), title (text), and author_id (integer). Then create a table called Authors with columns author_id (integer) and author_name (text).
SQL
Need a hint?

Use CREATE TABLE statements with the exact column names and types.

2
Insert data into Books and Authors
Write SQL INSERT INTO statements to add these exact rows into Books: (1, 'The Great Gatsby', 101), (2, '1984', 102), (3, 'To Kill a Mockingbird', 103). Then insert these exact rows into Authors: (101, 'F. Scott Fitzgerald'), (102, 'George Orwell'), (103, 'Harper Lee').
SQL
Need a hint?

Use one INSERT INTO statement per table with multiple rows.

3
Write the SELECT query for the view
Write a SQL SELECT statement that selects title from Books and author_name from Authors. Join the tables on Books.author_id = Authors.author_id.
SQL
Need a hint?

Use JOIN to combine the tables on author_id.

4
Create the view BookAuthorView
Write a SQL statement to create a view named BookAuthorView using the SELECT query that shows title and author_name by joining Books and Authors on author_id.
SQL
Need a hint?

Use CREATE VIEW view_name AS SELECT ... syntax.