0% found this document useful (0 votes)
31 views11 pages

CREATE

Uploaded by

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

CREATE

Uploaded by

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

CREATE TABLE Users ( UserID INT AUTO_INCREMENT PRIMARY KEY, Username VARCHAR(50) NOT

NULL UNIQUE, PasswordHash VARCHAR(255) NOT NULL, Email VARCHAR(100) NOT NULL UNIQUE,
CreatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP );

User table
CREATE TABLE Authors ( AuthorID INT AUTO_INCREMENT PRIMARY KEY, Name VARCHAR(100) NOT
NULL );

CREATE TABLE Categories ( CategoryID INT AUTO_INCREMENT PRIMARY KEY, CategoryName VAR
CHAR(100) NOT NULL UNIQUE );

CREATE TABLE Books (


BookID INT AUTO_INCREMENT PRIMARY KEY,
Title VARCHAR(255) NOT NULL,
AuthorID INT,
CategoryID INT,
PublishedDate DATE,
Description TEXT,
FOREIGN KEY (AuthorID) REFERENCES Authors(AuthorID),
FOREIGN KEY (CategoryID) REFERENCES Categories(CategoryID)
);
Figure 4: Create Books table

CREATE TABLE FreeBooks (


BookID INT PRIMARY KEY,
FOREIGN KEY (BookID) REFERENCES Books(BookID)
);

Figure 5: Create FreeBooks table

CREATE TABLE BookPrices (


BookID INT PRIMARY KEY,
Price DECIMAL(10, 2),
FOREIGN KEY (BookID) REFERENCES Books(BookID)
);

CREATE TABLE UserBooks (


UserBookID INT AUTO_INCREMENT PRIMARY KEY,
UserID INT,
BookID INT,
AccessDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (UserID) REFERENCES Users(UserID),
FOREIGN KEY (BookID) REFERENCES Books(BookID)
);

CREATE TABLE Logins (


LoginID INT AUTO_INCREMENT PRIMARY KEY,
UserID INT,
LoginTimestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (UserID) REFERENCES Users(UserID)
);

INSERT INTO Authors (Name) VALUES


('J.K. Rowling'),
('George R.R. Martin'),
('J.R.R. Tolkien'),
('Stephen King'),
('Agatha Christie'),
('Harper Lee'),
('Toni Morrison'),
('Margaret Atwood'),
('Neil Gaiman'),
('Ernest Hemingway'),
('J.D. Salinger'),
('Virginia Woolf'),
('Gabriel Garcia Marquez'),
('F. Scott Fitzgerald'),
('Hermann Hesse'),
('Leo Tolstoy'),
('Jane Austen'),
('Charles Dickens'),
('Mark Twain'),
('Homer'),
('H.G. Wells'),
('Emily Dickinson'),
('Arthur Conan Doyle'),
('Mary Shelley'),
('Edgar Allan Poe'),
('George Orwell'),
('H.P. Lovecraft'),
('Ray Bradbury'),
('Albert Camus'),
('Franz Kafka');
INSERT INTO Categories (CategoryName) VALUES
('Fantasy'),
('Science Fiction'),
('Mystery'),
('Romance'),
('Thriller'),
('Horror'),
('Adventure'),
('Historical Fiction'),
('Biography'),
('Self-Help'),
('Young Adult'),
('Poetry'),
('Classic'),
('Crime'),
('Humor'),
('Drama'),
('Action'),
('Western'),
('Satire'),
('Non-Fiction'),
('Psychology'),
('Cookbook'),
('Art'),
('Travel'),
('Science'),
('Business'),
('Religion'),
('Philosophy'),
('Music'),
('Sports');
INSERT INTO Users (Username, PasswordHash, Email) VALUES
('Alice', 'drowssap1', '[email protected]'),
('Bob', 'securepassword2', '[email protected]'),
('Charlie', 'pa$$w0rd3', '[email protected]'),
('David', 'myp@ssw0rd4', '[email protected]'),
('Emma', 'strongPassword5', '[email protected]'),
('Frank', 'p@$$w0rd6!', '[email protected]'),
('Grace', 'mysecurep@ss7', '[email protected]'),
('Henry', '1234passw0rd', '[email protected]'),
('Isabella', 'password!123', '[email protected]'),
('Jack', 'passw0rd8@', '[email protected]'),
('Katie', 'password123$', '[email protected]'),
('Liam', 'mystrongp@ss9', '[email protected]'),
('Mia', 'P@ssw0rd123', '[email protected]'),
('Noah', 'mysecurepassword10', '[email protected]'),
('Olivia', 'p@ssw0rd11!', '[email protected]'),
('Peter', 'secureP@ssw0rd12', '[email protected]'),
('Quinn', 'P@$$w0rd12345', '[email protected]'),
('Rachel', 'myP@ssword13', '[email protected]'),
('Samuel', 'passw0rd14!', '[email protected]'),
('Taylor', 'securepassword15$', '[email protected]'),
('Uma', 'password!12345', '[email protected]'),
('Victor', 'myP@ssword16', '[email protected]'),
('Wendy', 'passw0rd17@', '[email protected]'),
('Xavier', 'strongp@ssword18', '[email protected]'),
('Yvonne', 'myP@ssw0rd19', '[email protected]'),
('Zachary', 'p@ssword20!', '[email protected]'),
('Nora', 'secureP@$$w0rd21', '[email protected]'),
('Owen', 'P@$$w0rd22!', '[email protected]'),
('Sophia', 'mystrongpassword23', '[email protected]'),
('William', 'p@$$w0rd24', '[email protected]');
INSERT INTO Books (Title, AuthorID, CategoryID, PublishedDate, Description) VALUES
('Harry Potter and the Chamber of Secrets', 1, 1, '1998-07-02', 'Sequel to the first
Harry Potter book.'),
('Harry Potter and the Prisoner of Azkaban', 1, 1,'1999-07-08', 'Third installment in
the Harry Potter series.'),
('A Clash of Kings', 2, 1, '1998-11-16', 'Second book in the A Song of Ice and Fire
series.'),
('A Storm of Swords', 2, 1, '2000-08-08', 'Third book in the A Song of Ice and Fire
series.'),
('The Lord of the Rings: The Fellowship of the Ring', 3, 1, '1954-07-29', 'First part
of The Lord of the Rings trilogy.'),
('The Lord of the Rings: The Two Towers', 3, 1, '1954-11-11', 'Second part of The
Lord of the Rings trilogy.'),
('The Lord of the Rings: The Return of the King', 3, 1, '1955-10-20', 'Third part of
The Lord of the Rings trilogy.'),
('It', 4, 6, '1986-09-15', 'Horror novel about an evil entity that terrorizes
children.'),
('Murder on the Orient Express', 5, 3, '1934-01-01', 'Mystery novel featuring
detective Hercule Poirot.'),
('To Kill a Mockingbird', 6, 8, '1960-07-11', 'Classic novel about racial injustice
in the American South.'),
('Beloved', 7, 9, '1987-09-02', 'Historical fiction novel set after the American
Civil War.'),
('American Gods', 8, 1, '2001-06-19', 'Fantasy novel about old gods and new gods in
America.'),
('The Old Man and the Sea', 9, 15, '1952-09-01', 'Novella about an aging fisherman
and his battle with a giant marlin.'),
('The Catcher in the Rye', 10, 13, '1951-07-16', 'Classic novel about teenage angst
and alienation.'),
('Mrs. Dalloway', 11, 13, '1925-05-14', 'Modernist novel that follows a day in the
life of Clarissa Dalloway.');

INSERT INTO FreeBooks (BookID)


SELECT * FROM (
SELECT 1 AS BookID
) AS tmp
WHERE NOT EXISTS (
SELECT * FROM FreeBooks WHERE BookID = 1
) LIMIT 1;
INSERT INTO BookPrices (BookID, Price)
SELECT b.BookID, 9.99 -- Replace 9.99 with the actual price
FROM Books b
WHERE b.BookID = 1; -- Replace 1 with the specific BookID you want to insert the
price for

You might also like