sql sever 数据定义

经过几天时间终于把一学期的sql实验又写完了一遍

所以考试复习yyds

以下是数据定义实验

 

 我写的答案

可能有误,请各位大佬多多包涵,及时指出

--1创建数据库
create database SuperMarket


--2 创建Goods表
create table Goods
(GoodsNO varchar(20) primary key,
SupplierNO varchar(20), 
CategoryNO varchar(20),
GoodsName varchar(20),
Inprice  decimal(10,1),
SalePrice decimal(10,1),
Number int,
producTime date,
constraint wai_ma1 Foreign key(SupplierNO) references Supplier(SupplierNO))


--3 创建student表
create  table student
(SNO integer ,
Sname varchar(20),
Birthyear int,
Gender varchar(2),
College varchar(20),
Major varchar(20),
WeiXin varchar(20) ,
constraint SNO_zhuma primary key(SNO),
constraint Wei_Xin_weiyi unique(WeiXin))


--4 创建salebill表
create table Salebill
(
GoodsNO varchar(20),
SNO integer,
HappenTime date,
Number int,
constraint Salebill_zhuma primary key(GoodsNO,SNO)
)


--5 创建Category表
create table Category
(
CategoryNO varchar(20),
CategoryName varchar(20),
Descriptions varchar(50),
constraint Category_zhuma primary key(CategoryNO)
)


-- 6 创建supplier表
 create table Supplier
(SupplierNO varchar(20),
SupplierName varchar(20),
Address varchar(20),
Number varchar(50),
constraint Supplier_zhuma primary key(SupplierNO))


--7 在表上增加'保质期'属性列QGperiod 数据类型为整型
alter table Goods
add QGoperiod int


--8 删除删除表student的“出生年份”属性列。
alter table student
drop column Birthyear


--9 在表SaleBill上增加数量大于0的约束。
alter table SaleBill
add check (Number>0)
 
 exec sp_helpconstraint @objname=student
--10 删除表student微信号列的唯一值约束。
alter table student 
drop  constraint Wei_Xin_weiyi
 --/********************************************/
--查看未定义约束名的表
 --exec sp_helpconstraint @objname=表名
 --/*******************************************/

--11修改Goods表“进价”属性列为精确数值型,保留一位小数。
alter table Goods
alter column Inprice decimal(10,1)


--12 将表SaleBill上数量的约束修改为0~100。
--exec sp_helpconstraint @objname=SaleBill
alter table SaleBill
drop constraint CK__Salebill__Number__48CFD27E
alter table SaleBill
add check((Number>0) and (Number<=100))


--13 在表supplier表上,按供应商号属性列的唯一值方式建立索引。
create unique index Supplierno_unique 
on Supplier(SupplierNO)


--14 在Category表上,按商品类别编号属性列升序和商品名属性降序建立唯一值索引。
create unique index Category_wy_lb_asc_name_desc 
on Category(CategoryNO asc,CategoryName desc)


--15 删除supplier上的唯一值索引。
drop index  Supplierno_unique 
on Supplier

剩下实验链接如下 包涵数据定义 数据更新 数据查询 视图操作

   实验文件icon-default.png?t=M4ADhttps://download.csdn.net/download/zyx111999222/85351453

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

之学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值