-
Notifications
You must be signed in to change notification settings - Fork 0
/
339DatabaseClassQuery.sql
133 lines (110 loc) · 3.66 KB
/
339DatabaseClassQuery.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
CREATE TABLE Genres (
Id INT PRIMARY KEY IDENTITY,
GenreName VARCHAR(120) NOT NULL
);
CREATE TABLE Patrons (
Id INT PRIMARY KEY IDENTITY,
FirstName VARCHAR(120) NOT NULL,
LastName VARCHAR(120) NOT NULL,
DateOfBirth DATE NOT NULL,
Email VARCHAR(120) NOT NULL,
);
CREATE TABLE Authors (
Id INT PRIMARY KEY IDENTITY,
FirstName VARCHAR(40) NOT NULL,
LastName VARCHAR(40) NOT NULL,
);
CREATE TABLE Books (
Id INT PRIMARY KEY IDENTITY,
Title VARCHAR(120) NOT NULL,
AuthorId INT FOREIGN KEY REFERENCES Authors NOT NULL,
PublishingYear INT NOT NULL,
ISBN BIGINT UNIQUE NOT NULL,
AvailableCopies int NOT NULL,
GenreId INT FOREIGN KEY REFERENCES Genres NOT NULL
);
CREATE TABLE Loans (
Id INT PRIMARY KEY IDENTITY,
BookId INT FOREIGN KEY REFERENCES Books NOT NULL,
PatronId INT FOREIGN KEY REFERENCES Patrons NOT NULL,
CheckoutDate DATE NOT NULL,
DueDate DATE NOT NULL,
ReturnDate DATE NOT NULL
);
INSERT INTO Patrons (FirstName, LastName, DateOfBirth, Email)
VALUES
('Patricia', 'White', '1995-08-30', '[email protected]'),
('Tina', 'Robinson', '1990-04-23', '[email protected]'),
('Olivia','Young','2004-01-30','[email protected]'),
('Jasmine', 'Parker', '2006-05-10', '[email protected]'),
('Gabriel', 'Martin', '2007-07-31', '[email protected]'),
('Ethan', 'Jackson', '2005-11-26', '[email protected]'),
('Frank', 'Miller', '1980-12-22', '[email protected]'),
('Henry', 'Wilson', '1996-04-18', '[email protected]'),
('Bella', 'Evans','2002-06-22', '[email protected]'),
('Aiden', 'Carter', '2001-01-15', '[email protected]');
INSERT INTO Genres (GenreName)
VALUES ('Mystery'),
('Sci-Fi'),
('Fantasy'),
('Romance'),
('Horror'),
('Historical'),
('Thriller'),
('Biography'),
('Adventure'),
('Graphic Novel'),
('Poetry');
INSERT INTO Genres (GenreName)
Values ('Contemporary'),
('Dystopian'),
('Memoir');
INSERT INTO Patrons (FirstName, LastName, DateOfBirth, Email)
VALUES ('Keira', 'Stewart', '2004-05-25', '[email protected]');
INSERT INTO Authors (FirstName, LastName)
VALUES
('Cohen', 'Schlicher'),
('Keira', 'Stewart'),
('Aaron', 'Madison'),
('Dan', 'Smith'),
('Patrick', 'McDowell'),
('Ghassan', 'Alkadi'),
('Samuel', 'Echols'),
('Gabriel', 'Bradford'),
('Luke', 'White'),
('Peyton', 'Perry');
INSERT INTO Books
(Title, AuthorId, PublishingYear, ISBN, AvailableCopies, GenreId)
VALUES
('How to Code: Not For Beginners', 7, 2004, 123456789101112, 2, 1),
('Dad Jokes for Software Developers', 8, 2015, 234567891011345, 1, 2),
('SQL 101', 6, 2024, 345678910111213, 1, 3),
('How to Get a Girlfriend', 5, 2022, 134567890134567, 0, 1),
('Samuel Echols: An Autobiography', 7, 2023, 134567892340123, 3, 2),
('How to Get Through College', 1, 2024, 15678901234567, 3, 3);
INSERT INTO Books
(Title, AuthorId, PublishingYear, ISBN, AvailableCopies, GenreId)
VALUES
('Cool Old Book', 2, 1990, 109876543212345, 0, 1);
INSERT INTO Authors
(FirstName, LastName)
VALUES
('Generic', 'Name');
INSERT INTO Loans
(BookId, PatronId, CheckoutDate, DueDate, ReturnDate)
VALUES
(1, 1, '2024-08-18', '2024-08-30', '2024-08-28'),
(2, 2, '2023-11-01', '2023-11-10', '2023-11-11');
UPDATE Genres SET GenreName = 'Historical' WHERE GenreName = 'Historical Fiction';
UPDATE Books
SET Title = 'Uncool Old Book'
WHERE Title = 'Cool Old Book';
UPDATE Authors
SET FirstName = 'Cone'
WHERE FirstName = 'Cohen';
UPDATE Genres SET GenreName = 'Historical' WHERE GenreName = 'Historical Fiction';
SELECT * FROM Authors;
SELECT * FROM Books;
SELECT * FROM Genres;
SELECT * FROM Patrons;
SELECT * FROM Loans;