USE master GO IF EXISTS(SELECT name FROM sys.sysdatabases WHERE name = ‘BOOK‘) DROP DATABASE BOOK GO CREATE DATABASE BOOK GO USE BOOK GO CREATE TABLE STUDENT( stuID CHAR(10) PRIMARY KEY, stuName CHAR(10) NOT NULL, Major CHAR(50) NOT NULL ) GO CREATE TABLE BOOK( BID CHAR(10) PRIMARY KEY, Title CHAR(50) NOT NULL, Author CHAR(20) NOT NULL ) GO CREATE TABLE Borrow( BorrowID CHAR(10) PRIMARY KEY, stuID CHAR(10) FOREIGN KEY(stuID) REFERENCES dbo.STUDENT(stuID), BID CHAR(10) FOREIGN KEY(BID) REFERENCES dbo.BOOK(BID), T_time DATETIME NOT NULL, B_time DATETIME ) GO INSERT INTO dbo.STUDENT( stuID, stuName, Major )VALUES ( ‘1001‘, ‘林宏权‘,‘计算机‘) INSERT INTO dbo.STUDENT( stuID, stuName, Major )VALUES ( ‘1002‘, ‘何凡‘,‘计算机‘) INSERT INTO dbo.STUDENT( stuID, stuName, Major )VALUES ( ‘1003‘, ‘吴一‘,‘English‘) INSERT INTO dbo.STUDENT( stuID, stuName, Major )VALUES ( ‘1004‘, ‘何小东‘,‘化学‘) INSERT INTO dbo.STUDENT( stuID, stuName, Major )VALUES ( ‘1005‘, ‘王亮‘,‘工商管理‘) INSERT INTO dbo.STUDENT( stuID, stuName, Major )VALUES ( ‘1006‘, ‘孙兴‘,‘行政‘) INSERT INTO dbo.BOOK( BID, Title, Author )VALUES ( ‘B001‘, ‘ASP.NET应用与开发案例教程‘, ‘徐谡,徐立‘ ) INSERT INTO dbo.BOOK( BID, Title, Author )VALUES ( ‘B002‘, ‘ExtJS Web应用程序开发指南(第2版)‘, ‘卫军‘ ) INSERT INTO dbo.BOOK( BID, Title, Author )VALUES ( ‘B003‘, ‘Oracle.11g权威指南(第2版)‘, ‘谷长勇‘ ) INSERT INTO dbo.BOOK( BID, Title, Author )VALUES ( ‘B004‘, ‘锋利的SQL‘, ‘张洪举‘ ) INSERT INTO dbo.BOOK( BID, Title, Author )VALUES ( ‘B005‘, ‘ASP.NET MVC 4框架揭秘‘, ‘蒋金楠‘ ) INSERT INTO dbo.BOOK( BID, Title, Author )VALUES ( ‘B006‘, ‘疯狂Ajax讲义‘, ‘李刚‘ ) INSERT INTO dbo.Borrow ( BorrowID, stuID, BID, T_time, B_time )VALUES ( ‘T001‘, ‘1001‘, ‘B001‘, ‘2007-12-26‘, NULL ) INSERT INTO dbo.Borrow ( BorrowID, stuID, BID, T_time, B_time )VALUES ( ‘T002‘, ‘1004‘, ‘B003‘, ‘2008-1-5‘, NULL ) INSERT INTO dbo.Borrow ( BorrowID, stuID, BID, T_time, B_time )VALUES ( ‘T003‘, ‘1005‘, ‘B001‘, ‘2007-10-8‘, ‘2007-12-25‘ ) INSERT INTO dbo.Borrow ( BorrowID, stuID, BID, T_time, B_time )VALUES ( ‘T004‘, ‘1005‘, ‘B002‘, ‘2007-12-16‘, ‘2008-1-7‘ ) INSERT INTO dbo.Borrow ( BorrowID, stuID, BID, T_time, B_time )VALUES ( ‘T005‘, ‘1002‘, ‘B004‘, ‘2007-12-22‘, NULL ) INSERT INTO dbo.Borrow ( BorrowID, stuID, BID, T_time, B_time )VALUES ( ‘T006‘, ‘1005‘, ‘B005‘, ‘2008-1-6‘, NULL ) INSERT INTO dbo.Borrow ( BorrowID, stuID, BID, T_time, B_time )VALUES ( ‘T007‘, ‘1002‘, ‘B001‘, ‘2007-9-11‘, NULL ) INSERT INTO dbo.Borrow ( BorrowID, stuID, BID, T_time, B_time )VALUES ( ‘T008‘, ‘1005‘, ‘B004‘, ‘2007-12-10‘, NULL ) INSERT INTO dbo.Borrow ( BorrowID, stuID, BID, T_time, B_time )VALUES ( ‘T009‘, ‘1004‘, ‘B005‘, ‘2007-10-16‘, ‘2007-12-18‘ ) INSERT INTO dbo.Borrow ( BorrowID, stuID, BID, T_time, B_time )VALUES ( ‘T010‘, ‘1002‘, ‘B002‘, ‘2007-9-15‘, ‘2008-1-5‘ ) INSERT INTO dbo.Borrow ( BorrowID, stuID, BID, T_time, B_time )VALUES ( ‘T011‘, ‘1004‘, ‘B003‘, ‘2007-12-28‘, NULL ) INSERT INTO dbo.Borrow ( BorrowID, stuID, BID, T_time, B_time )VALUES ( ‘T012‘, ‘1002‘, ‘B003‘, ‘2007-12-30‘, NULL )
时间: 2024-12-16 10:10:18