0% found this document useful (0 votes)
3 views2 pages

Extended Smart Ebook Library SQL Code

The document contains SQL code for creating and managing a Smart Ebook Library database. It includes commands to create a database, a table for ebooks, insert sample records, perform searches, update and delete records, and generate various reports. Key functionalities include counting total books, retrieving the latest published book, and listing books by genre.

Uploaded by

rooshaannasir70
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Extended Smart Ebook Library SQL Code

The document contains SQL code for creating and managing a Smart Ebook Library database. It includes commands to create a database, a table for ebooks, insert sample records, perform searches, update and delete records, and generate various reports. Key functionalities include counting total books, retrieving the latest published book, and listing books by genre.

Uploaded by

rooshaannasir70
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Extended SQL Code for Smart Ebook Library

-- Create Database

CREATE DATABASE library;

-- Use the database

USE library;

-- Create Table

CREATE TABLE ebooks (

book_id INT AUTO_INCREMENT PRIMARY KEY,

title VARCHAR(100),

author VARCHAR(100),

genre VARCHAR(50),

year INT

);

-- Insert Sample Records

INSERT INTO ebooks (title, author, genre, year) VALUES

('The Alchemist', 'Paulo Coelho', 'Fiction', 1988),

('Python Programming', 'John Zelle', 'Education', 2010),

('Digital Fortress', 'Dan Brown', 'Thriller', 1998),

('Clean Code', 'Robert C. Martin', 'Programming', 2008),

('Atomic Habits', 'James Clear', 'Self-help', 2018),

('To Kill a Mockingbird', 'Harper Lee', 'Classic', 1960),

('A Brief History of Time', 'Stephen Hawking', 'Science', 1988),

('1984', 'George Orwell', 'Dystopian', 1949),

('The Pragmatic Programmer', 'Andy Hunt', 'Programming', 1999);

-- Display All Records

SELECT * FROM ebooks;

-- Search Records by title or author


SELECT * FROM ebooks WHERE title LIKE '%Code%' OR author LIKE '%Orwell%';

-- Update a Book Record

UPDATE ebooks SET title='Clean Coder', author='Robert C. Martin', genre='Programming',

year=2011 WHERE book_id=4;

-- Delete a Book Record

DELETE FROM ebooks WHERE book_id=2;

-- Add Another Book

INSERT INTO ebooks (title, author, genre, year) VALUES

('Zero to One', 'Peter Thiel', 'Business', 2014);

-- Search for Genre 'Programming'

SELECT * FROM ebooks WHERE genre='Programming';

-- Count Total Books

SELECT COUNT(*) FROM ebooks;

-- Get Latest Published Book

SELECT * FROM ebooks ORDER BY year DESC LIMIT 1;

-- List Books Published Before 2000

SELECT * FROM ebooks WHERE year < 2000;

-- List Books by Genre with Count

SELECT genre, COUNT(*) AS total FROM ebooks GROUP BY genre;

You might also like