图书管理系统sql server代码
时间: 2023-06-29 22:02:14 浏览: 134
图书管理系统 C# SQL SERVER.zip
以下是一个简单的图书管理系统的 SQL Server 代码示例:
创建数据库:
```
CREATE DATABASE LibraryManagementSystem;
```
使用数据库:
```
USE LibraryManagementSystem;
```
创建图书表:
```
CREATE TABLE Books (
BookID INT PRIMARY KEY,
Title VARCHAR(100) NOT NULL,
Author VARCHAR(50) NOT NULL,
Publisher VARCHAR(50) NOT NULL,
PublishDate DATE NOT NULL,
ISBN VARCHAR(20) NOT NULL,
TotalQuantity INT NOT NULL,
AvailableQuantity INT NOT NULL
);
```
创建借阅者表:
```
CREATE TABLE Borrowers (
BorrowerID INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Address VARCHAR(100) NOT NULL,
Phone VARCHAR(20) NOT NULL,
Email VARCHAR(50) NOT NULL
);
```
创建借阅记录表:
```
CREATE TABLE BorrowRecords (
BorrowRecordID INT PRIMARY KEY,
BookID INT NOT NULL,
BorrowerID INT NOT NULL,
BorrowDate DATE NOT NULL,
ReturnDate DATE,
FOREIGN KEY (BookID) REFERENCES Books (BookID),
FOREIGN KEY (BorrowerID) REFERENCES Borrowers (BorrowerID)
);
```
创建还书记录表:
```
CREATE TABLE ReturnRecords (
ReturnRecordID INT PRIMARY KEY,
BorrowRecordID INT NOT NULL,
ReturnDate DATE NOT NULL,
Penalty DECIMAL(5,2),
FOREIGN KEY (BorrowRecordID) REFERENCES BorrowRecords (BorrowRecordID)
);
```
以上是一个简单的图书管理系统的 SQL Server 代码示例,可以根据需要进行修改和完善。
阅读全文