创建上面四张表并插入数据
时间: 2023-11-19 21:43:21 浏览: 93
填充数据表
好的,我将为您创建四张表并插入数据。以下是创建和插入数据的SQL语句:
1. 创建仓库表(warehouse):
```sql
CREATE TABLE warehouse (
whid VARCHAR(10) PRIMARY KEY,
city VARCHAR(20),
areawh INT
);
INSERT INTO warehouse (whid, city, areawh)
VALUES ('wh1', '北京', 370),
('wh2', '上海', 500),
('wh3', '广州', 200),
('wh4', '武汉', 400);
```
2. 创建职工表(emp):
```sql
CREATE TABLE emp (
empid VARCHAR(10) PRIMARY KEY,
whid VARCHAR(10),
salary INT,
FOREIGN KEY (whid) REFERENCES warehouse(whid)
);
INSERT INTO emp (empid, whid, salary)
VALUES ('e1', 'wh2', 11220),
('e3', 'wh1', 31210),
('e4', 'wh2', 41250),
('e6', 'wh3', 61230),
('e7', 'wh1', 71250);
```
3. 创建订购单表(ord):
```sql
CREATE TABLE ord (
spid VARCHAR(10),
orderno VARCHAR(10) PRIMARY KEY,
empid VARCHAR(10),
orderdate DATE,
FOREIGN KEY (empid) REFERENCES emp(empid)
);
INSERT INTO ord (spid, orderno, empid, orderdate)
VALUES ('s3', 'e3s7or67', 'e1', '2001-06-23'),
('s4', 'e1s4or73', 'e7', '2001-07-28'),
('s4', 'e7s4or76', 'e6', '2001-05-25'),
('s4', 'e3s4or79', 'e1', '2001-06-13'),
('s3', 'e3s3or91', 'e3', '2001-07-13');
```
4. 创建供应商表(supplier):
```sql
CREATE TABLE supplier (
spid VARCHAR(10) PRIMARY KEY,
spname VARCHAR(50),
address VARCHAR(100)
);
INSERT INTO supplier (spid, spname, address)
VALUES ('s4', '振华电子厂', '西安'),
('s6', '华通电子公司', '北京'),
('s7', '爱华电子厂', '北京');
```
以上是创建四张表和插入数据的SQL语句。您可以根据需要执行这些语句来创建表并插入数据。请注意,这里只提供了简单的示例数据,您可以根据实际情况进行修改和扩充。
阅读全文