- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
sql2008试验2
试验2
use master
go
--(1)创建数据库
if DB_ID(s_student)is not null
drop database s_student
create database s_student
on
(
name=s_student,
filename=e:\sqldb2005\s_student.mdf,
size=5,
maxsize=15,
filegrowth=5
)
log on
(
name=s_studentlog,
filename = e:\sqldb2005\s_student.ldf,
size=5,
maxsize=15,
filegrowth=5
)
Go
--(2)创建表s,c,sc
use s_student
go
if OBJECT_ID(S)IS NOT NULL
drop table s
if OBJECT_ID(SC)IS NOT NULL
drop table sc
if OBJECT_ID(c)IS NOT NULL
drop table c
go
create table s
(
sno char(6) primary key,
sn char(20),
sa smallint check (sa=12 and sa=50)
)
create table c
(
cno char(4) primary key,
cn char(30),
pcno char(4)
)
create table sc
(
sno char(6)not null,
cno char(4)not null,
g smallint check (g in(1,2,3,4,5)),
primary key(sno,cno),
foreign key (sno) references s(sno),
foreign key (cno) references c(cno)
)
go
alter table sc
add constraint fk_sc_cno foreign key (cno) references c(cno) --自行另外添加约束constraint
go
-- 验证用户数据表确实建立
SELECT name
FROM sys.objects
WHERE type = U;
GO
--(3)添加项删除项
alter table s
add sd char(8)
select *
from s
go
alter table c
add teacher char(8)
select *
from c
alter table C
drop column teacher
go --column列
select *
from c
--(4)创建索引
if exists (select * from dbo.sysindexes where name=s_s)
drop index s_s on s
if exists (select * from dbo.sysindexes where name=s_c)
drop index s_c on c
if exists (select * from dbo.sysindexes where name=s_sc)
drop index s_sc on sc
create unique index s_s on s(sno)
create unique index s_c on c(cno)
create unique index s_sc on sc(sno,cno)
go
--(5)约束
sp_help sc
--查看约束
select name from sys.objects where type=c
--删除约束
alter table sc drop constraint CK__sc__g__0AD2A005
select name from sys.objects where type=c
--添加约束
alter table sc add check (g between 1 and 5)
--(6)图形界面操作。
--()加入数据
insert into s
values(990104,shanwang,20,cs)
--
insert into c(cno,cn)
values(c135,math)
--
insert into sc
values (990104,c135,4)
您可能关注的文档
最近下载
- GB50209-2010建筑地面工程施工质量验收规范(新).pdf VIP
- 新苏教版六年级科学上册 第一单元《物质的变化》测试卷(A卷).docx VIP
- 2025年中国便利店发展报告.pptx VIP
- 新苏教版六年级科学上册第一单元《物质的变化》测试卷及答案.pdf VIP
- 标准图集-20S515-钢筋混凝土及砖砌排水检查井.pdf VIP
- 住院患者跌倒护理风险评估与护理指导意见.pdf VIP
- 煤矿用防爆电气设备防爆检查标准-培训课件.pptx
- 半导体物理学(第8版)刘恩科课后习题答案解析.pdf
- 新媒体背景下信息技术的发展及其应用分析.pdf VIP
- 一种大吨位玄武岩纤维锚索整体张拉试验系统及试验方法.pdf VIP
文档评论(0)