在SQL中用语句实现1.物资管理子系统的关系模式 仓库(仓库号、面积、电话号码) 零件(零件号、名称、规格、描述) 供应商(供应商号、姓名、地址、电话号码) 项目(项目号、预算、开工日期) 职工(职工号、姓名、年龄、职称) 入库记录(入库记录号、仓库号、零件号、供应商号、项目号、入库日期) 入库细节(入库记录号、零件号、单价) 出库记录(出库记录号、仓库号、零件号、项目号、出库日期) 出库细节(出库记录号、零件号、单价)遵循实体完整性,参照完整性,用户自定义完整性
时间: 2023-07-04 13:14:28 浏览: 102
以下是SQL语句实现物资管理子系统的关系模式:
1. 创建仓库表:
```
CREATE TABLE Warehouse (
Warehouse_ID INT PRIMARY KEY,
Area INT,
Phone_Number VARCHAR(20)
);
```
2. 创建零件表:
```
CREATE TABLE Part (
Part_ID INT PRIMARY KEY,
Name VARCHAR(50),
Spec VARCHAR(50),
Description VARCHAR(200)
);
```
3. 创建供应商表:
```
CREATE TABLE Supplier (
Supplier_ID INT PRIMARY KEY,
Name VARCHAR(50),
Address VARCHAR(100),
Phone_Number VARCHAR(20)
);
```
4. 创建项目表:
```
CREATE TABLE Project (
Project_ID INT PRIMARY KEY,
Budget DECIMAL(10, 2),
Start_Date DATE
);
```
5. 创建职工表:
```
CREATE TABLE Employee (
Employee_ID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
Title VARCHAR(20)
);
```
6. 创建入库记录表:
```
CREATE TABLE Inbound_Record (
Inbound_ID INT PRIMARY KEY,
Warehouse_ID INT,
Part_ID INT,
Supplier_ID INT,
Project_ID INT,
Inbound_Date DATE,
FOREIGN KEY (Warehouse_ID) REFERENCES Warehouse(Warehouse_ID),
FOREIGN KEY (Part_ID) REFERENCES Part(Part_ID),
FOREIGN KEY (Supplier_ID) REFERENCES Supplier(Supplier_ID),
FOREIGN KEY (Project_ID) REFERENCES Project(Project_ID)
);
```
7. 创建入库细节表:
```
CREATE TABLE Inbound_Detail (
Inbound_ID INT,
Part_ID INT,
Price DECIMAL(10, 2),
FOREIGN KEY (Inbound_ID) REFERENCES Inbound_Record(Inbound_ID),
FOREIGN KEY (Part_ID) REFERENCES Part(Part_ID),
PRIMARY KEY (Inbound_ID, Part_ID)
);
```
8. 创建出库记录表:
```
CREATE TABLE Outbound_Record (
Outbound_ID INT PRIMARY KEY,
Warehouse_ID INT,
Part_ID INT,
Project_ID INT,
Outbound_Date DATE,
FOREIGN KEY (Warehouse_ID) REFERENCES Warehouse(Warehouse_ID),
FOREIGN KEY (Part_ID) REFERENCES Part(Part_ID),
FOREIGN KEY (Project_ID) REFERENCES Project(Project_ID)
);
```
9. 创建出库细节表:
```
CREATE TABLE Outbound_Detail (
Outbound_ID INT,
Part_ID INT,
Price DECIMAL(10, 2),
FOREIGN KEY (Outbound_ID) REFERENCES Outbound_Record(Outbound_ID),
FOREIGN KEY (Part_ID) REFERENCES Part(Part_ID),
PRIMARY KEY (Outbound_ID, Part_ID)
);
```
在创建这些数据表时,需要注意实体完整性、参照完整性以及用户自定义完整性的要求,例如在创建入库记录表和入库细节表时,需要使用外键来实现参照完整性。
阅读全文