sql2008试验2.doc_第1页
sql2008试验2.doc_第2页
sql2008试验2.doc_第3页
sql2008试验2.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

试验2use mastergo-(1)创建数据库if DB_ID(s_student)is not nulldrop database s_studentcreate database s_studenton (name=s_student,filename=e:sqldb2005s_student.mdf,size=5,maxsize=15,filegrowth=5)log on(name=s_studentlog,filename = e:sqldb2005s_student.ldf,size=5,maxsize=15,filegrowth=5)Go-(2)创建表s,c,scuse s_studentgoif OBJECT_ID(S)IS NOT NULLdrop table sif OBJECT_ID(SC)IS NOT NULLdrop table scif OBJECT_ID(c)IS NOT NULLdrop table cgocreate 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)goalter table scadd constraint fk_sc_cno foreign key (cno) references c(cno)-自行另外添加约束constraintgo- 验证用户数据表确实建立SELECT name FROM sys.objectsWHERE type = U;GO-(3)添加项删除项alter table sadd sd char(8)select *from sgoalter table cadd teacher char(8)select *from calter table Cdrop column teachergo -column列select *from c-(4)创建索引if exists (select * from dbo.sysindexes where name=s_s)drop index s_s on sif exists (select * from dbo.sysindexes where name=s_c)drop index s_c on cif exists (select * from dbo.sysindexes where name=s_sc)drop index s_sc on sccreate 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_0AD2A005select name from sys.objects where type=c-添加约束alter table sc add check (g between 1 and 5)-(6)图形界面操作。-()加入数据insert into svalues(990104,shanwa

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论