The document outlines the SQL commands for creating a database named 'Library' and its associated tables, including User, Document, User_Book, and Comments. It specifies the structure of each table, including fields and data types, as well as foreign key relationships. Additionally, it includes an insert command for adding an admin user to the User table.
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views
console-2
The document outlines the SQL commands for creating a database named 'Library' and its associated tables, including User, Document, User_Book, and Comments. It specifies the structure of each table, including fields and data types, as well as foreign key relationships. Additionally, it includes an insert command for adding an admin user to the User table.
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2
CREATE DATABASE IF NOT EXISTS Library;
USE Library;
drop table if exists Comments;
drop table if exists User_Book; DROP table if exists Document; Drop table if exists User; create table if not exists User ( username varchar(100) not null, primary key (username), password varchar(100) not null, fullname varchar(100) not null, allBorrowed int, borrowed int, type varchar(5) not null, gender varchar(10) , birthday varchar(20), avatar varchar(100) ); CREATE TABLE IF NOT EXISTS Document( ISBN int NOT NULL auto_increment, Title VARCHAR(255) NOT NULL , Author VARCHAR(100) NOT NULL , Year INT(10), imageData BLOB, ImageURL VARCHAR(255), remaining int not null, categories varchar(255), description text, publishDate varchar(100), PRIMARY KEY (ISBN) );
create table User_Book(
ISBN int NOT NULL , title varchar(255) not null , username varchar(100) not null, Author VARCHAR(100) NOT NULL , borrowDate date, returnDate date, foreign key (username) references user(username) on update cascade , foreign key (ISBN) references Document(ISBN) on update cascade );
create table Comments(
ISBN int not null, username varchar(100), content text, foreign key (username) references user(username) on update cascade , foreign key (ISBN) references Document(ISBN) on update cascade );
INSERT INTO User (username, password, fullname, type, borrowed)
value ('admin', '1', 'anhtuyen', 'A', 0); # insert ignore into User (username, password, fullname) # values ('anh15082005', '123456', 'soobin'); # SELECT * FROM Document # SELECT * FROM Document WHERE Title LIKE '%Lose%' select * from user_book; select * from document; select * from User;