CREATE TABLE Students
(
StudentID int PRIMARY KEY NOT NULL,
StudName varchar(50) NOT NULL
);
CREATE TABLE Books
(
BookID int PRIMARY KEY,
Title varchar(50) NOT NULL,
Author varchar(50)
);
CREATE TABLE Borrow
(
BorrowID int PRIMARY KEY,
StudentID int NOT NULL,
BookID int NOT NULL
);
INSERT INTO Students
(StudentID, StudName)
VALUES
('1','Alquisada');
INSERT INTO Students
(StudentID, StudName)
VALUES
('2','Ardena'),
('3','Suner'),
('4','Eusuya'),
('5', 'Arca');
SELECT * FROM Students;
SELECT StudName FROM Students;
INSERT INTO Books
(BookID, Title, Author)
VALUES
('1','Harry Potter','JK Rowling');
INSERT INTO Books
(BookID, Title, Author)
VALUES
('2','Percy Jackson','Rick Riordan');
SELECT * FROM Books;
INSERT INTO Borrow
(BorrowID, StudentID, BookID)
VALUES
('1','1','1'),
('2','1','2'),
('3','2','1');
SELECT * FROM Borrow;
SELECT
Students.StudName, Books.Title, Books.Author
FROM Students
INNER JOIN Borrow
ON Students.StudentID = Borrow.StudentID
INNER JOIN Books
ON Borrow.BookID = Books.BookID;
SELECT
Students.StudName, Books.Title, Books.Author
FROM Students
INNER JOIN Borrow
ON Students.StudentID = Borrow.StudentID
INNER JOIN Books
ON Borrow.BookID = Books.BookID
WHERE Students.StudentID = '2'
;
DROP TABLE Books;
ALTER TABLE Books
ALTER COLUMN Title varchar(50);
ALTER TABLE Books
ADD Book_Desc varchar(100);
ALTER TABLE Books
DROP COLUMN Book_Desc;
UPDATE Books
SET Title = 'Title 2', Author = 'dfgdfgfdg'
WHERE BookID = '2';
No comments:
Post a Comment