202 lines
7.3 KiB
Plaintext
202 lines
7.3 KiB
Plaintext
-- Insert data into Genres
|
||
INSERT INTO Genres (GenreName) VALUES
|
||
('None'), ('Adventure'), ('Fantasy'), ('Mystery'), ('Fiction'), ('Suspense'), ('Romance'), ('Crime'), ('Talent'), ('Realism'), ('Horror'), ('Historical');
|
||
|
||
-- Insert data into Books (with updated GenreIDs and Status)
|
||
INSERT INTO Books (Title, Author, PublishYear, Status, GenreMask) VALUES
|
||
('The Hobbit', 'J.R.R. Tolkien', 1937, 3, 1024), -- On Stock, Fantasy
|
||
('Pride and Prejudice', 'Jane Austen', 1813, 3, 2 | 128), -- On Stock, Romance | Realism
|
||
('The Da Vinci Code', 'Dan Brown', 2003, 4, 4 | 16), -- Borrowed, Mystery | Suspense
|
||
('1984', 'George Orwell', 1949, 3, 8 | 128), -- On Stock, Fiction | Realism
|
||
('To Kill a Mockingbird', 'Harper Lee', 1960, 4, 8 | 128), -- Borrowed, Fiction | Realism
|
||
('The Great Gatsby', 'F. Scott Fitzgerald', 1925, 3, 2 | 128), -- On Stock, Romance | Realism
|
||
('The Time Traveler''s Wife', 'Audrey Niffenegger', 2003, 4, 2 | 1024), -- Borrowed, Romance | Fantasy
|
||
('The Secret Garden', 'Frances Hodgson Burnett', 1911, 2, 1), -- in IDassignment state, Adventure
|
||
('Gone Girl', 'Gillian Flynn', 2012, 1, 4 | 16 | 32), -- Ordered, Mystery | Suspense | Crime
|
||
('A Game of Thrones', 'George R.R. Martin', 1996, 3, 1 | 1024 | 8), -- On Stock, Adventure | Fantasy | Fiction
|
||
('Harry Potter and the Sorcerer''s Stone', 'J.K. Rowling', 1997, 3, 1 | 8 | 1024), -- On Stock, Adventure | Fiction | Fantasy
|
||
('The Martian', 'Andy Weir', 2011, 3, 1 | 8), -- On Stock, Adventure | Fiction
|
||
('Little Women', 'Louisa May Alcott', 1868, 5, 2), -- Debited, Romance
|
||
('The Seven Husbands of Evelyn Hugo', 'Taylor Jenkins Reid', 2017, 3, 2 | 128); -- On Stock, Romance | Realism
|
||
-- ('Where the Crawdads Sing', 'Delia Owens', 2018, ); -- Fiction, Borrowed
|
||
-- ('The Lord of the Rings', 'J.R.R. Tolkien', 1954, ), -- Fantasy, Unable
|
||
-- ('The Nightingale', 'Kristin Hannah', 2015, ), -- Romance, Borrowed
|
||
-- ('The Book Thief', 'Markus Zusak', 2005, ), -- Fiction, On Stock
|
||
-- ('The Help', 'Kathryn Stockett', 2009, ), -- Fiction, Borrowed
|
||
-- ('The Girl on the Train', 'Paula Hawkins', 2015, ), -- Suspense, On Stock
|
||
-- ('The Girl with the Dragon Tattoo', 'Stieg Larsson', 2005, ), -- Suspense, On Stock
|
||
-- ('The Catcher in the Rye', 'J.D. Salinger', 1951, ), -- Fiction, Unable
|
||
-- ('The Hunger Games', 'Suzanne Collins', 2008, ), -- Suspense, Borrowed
|
||
-- ('The Silent Patient', 'Alex Michaelides', 2019, ), -- Mystery, Unable
|
||
-- ('And Then There Were None', 'Agatha Christie', 1939, ), -- Mystery, Unable
|
||
|
||
-- Insert data into LibrarianCards (reference existing GenreIDs)
|
||
INSERT INTO LibrarianCards (FIO, GenreMask) VALUES
|
||
('Carla R.E.', 4 | 16 | 32),
|
||
('Bonnet D.P.', 2 | 128),
|
||
('Gabriel W.T.', 1 | 1024 | 8);
|
||
|
||
-- Insert data into CustomerCards
|
||
INSERT INTO CustomerCards (FIO, AgeBirthday) VALUES
|
||
('Winsent G.P.', '2000-01-15'),
|
||
('Quincy P.R.', '2005-05-20'),
|
||
('Emily Y.N.', '2009-11-10'),
|
||
('Frank A.K.', '2007-07-25'),
|
||
('Marinett J.C.', '2004-03-01'),
|
||
('Alice B.T.', '2002-08-10'),
|
||
('Bob C.L.', '1998-03-25'),
|
||
('Charlie D.M.', '2011-06-18'),
|
||
('Diana E.S.', '1995-12-05'),
|
||
('Eve F.W.', '2007-09-30');
|
||
|
||
|
||
-- Insert more data into Orders
|
||
INSERT INTO Orders (CardID, LibrarianID, BorrowDate) VALUES
|
||
(6, 1, '2024-05-10 11:00:00'),
|
||
(1, 3, '2024-05-15 15:30:00'),
|
||
(9, 1, '2024-05-20 09:45:00'),
|
||
(3, 2, '2024-05-25 13:15:00'),
|
||
(4, 3, '2024-06-01 10:00:00'),
|
||
(5, 1, '2024-06-05 16:45:00'),
|
||
(10, 2, '2024-06-10 14:15:00'),
|
||
(1, 1, '2024-07-15 10:30:00'),
|
||
(10, 3, '2024-07-20 12:45:00'),
|
||
(7, 1, '2024-07-25 17:00:00'),
|
||
(2, 1, '2024-08-20 09:45:00'),
|
||
(8, 2, '2024-08-25 13:15:00'),
|
||
(4, 3, '2024-09-01 10:00:00'),
|
||
(5, 1, '2024-09-12 16:45:00'),
|
||
(8, 3, '2024-09-16 10:00:00'),
|
||
(6, 1, '2024-09-24 16:45:00'),
|
||
(9, 2, '2024-10-10 14:15:00'),
|
||
(1, 1, '2024-10-15 10:30:00'),
|
||
(7, 3, '2024-12-09 12:45:00'),
|
||
(3, 1, '2024-12-25 17:00:00'),
|
||
(4, 1, '2024-12-20 09:45:00');
|
||
|
||
-- Insert more data into Registrations
|
||
INSERT INTO Registrations (OrderID, BookID, Note) VALUES
|
||
(1, 6, '07-10'),
|
||
(2, 10, '07-15'),
|
||
(3, 2, '07-20'),
|
||
(4, 7, '07-25'),
|
||
(5, 11, '08-07'),
|
||
(5, 9, '08-07'),
|
||
(6, 8, '08-10'),
|
||
(7, 4, '08-15'),
|
||
(7, 5, '08-15'),
|
||
(7, 6, '08-15'),
|
||
(7, 7, '08-15'),
|
||
(8, 11, '08-18'),
|
||
(9, 9, '08-27'),
|
||
(9, 3, '08-10'),
|
||
(10, 4, '08-15'),
|
||
(11, 8, '07-25'),
|
||
(12, 10, '08-01'),
|
||
(13, 12, '08-05'),
|
||
(14, 3, '08-10'),
|
||
(14, 4, '08-15'),
|
||
(14, 5, '08-20'),
|
||
(14, 1, '08-25'),
|
||
(15, 6, '08-25'),
|
||
(16, 7, '07-25'),
|
||
(17, 8, '08-01'),
|
||
(17, 9, '08-05'),
|
||
(18, 11, '08-10'),
|
||
(18, 4, '08-15'),
|
||
(18, 7, '07-25'),
|
||
(18, 1, '08-01');
|
||
|
||
-- Insert more data into Updates – Multiple updates on the same day
|
||
INSERT INTO Updates (LastUpdate, UpdBoundary, Note, LibrarianID, CardID) VALUES
|
||
('2017-05-10', '2021-03-15', 'Card Received', 3, 1),
|
||
('2022-11-22', '2025-08-20', 'Renewed card', 2, 3),
|
||
('2016-02-01', '2020-01-10', 'Card Received', 2, 2),
|
||
('2020-09-18', '2024-12-05', 'Updated address', 1, 4),
|
||
('2018-07-05', '2024-06-25', 'Card Received', 3, 5),
|
||
('2023-10-26', '2024-04-15', 'Lost card, reissued', 1, 1),
|
||
('2023-10-26', '2024-05-10', 'Payment overdue', 2, 5),
|
||
('2024-01-15', '2024-07-15', 'Address change', 3, 2),
|
||
('2024-03-01', '2024-09-01', 'Renewed card', 1, 4),
|
||
('2024-03-01', '2024-09-01', 'Fee payment', 1, 3), -- Multiple updates on the same day
|
||
('2024-03-10', '2025-01-10', 'Card Received', 2, 6),
|
||
('2024-04-20', '2025-02-20', 'Renewal', 3, 1),
|
||
('2024-05-10', '2025-03-10', 'New Card issued', 1, 5);
|
||
|
||
-- Drop the table if it exists -----------------------------
|
||
DROP TABLE IF EXISTS Updates;
|
||
|
||
DROP TABLE IF EXISTS Registrations;
|
||
DROP TABLE IF EXISTS Orders;
|
||
|
||
DROP TABLE IF EXISTS LibrarianCards;
|
||
DROP TABLE IF EXISTS CustomerCards;
|
||
|
||
DROP TABLE IF EXISTS Books;
|
||
DROP TABLE IF EXISTS Genres;
|
||
|
||
-- Create the Genres table [ 1 ]
|
||
CREATE TABLE Genres (
|
||
GenreID SERIAL PRIMARY KEY,
|
||
GenreName VARCHAR(255) NOT NULL UNIQUE
|
||
);
|
||
|
||
-- Create the Books table [ 2 ]
|
||
CREATE TABLE Books (
|
||
BookID SERIAL PRIMARY KEY,
|
||
Title VARCHAR(255) NOT NULL,
|
||
Author VARCHAR(255) NOT NULL,
|
||
PublishYear INTEGER,
|
||
Status INTEGER CHECK (Status IN (0, 1, 2, 3, 4, 5)),
|
||
GenreMask INTEGER DEFAULT 0
|
||
-- CountOnStock INTEGER CHECK (CountOnStock >= 0),
|
||
-- > GenreID INTEGER REFERENCES Genres(GenreID)
|
||
);
|
||
|
||
-- > ALTER TABLE Books DROP COLUMN GenreID;
|
||
|
||
-- Now, add the GenreMask column to the Books table
|
||
-- [ ! ] ALTER TABLE Books ADD COLUMN GenreMask INTEGER DEFAULT 0; -- Using INTEGER to store bitmask
|
||
|
||
|
||
-- Create the CustomerCards table [ 3 ]
|
||
CREATE TABLE CustomerCards (
|
||
CardID SERIAL PRIMARY KEY,
|
||
FIO VARCHAR(255) NOT NULL,
|
||
AgeBirthday DATE
|
||
);
|
||
|
||
-- Create the LibrarianCards table [ 4 ]
|
||
CREATE TABLE LibrarianCards (
|
||
CardID SERIAL PRIMARY KEY,
|
||
FIO VARCHAR(255) NOT NULL,
|
||
GenreMask INTEGER DEFAULT 0
|
||
-- GenreID INTEGER REFERENCES Genres(GenreID)
|
||
);
|
||
|
||
-- Create the Orders table [ 5 ]
|
||
CREATE TABLE Orders (
|
||
OrderID SERIAL PRIMARY KEY,
|
||
CardID INTEGER REFERENCES CustomerCards(CardID) NOT NULL,
|
||
LibrarianID INTEGER REFERENCES LibrarianCards(CardID) NOT NULL,
|
||
BorrowDate TIMESTAMP WITH TIME ZONE
|
||
);
|
||
|
||
-- Create the Registrations table [ 6 ]
|
||
CREATE TABLE Registrations (
|
||
ID SERIAL PRIMARY KEY,
|
||
OrderID INTEGER REFERENCES Orders(OrderID) NOT NULL,
|
||
BookID INTEGER REFERENCES Books(BookID) NOT NULL,
|
||
Note TEXT
|
||
);
|
||
|
||
-- Create the Updates table [ 7 ]
|
||
CREATE TABLE Updates (
|
||
ID SERIAL PRIMARY KEY,
|
||
LastUpdate DATE NOT NULL,
|
||
UpdBoundary DATE,
|
||
Note TEXT,
|
||
LibrarianID INTEGER REFERENCES LibrarianCards(CardID) NOT NULL,
|
||
CardID INTEGER REFERENCES CustomerCards(CardID) NOT NULL
|
||
);
|