用SQL语言创建物流管理系统数据库LogisticsDB
时间: 2024-09-23 18:03:55 浏览: 33
SQL语言-数据定义实验教程:创建与管理数据库表
在创建物流管理系统数据库LogisticsDB时,我们将需要设计几个关键表来存储相关的业务信息。以下是创建基本表格的示例,使用SQL语言:
1. **CompanyTable** (公司表)
```sql
CREATE TABLE Company (
ID INT PRIMARY KEY,
Name VARCHAR(100),
Address VARCHAR(255)
);
```
2. **WarehouseTable** (仓库表)
```sql
CREATE TABLE Warehouse (
ID INT PRIMARY KEY,
CompanyID INT,
Name VARCHAR(100),
Address VARCHAR(255),
FOREIGN KEY (CompanyID) REFERENCES Company(ID)
);
```
3. **ProductTable** (产品表)
```sql
CREATE TABLE Product (
ID INT PRIMARY KEY,
Name VARCHAR(100),
Description TEXT,
Quantity INT
);
```
4. **OrderTable** (订单表)
```sql
CREATE TABLE Order (
ID INT PRIMARY KEY,
CustomerID INT,
WarehouseID INT,
OrderDate DATE,
FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID),
FOREIGN KEY (WarehouseID) REFERENCES Warehouse(WarehouseID)
);
```
5. **OrderDetailsTable** (订单详情表 - 包含产品和数量信息)
```sql
CREATE TABLE OrderDetails (
OrderID INT,
ProductID INT,
Quantity INT,
Price DECIMAL(10, 2),
PRIMARY KEY (OrderID, ProductID),
FOREIGN KEY (OrderID) REFERENCES Order(ID),
FOREIGN KEY (ProductID) REFERENCES Product(ID)
);
```
6. **EmployeeTable** (员工表)
```sql
CREATE TABLE Employee (
ID INT PRIMARY KEY,
Name VARCHAR(100),
Role ENUM('Manager', 'Driver', 'Picker'),
WarehouseID INT,
FOREIGN KEY (WarehouseID) REFERENCES Warehouse(WarehouseID)
);
```
阅读全文