Updates
This commit is contained in:
parent
2b0f503c9f
commit
876b5d8d40
Binary file not shown.
Binary file not shown.
|
|
@ -5,9 +5,9 @@ CREATE DATABASE library;
|
||||||
|
|
||||||
## Table creation
|
## Table creation
|
||||||
CREATE TABLE book (
|
CREATE TABLE book (
|
||||||
isbn INT PRIMARY KEY,
|
isbn BIGINT PRIMARY KEY,
|
||||||
title VARCHAR(100) NOT NULL,
|
title VARCHAR(50) NOT NULL,
|
||||||
author VARCHAR(100) NOT NULL,
|
author VARCHAR(50) NOT NULL,
|
||||||
year INT NOT NULL
|
year INT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -18,11 +18,11 @@ CREATE TABLE member (
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE loan (
|
CREATE TABLE loan (
|
||||||
isbn INT REFERENCES book(isbn),
|
isbn BIGINT REFERENCES book(isbn),
|
||||||
member_id INT REFERENCES member(member_id),
|
member_id INT REFERENCES member(member_id),
|
||||||
loan_date DATE NOT NULL,
|
loan_date DATE NOT NULL,
|
||||||
return_date DATE NOT NULL,
|
return_date DATE NOT NULL,
|
||||||
PRIMARY_KEY(isbn, member_id)
|
PRIMARY KEY(isbn, member_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
SHOW TABLES;
|
SHOW TABLES;
|
||||||
|
|
@ -31,8 +31,8 @@ SHOW TABLES;
|
||||||
### Insert at least 3 books and 2 members
|
### Insert at least 3 books and 2 members
|
||||||
INSERT INTO book VALUES
|
INSERT INTO book VALUES
|
||||||
(9781927077030, 'The Three Principles of the People - San Min Chu I', 'Sun Yat-Sen', 2011),
|
(9781927077030, 'The Three Principles of the People - San Min Chu I', 'Sun Yat-Sen', 2011),
|
||||||
(9780717802418, 'The Communist Manifesto', 'Karl Marx, Friedrich Engels', ''),
|
(9780717802418, 'The Communist Manifesto', 'Karl Marx, Friedrich Engels', 1848),
|
||||||
(9780131103627, 'C Programming Language, 2nd Edition', 'Brian W. Kernighan, Dennis M. Ritchie');
|
(9780131103627, 'C Programming Language, 2nd Edition', 'Brian W. Kernighan, Dennis M. Ritchie', 1988);
|
||||||
|
|
||||||
INSERT INTO member VALUES
|
INSERT INTO member VALUES
|
||||||
(10000001, 'Winnie The Pooh', 'winniethepooh@gmail.com'),
|
(10000001, 'Winnie The Pooh', 'winniethepooh@gmail.com'),
|
||||||
|
|
@ -44,15 +44,15 @@ SELECT * FROM member;
|
||||||
### Insert 2 loans
|
### Insert 2 loans
|
||||||
INSERT INTO loan VALUES
|
INSERT INTO loan VALUES
|
||||||
(9780131103627, 10000001, '2025-09-11', '2025-09-14'),
|
(9780131103627, 10000001, '2025-09-11', '2025-09-14'),
|
||||||
(9781927077030, 10000002, '2025-08-10, '2025-10-12')
|
(9781927077030, 10000002, '2025-08-10', '2025-10-12');
|
||||||
|
|
||||||
SELECT * FROM loan;
|
SELECT * FROM loan;
|
||||||
|
|
||||||
### Select all loans with member name and book title (JOIN)
|
### Select all loans with member name and book title (JOIN)
|
||||||
SELECT B.title, M.name
|
SELECT B.title, M.name
|
||||||
FROM loans L
|
FROM loan L
|
||||||
INNER JOIN book B ON B.isbn = L.isbn,
|
INNER JOIN book B ON L.isbn = B.isbn
|
||||||
INNER JOIN member M ON M.member_id = L.member_id;
|
INNER JOIN member M ON L.member_id = M.member_id;
|
||||||
|
|
||||||
### Update one Loan's ReturnDate
|
### Update one Loan's ReturnDate
|
||||||
UPDATE loan
|
UPDATE loan
|
||||||
|
|
@ -67,7 +67,7 @@ SELECT * FROM loan;
|
||||||
### Delete one loan record
|
### Delete one loan record
|
||||||
DELETE FROM loan
|
DELETE FROM loan
|
||||||
WHERE
|
WHERE
|
||||||
isbn = 9870131103627
|
isbn = 9780131103627
|
||||||
AND
|
AND
|
||||||
member_id = 10000001;
|
member_id = 10000001;
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 352 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 578 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 143 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 149 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 199 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 130 KiB |
Binary file not shown.
Loading…
Reference in New Issue