--商品goods(商品号goodsId,商品名goodsName,
--单价unitprice,商品类别category,供应商provider)
--客户customer(客户号customerId,姓名name,住址address,电邮email
--性别sex,身份证cardId)
--购买purchase(客户号customerId,商品号goodsId,购买数量nums)
--请用SQL语言完成下列功能;
--1 建表,在定义中要求声明:
-- (1)每个表的主外键
-- (2)客户的姓名不能为空值;
-- (3)单价必须大于0,购买数量必须在1到30之间;
-- (4)点又不能够重复
-- (5)客户的性别必须是 男 或者 女,默认是男
--goods 表
create table goods
(goodsId nvarchar(50) primary key ,
goodsName nvarchar(80) not null,
unitprice numeric(10,2) check (unitprice>0),
category nvarchar(30) check(category in ('food','daily') ),
provider nvarchar (50)
)
--customer表
drop table customer
create table customer
(customerId nvarchar(50) primary key,
cusname nvarchar(50) not null,
address nvarchar(50),
email nvarchar(100) unique,
sex nchar(1) check ( sex in ('男','女')) default '男',
cardId nvarchar(18)
)
--purchase表
create table purchase
(customerId nvarchar(50) foreign key references customer(customerId),
goodsId nvarchar(50) foreign key references goods(goodsId),
nums int check (nums>0)
)
sql语句的表的连接
最新推荐文章于 2024-02-20 11:45:23 发布