-- 创建book表格 CREATE TABLE book ( book_id INT(11) NOT NULL AUTO_INCREMENT, title VARCHAR(255) DEFAULT NULL, author VARCHAR(255) DEFAULT NULL, publisher VARCHAR(255) DEFAULT NULL, publication_date DATE DEFAULT NULL, PRIMARY KEY (book_id) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4; -- 创建borrow表格 CREATE TABLE borrow ( borrow_id INT(11) NOT NULL AUTO_INCREMENT, book_id INT(11) NOT NULL, user_id VARCHAR(255) NOT NULL, borrow_date DATE NOT NULL, return_date DATE NOT NULL, PRIMARY KEY (borrow_id), KEY book_id (book_id), FOREIGN KEY (book_id) REFERENCES book (book_id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- 创建user表格 CREATE TABLE user ( user_id VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, phone VARCHAR(255) NOT NULL, PRIMARY KEY (user_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
这些代码将创建三个表格:book、borrow和user。book表格用于存储书籍信息,borrow表格用于存储用户借阅信息,user表格用于存储用户信息。其中,borrow表格的book_id列是对book表格中book_id列的外键引用,用于建立两个表格之间的关联。