This commit is contained in:
Win 2025-10-02 02:17:43 +07:00
parent 2b0f503c9f
commit 876b5d8d40
10 changed files with 12 additions and 12 deletions

View File

@ -5,9 +5,9 @@ CREATE DATABASE library;
## Table creation
CREATE TABLE book (
isbn INT PRIMARY KEY,
title VARCHAR(100) NOT NULL,
author VARCHAR(100) NOT NULL,
isbn BIGINT PRIMARY KEY,
title VARCHAR(50) NOT NULL,
author VARCHAR(50) NOT NULL,
year INT NOT NULL
);
@ -18,11 +18,11 @@ CREATE TABLE member (
);
CREATE TABLE loan (
isbn INT REFERENCES book(isbn),
isbn BIGINT REFERENCES book(isbn),
member_id INT REFERENCES member(member_id),
loan_date DATE NOT NULL,
return_date DATE NOT NULL,
PRIMARY_KEY(isbn, member_id)
PRIMARY KEY(isbn, member_id)
);
SHOW TABLES;
@ -31,8 +31,8 @@ SHOW TABLES;
### Insert at least 3 books and 2 members
INSERT INTO book VALUES
(9781927077030, 'The Three Principles of the People - San Min Chu I', 'Sun Yat-Sen', 2011),
(9780717802418, 'The Communist Manifesto', 'Karl Marx, Friedrich Engels', ''),
(9780131103627, 'C Programming Language, 2nd Edition', 'Brian W. Kernighan, Dennis M. Ritchie');
(9780717802418, 'The Communist Manifesto', 'Karl Marx, Friedrich Engels', 1848),
(9780131103627, 'C Programming Language, 2nd Edition', 'Brian W. Kernighan, Dennis M. Ritchie', 1988);
INSERT INTO member VALUES
(10000001, 'Winnie The Pooh', 'winniethepooh@gmail.com'),
@ -44,15 +44,15 @@ SELECT * FROM member;
### Insert 2 loans
INSERT INTO loan VALUES
(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 all loans with member name and book title (JOIN)
SELECT B.title, M.name
FROM loans L
INNER JOIN book B ON B.isbn = L.isbn,
INNER JOIN member M ON M.member_id = L.member_id;
FROM loan L
INNER JOIN book B ON L.isbn = B.isbn
INNER JOIN member M ON L.member_id = M.member_id;
### Update one Loan's ReturnDate
UPDATE loan
@ -67,7 +67,7 @@ SELECT * FROM loan;
### Delete one loan record
DELETE FROM loan
WHERE
isbn = 9870131103627
isbn = 9780131103627
AND
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