Trystories.sql -
To create the content for a file named trystories.sql , you first need a schema that can support storytelling data—such as users, the stories they write, and the chapters within those stories.
: For the content field in the chapters table, modern databases prefer TEXT or VARCHAR(MAX) over older NTEXT types to store book-length narratives. trystories.sql
-- 1. Create Tables (DDL) CREATE TABLE users ( user_id INTEGER PRIMARY KEY AUTOINCREMENT, username VARCHAR(50) NOT NULL UNIQUE, email VARCHAR(100) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE stories ( story_id INTEGER PRIMARY KEY AUTOINCREMENT, author_id INTEGER, title VARCHAR(255) NOT NULL, genre VARCHAR(50), summary TEXT, is_published BOOLEAN DEFAULT FALSE, FOREIGN KEY (author_id) REFERENCES users(user_id) ); CREATE TABLE chapters ( chapter_id INTEGER PRIMARY KEY AUTOINCREMENT, story_id INTEGER, chapter_number INTEGER, chapter_title VARCHAR(255), content TEXT, -- Storing large blocks of story text FOREIGN KEY (story_id) REFERENCES stories(story_id) ); -- 2. Insert Sample Data (DML) INSERT INTO users (username, email) VALUES ('InkMaster', 'ink@example.com'), ('StorySeeker', 'seeker@example.com'); INSERT INTO stories (author_id, title, genre, summary) VALUES (1, 'The SQL Quest', 'Fantasy', 'A journey through a world governed by queries.'), (2, 'Midnight Schema', 'Mystery', 'A database admin finds a hidden table with dark secrets.'); INSERT INTO chapters (story_id, chapter_number, chapter_title, content) VALUES (1, 1, 'The First Select', 'The traveler looked upon the ancient console and typed: SELECT * FROM world;'), (1, 2, 'The Join of Kingdoms', 'The primary keys were finally united across the Great Inner Join.'); -- 3. Sample Query for Data Storytelling -- This query retrieves all stories along with their author's name SELECT u.username AS author, s.title AS story_title, s.genre, COUNT(c.chapter_id) AS total_chapters FROM users u JOIN stories s ON u.user_id = s.author_id LEFT JOIN chapters c ON s.story_id = c.story_id GROUP BY s.story_id; Use code with caution. Copied to clipboard Key Elements Explained To create the content for a file named trystories