用SQL语句创建上述数据库
时间: 2024-03-10 13:43:53 浏览: 120
xkqk选课情况-使用SQL语句创建数据库创建表
以下是用 SQL 语句创建上述数据库的代码:
创建出版社表:
```
CREATE TABLE Publisher (
PublisherID INT PRIMARY KEY AUTO_INCREMENT,
PublisherName VARCHAR(50),
PublisherAddress VARCHAR(100),
PublisherPhone VARCHAR(20)
);
```
创建教材类型表:
```
CREATE TABLE TextbookType (
TypeID INT PRIMARY KEY AUTO_INCREMENT,
TypeName VARCHAR(50)
);
```
创建教材表:
```
CREATE TABLE Textbook (
TextbookID INT PRIMARY KEY AUTO_INCREMENT,
TextbookName VARCHAR(50),
TypeID INT,
PublisherID INT,
UnitPrice FLOAT,
FOREIGN KEY (TypeID) REFERENCES TextbookType(TypeID),
FOREIGN KEY (PublisherID) REFERENCES Publisher(PublisherID)
);
```
创建学生表:
```
CREATE TABLE Student (
StudentID INT PRIMARY KEY AUTO_INCREMENT,
StudentName VARCHAR(50),
StudentGender VARCHAR(10),
StudentAge INT,
StudentClass VARCHAR(50),
StudentPhone VARCHAR(20)
);
```
创建教材订购表:
```
CREATE TABLE TextbookOrder (
OrderID INT PRIMARY KEY AUTO_INCREMENT,
StudentID INT,
TextbookID INT,
OrderNum INT,
OrderDate DATE,
FOREIGN KEY (StudentID) REFERENCES Student(StudentID),
FOREIGN KEY (TextbookID) REFERENCES Textbook(TextbookID)
);
```
创建教材库存表:
```
CREATE TABLE TextbookStock (
StockID INT PRIMARY KEY AUTO_INCREMENT,
TextbookID INT,
StockNum INT,
FOREIGN KEY (TextbookID) REFERENCES Textbook(TextbookID)
);
```
创建教材领用表:
```
CREATE TABLE TextbookReceive (
ReceiveID INT PRIMARY KEY AUTO_INCREMENT,
StudentID INT,
TextbookID INT,
ReceiveNum INT,
ReceiveDate DATE,
FOREIGN KEY (StudentID) REFERENCES Student(StudentID),
FOREIGN KEY (TextbookID) REFERENCES Textbook(TextbookID)
);
```
创建教材订阅统计表:
```
CREATE TABLE TextbookSubscription (
SubscriptionID INT PRIMARY KEY AUTO_INCREMENT,
TextbookID INT,
SubscriptionNum INT,
FOREIGN KEY (TextbookID) REFERENCES Textbook(TextbookID)
);
```
以上 SQL 代码可以在 MySQL 或其他支持 SQL 语句的数据库管理系统中执行。
阅读全文