Skip to content

Commit 7326806

Browse files
authored
Create bookstore.sql
1 parent 1c17a0f commit 7326806

1 file changed

Lines changed: 287 additions & 0 deletions

File tree

‎Dummy_DataBase/bookstore.sql‎

Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
-- =========================================
2+
-- CREATE DATABASE & USE IT
3+
-- =========================================
4+
CREATE DATABASE IF NOT EXISTS bookstore;
5+
USE bookstore;
6+
7+
-- =========================================
8+
-- DROP TABLES IF THEY EXIST (RESET)
9+
-- =========================================
10+
DROP TABLE IF EXISTS Orders;
11+
DROP TABLE IF EXISTS Books;
12+
DROP TABLE IF EXISTS Customers;
13+
DROP TABLE IF EXISTS Authors;
14+
15+
-- =========================================
16+
-- CREATE TABLES
17+
-- =========================================
18+
19+
-- AUTHORS TABLE
20+
CREATE TABLE Authors (
21+
author_id INT AUTO_INCREMENT PRIMARY KEY,
22+
first_name VARCHAR(50) NOT NULL,
23+
last_name VARCHAR(50) NOT NULL,
24+
birth_year INT,
25+
nationality VARCHAR(50)
26+
);
27+
28+
-- BOOKS TABLE
29+
CREATE TABLE Books (
30+
book_id INT AUTO_INCREMENT PRIMARY KEY,
31+
title VARCHAR(150) NOT NULL,
32+
author_id INT,
33+
publication_year INT,
34+
genre VARCHAR(50),
35+
price DECIMAL(10,2) CHECK (price > 0),
36+
stock INT DEFAULT 0,
37+
FOREIGN KEY (author_id) REFERENCES Authors(author_id)
38+
);
39+
40+
-- CUSTOMERS TABLE
41+
CREATE TABLE Customers (
42+
customer_id INT AUTO_INCREMENT PRIMARY KEY,
43+
first_name VARCHAR(50),
44+
last_name VARCHAR(50),
45+
email VARCHAR(100),
46+
join_date DATE
47+
);
48+
49+
-- ORDERS TABLE
50+
CREATE TABLE Orders (
51+
order_id INT AUTO_INCREMENT PRIMARY KEY,
52+
customer_id INT,
53+
book_id INT,
54+
order_date DATE,
55+
quantity INT,
56+
total_amount DECIMAL(10,2),
57+
FOREIGN KEY (customer_id) REFERENCES Customers(customer_id),
58+
FOREIGN KEY (book_id) REFERENCES Books(book_id)
59+
);
60+
61+
-- =========================================
62+
-- INSERT BASE MANUAL DATA
63+
-- =========================================
64+
65+
-- 20 BASE AUTHORS (MANUAL)
66+
INSERT INTO Authors (first_name, last_name, birth_year, nationality) VALUES
67+
('John','Doe',1975,'American'),
68+
('Alice','Walker',1985,'British'),
69+
('Ravi','Kumar',1990,'Indian'),
70+
('Maria','Gomez',1978,'Spanish'),
71+
('David','Smith',1982,'American'),
72+
('Linda','Brown',1988,'Canadian'),
73+
('Ken','Tanaka',1972,'Japanese'),
74+
('Sara','Miller',1991,'British'),
75+
('Omar','Hassan',1980,'Egyptian'),
76+
('Julia','Roberts',1975,'American'),
77+
('Leon','Adams',1973,'German'),
78+
('Vikram','Singh',1988,'Indian'),
79+
('Chen','Wei',1983,'Chinese'),
80+
('Hiro','Sato',1979,'Japanese'),
81+
('Paula','Fernandez',1985,'Mexican'),
82+
('Mohammed','Ali',1981,'UAE'),
83+
('Eva','Larsen',1989,'Norwegian'),
84+
('Pierre','Dupont',1977,'French'),
85+
('Isabella','Rossi',1984,'Italian'),
86+
('Oliver','King',1976,'British');
87+
88+
-- 30 MORE AUTHORS (MANUAL) = 50 MANUAL AUTHORS
89+
INSERT INTO Authors (first_name, last_name, birth_year, nationality) VALUES
90+
('Sonia','Sharma',1991,'Indian'),
91+
('Arjun','Patel',1987,'Indian'),
92+
('Henry','Clark',1980,'American'),
93+
('Jacob','White',1979,'American'),
94+
('Nina','Lopez',1986,'Spanish'),
95+
('Carlos','Martinez',1990,'Mexican'),
96+
('Yuki','Nakamura',1983,'Japanese'),
97+
('Jin','Park',1985,'Korean'),
98+
('Aisha','Rahman',1988,'Bangladeshi'),
99+
('Tom','Baker',1978,'British'),
100+
('George','Hall',1974,'American'),
101+
('Irina','Petrov',1982,'Russian'),
102+
('Natalia','Smirnova',1987,'Russian'),
103+
('Liam','Scott',1985,'Australian'),
104+
('Noah','Turner',1990,'Australian'),
105+
('Emma','Wright',1993,'Canadian'),
106+
('Maya','Kapoor',1992,'Indian'),
107+
('Zara','Qureshi',1989,'Pakistani'),
108+
('Farhan','Iqbal',1984,'Pakistani'),
109+
('Tariq','Hussein',1976,'Jordanian'),
110+
('Anita','Desai',1958,'Indian'),
111+
('Mark','Wilson',1986,'American'),
112+
('Grace','Young',1991,'British'),
113+
('Hannah','Moore',1983,'Canadian'),
114+
('Samuel','Reed',1980,'American'),
115+
('Austin','Cole',1994,'Australian'),
116+
('Andre','Silva',1987,'Brazilian'),
117+
('Miguel','Castro',1982,'Portuguese'),
118+
('Elena','Costa',1985,'Italian'),
119+
('Jonas','Muller',1981,'German');
120+
121+
-- 25 BASE BOOKS (MANUAL)
122+
INSERT INTO Books (title, author_id, publication_year, genre, price, stock) VALUES
123+
('Python Basics',1,2020,'Programming',20.00,10),
124+
('Advanced Python Concepts',1,2022,'Programming',25.00,4),
125+
('Java Essentials',2,2021,'Programming',18.50,5),
126+
('Machine Learning 101',3,2023,'AI',30.00,8),
127+
('Deep Learning Guide',3,2022,'AI',40.00,2),
128+
('The Great Adventure',4,2018,'Fiction',12.99,13),
129+
('Love and War',5,2019,'Fiction',15.50,6),
130+
('Secrets of the Universe',6,2020,'Science',22.00,9),
131+
('History of Civilizations',7,2015,'History',18.00,20),
132+
('Fantasy World',8,2017,'Fantasy',16.50,7),
133+
('Cloud Computing',9,2021,'Technology',28.00,3),
134+
('Cyber Security Fundamentals',10,2020,'Technology',32.00,5),
135+
('AI for Beginners',11,2021,'AI',24.99,14),
136+
('Cooking Made Easy',12,2019,'Cooking',12.00,16),
137+
('Master Chef Secrets',13,2022,'Cooking',18.00,5),
138+
('Gardening at Home',14,2021,'Lifestyle',14.00,8),
139+
('Healthy Living',15,2020,'Lifestyle',19.00,11),
140+
('Travel the World',16,2018,'Travel',20.50,4),
141+
('Mountains & Rivers',17,2017,'Travel',21.00,3),
142+
('Digital Photography',18,2021,'Art',26.00,7),
143+
('Painting for All',19,2019,'Art',22.00,9),
144+
('Blockchain Explained',20,2022,'Technology',29.99,6),
145+
('Cryptocurrency Mastery',21,2023,'Technology',34.99,2),
146+
('Big Data Analytics',22,2020,'Technology',27.00,8),
147+
('Physics for Everyone',23,2018,'Science',23.50,15);
148+
149+
-- 25 MORE BASE BOOKS (MANUAL) = 50 MANUAL BOOKS
150+
INSERT INTO Books (title, author_id, publication_year, genre, price, stock) VALUES
151+
('Chemistry Basics',24,2021,'Science',17.50,6),
152+
('Biology Illustrated',25,2022,'Science',19.99,4),
153+
('Space Exploration',26,2023,'Science',28.00,7),
154+
('Programming in C++',27,2021,'Programming',22.50,10),
155+
('Web Development with HTML',28,2020,'Programming',15.99,12),
156+
('Mastering CSS',29,2022,'Programming',17.99,8),
157+
('JavaScript in Depth',30,2023,'Programming',24.99,3),
158+
('PHP & MySQL Guide',31,2021,'Programming',19.50,5),
159+
('Data Structures & Algorithms',32,2020,'Programming',26.50,7),
160+
('Linux for Everyone',33,2022,'Technology',29.50,4),
161+
('Networking Essentials',34,2021,'Technology',21.99,6),
162+
('Mobile App Development',35,2023,'Programming',31.00,3),
163+
('Android Development',36,2021,'Programming',18.50,9),
164+
('iOS Development',37,2022,'Programming',27.50,2),
165+
('Machine Learning Advanced',38,2023,'AI',39.99,4),
166+
('Quantum Computing',39,2022,'Technology',45.00,1),
167+
('Artificial Intelligence Future',40,2023,'AI',35.00,5),
168+
('Romantic Stories',41,2018,'Fiction',11.50,14),
169+
('Horror Night',42,2019,'Fiction',13.00,8),
170+
('Detective Mystery',43,2020,'Fiction',15.00,5),
171+
('Spiritual Awakening',44,2021,'Religion',16.99,6),
172+
('Philosophy of Life',45,2019,'Philosophy',18.99,9),
173+
('Economics Explained',46,2020,'Economics',24.00,7),
174+
('Business Management',47,2022,'Business',29.00,4),
175+
('Startup Guide',48,2021,'Business',19.50,11);
176+
177+
-- 20 BASE CUSTOMERS (MANUAL)
178+
INSERT INTO Customers (first_name, last_name, email, join_date) VALUES
179+
('Amit','Sharma','amit1@mail.com','2022-01-10'),
180+
('Riya','Mehta','riya2@mail.com','2023-02-14'),
181+
('John','King','john3@mail.com','2021-05-20'),
182+
('Karan','Patel','karan4@mail.com','2020-08-11'),
183+
('Sneha','Kapoor','sneha5@mail.com','2023-03-19'),
184+
('Pooja','Iyer','pooja6@mail.com','2022-09-21'),
185+
('Rahul','Singh','rahul7@mail.com','2021-11-23'),
186+
('Mohan','Das','mohan8@mail.com','2020-10-12'),
187+
('Preeti','Nair','preeti9@mail.com','2023-01-05'),
188+
('Daniel','Jones','dan10@mail.com','2022-04-17'),
189+
('Sophia','Brown','soph11@mail.com','2023-01-30'),
190+
('Emma','Wilson','emm12@mail.com','2022-06-21'),
191+
('Oliver','Scott','oli13@mail.com','2021-03-27'),
192+
('Lucas','Walker','luc14@mail.com','2021-07-14'),
193+
('Noah','Adams','noah15@mail.com','2023-02-11'),
194+
('Arjun','Khurana','arj16@mail.com','2020-01-11'),
195+
('Kabir','Rathod','kab17@mail.com','2021-02-05'),
196+
('Sanjay','Shah','san18@mail.com','2022-10-10'),
197+
('Deepa','Joshi','deep19@mail.com','2023-04-09'),
198+
('Zoya','Ali','zoy20@mail.com','2020-12-12');
199+
200+
-- 20 BASE ORDERS (MANUAL)
201+
INSERT INTO Orders (customer_id, book_id, order_date, quantity, total_amount) VALUES
202+
(1,1,'2023-01-10',2,40.00),
203+
(2,3,'2023-03-15',1,18.50),
204+
(3,5,'2022-07-20',1,40.00),
205+
(4,2,'2021-09-11',3,75.00),
206+
(5,10,'2023-04-19',2,52.00),
207+
(6,7,'2022-10-21',1,15.50),
208+
(7,12,'2021-12-23',1,32.00),
209+
(8,4,'2020-11-12',2,60.00),
210+
(9,6,'2023-02-05',1,12.99),
211+
(10,8,'2022-05-17',2,44.00),
212+
(11,15,'2023-02-28',1,18.00),
213+
(12,20,'2022-08-22',1,26.00),
214+
(13,25,'2021-04-01',2,47.00),
215+
(14,30,'2021-08-18',1,24.99),
216+
(15,40,'2023-02-11',3,105.00),
217+
(16,45,'2020-01-11',1,18.99),
218+
(17,48,'2021-02-05',2,39.00),
219+
(18,50,'2022-10-10',1,31.50),
220+
(19,11,'2023-04-09',1,24.99),
221+
(20,19,'2020-12-12',1,21.00);
222+
223+
-- =========================================
224+
-- AUTO-GENERATED EXTRA DATA
225+
-- To reach 2000+ total rows (especially in Orders)
226+
-- =========================================
227+
228+
-- -----------------------------------------
229+
-- MORE AUTHORS (AUTO) → about +150 extra
230+
-- -----------------------------------------
231+
SET @a := 0;
232+
INSERT INTO Authors (first_name, last_name, birth_year, nationality)
233+
SELECT CONCAT('AutoFirst', @a := @a + 1),
234+
CONCAT('AutoLast', @a),
235+
FLOOR(RAND()*40) + 1960,
236+
ELT(FLOOR(RAND()*6)+1,
237+
'American','British','Indian','Canadian','German','Australian')
238+
FROM information_schema.columns
239+
LIMIT 150;
240+
241+
-- -----------------------------------------
242+
-- MORE BOOKS (AUTO) → about +450 extra
243+
-- -----------------------------------------
244+
SET @b := 0;
245+
INSERT INTO Books (title, author_id, publication_year, genre, price, stock)
246+
SELECT CONCAT('Book Title ', @b := @b + 1),
247+
FLOOR(RAND() * (SELECT MAX(author_id) FROM Authors)) + 1,
248+
FLOOR(RAND()*24) + 2000, -- years 2000–2023
249+
ELT(FLOOR(RAND()*6)+1,
250+
'Programming','Fiction','Science','History','Fantasy','Business'),
251+
ROUND(RAND()*40 + 10, 2), -- price between 10 and 50
252+
FLOOR(RAND()*30) -- stock 0–29
253+
FROM information_schema.columns
254+
LIMIT 450;
255+
256+
-- -----------------------------------------
257+
-- MORE CUSTOMERS (AUTO) → about +180 extra
258+
-- -----------------------------------------
259+
SET @c := 20;
260+
INSERT INTO Customers (first_name, last_name, email, join_date)
261+
SELECT CONCAT('CustFirst', @c := @c + 1),
262+
CONCAT('CustLast', @c),
263+
CONCAT('customer', @c, '@mail.com'),
264+
DATE_ADD('2020-01-01', INTERVAL FLOOR(RAND()*1460) DAY) -- between 2020-2023
265+
FROM information_schema.columns
266+
LIMIT 180;
267+
268+
-- -----------------------------------------
269+
-- MORE ORDERS (AUTO) → about +2000 extra
270+
-- -----------------------------------------
271+
SET @o := 20;
272+
INSERT INTO Orders (customer_id, book_id, order_date, quantity, total_amount)
273+
SELECT
274+
FLOOR(RAND() * (SELECT MAX(customer_id) FROM Customers)) + 1 AS customer_id,
275+
FLOOR(RAND() * (SELECT MAX(book_id) FROM Books)) + 1 AS book_id,
276+
DATE_ADD('2021-01-01', INTERVAL FLOOR(RAND()*1460) DAY) AS order_date, -- 2021–2024 approx
277+
(@qty := FLOOR(RAND()*5) + 1) AS quantity,
278+
ROUND(@qty * (RAND()*40 + 10), 2) AS total_amount
279+
FROM information_schema.columns
280+
LIMIT 2000;
281+
282+
-- At this point:
283+
-- Authors ≈ 200+
284+
-- Books ≈ 500+
285+
-- Customers ≈ 200+
286+
-- Orders ≈ 2020+
287+
-- Total rows >> 2000

0 commit comments

Comments
 (0)