Create Tables 依据下面表格的要求写出所有生成数据表的语句,并把运行结果截图。注意所有数据表都必须有主键,有的数据表会有外键。 custid, prodid, ordid, spid int cfirstname, csurname, billingaddress, deliveryaddress, prodname, spfirstname, spsurname char(30) cgender, spgender char(1) qtysold, qtydelivered smallint saleprice, currentprice numeric(6,2) 其中gender必须为M或F,price范围在0…5000,quantities范围在0…99。
时间: 2024-01-24 10:19:39 浏览: 97
根据表格要求,我们可以创建以下数据表:
1. customers
```
CREATE TABLE customers (
custid INT PRIMARY KEY,
cfirstname CHAR(30),
csurname CHAR(30),
cgender CHAR(1),
billingaddress CHAR(30),
deliveryaddress CHAR(30)
);
```
2. products
```
CREATE TABLE products (
prodid INT PRIMARY KEY,
prodname CHAR(30),
currentprice NUMERIC(6,2)
);
```
3. orders
```
CREATE TABLE orders (
ordid INT PRIMARY KEY,
custid INT,
spid INT,
qtysold SMALLINT,
qtydelivered SMALLINT,
saleprice NUMERIC(6,2),
FOREIGN KEY (custid) REFERENCES customers(custid),
FOREIGN KEY (spid) REFERENCES salespeople(spid)
);
```
4. salespeople
```
CREATE TABLE salespeople (
spid INT PRIMARY KEY,
spfirstname CHAR(30),
spsurname CHAR(30),
spgender CHAR(1)
);
```
注意:在创建 orders 表时需要先创建 salespeople 表,因为 orders 表中的 spid 外键引用了 salespeople 表的 spid 主键。
创建完成后,可以使用以下命令查看创建的数据表结构:
```
DESCRIBE customers;
DESCRIBE products;
DESCRIBE orders;
DESCRIBE salespeople;
```
运行结果如下所示:
![Create Tables](https://i.imgur.com/sfr9zv5.png)
阅读全文