数据库应用实验_第1页
数据库应用实验_第2页
数据库应用实验_第3页
数据库应用实验_第4页
数据库应用实验_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

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

文档简介

1、.数据库应用实验报告(总四次)目录实验一3第二章 T-SQL语言基础31 实验目的32 实验内容和步骤33 实验小结4第三章 数据库及其管理41 实验目的42 实验内容和步骤43 实验小结5实验二5第四章 数据表与表数据51 实验目的52 实验内容和步骤6第五章 数据查询71 实验目的72 实验内容和步骤73 实验小结9实验三10第六章 试图及其应用101 实验目的102 实验内容103 实验小结11第七章 索引及其应用111 实验目的112 实验内容11实验四12第八章 存储过程与触发器121 实验目的122 实验内容123 实验小结14第九章 事务与游标141 实验目的142 实验内容14

2、3 实验小结15实验一第二章 T-SQL语言基础1 实验目的1)学会定义数据类型,声明局部变量的方法;2) 学会批处理和流程控制语句的使用方法。2 实验内容和步骤(1)使用系统存储过程,用户自定义数据类型自定义一个地址(address)数据类型。EXEC sp_addtype address, varchar(80), not null创建两个自定义类型stud_name 和 postalcode.Use studentGo Exec sp_addtype stud_name , varchar(8) , nullExec sp_addtype postalcode , char(6) , n

3、ot null Go (2)使用DECLARE语句声明局部变量,并使用SELECT或SER语句给变量赋值定义一个整型局部变量和一个可变长字符型局部变量并赋值。(略)(3)使用流程控制语句编写程序编写计算n!(20)的T-SQL语句,并显示计算结果。输出字符串“School”中每一个字符的ASCII值和字符。设置在五分钟后进行一次查询操作。使用CASE语句,输出教师基本信息表(teacher_info)中的所有教师所在的年龄段(每6年划分一个段),并说明对应教师的职称。use studentgoselect tech_title 职称, areaofage=(case when age18 an

4、d age24 and age30 and age36 and age42 and age0)begin raiserror(you can not delete the teacher_info with the order record. the transaction will be cancelled,10,1) rollback transactionend执行:delete from teacher_info where teacher_id=010101独立实践:编写一个触发器,在对student数据库中的数据表stud_info执行插入、更新和删除三种操作后作出相应提示。use

5、 studentgocreate trigger teacher_tri3on stud_infofor insert,update,deleteasif(select count(*) from inserted inner join deleted on inserted.stud_id=deleted.stud_id)0) printupdate successfullyif(select count(*) from deleted)0) printdelete successfullyif(select count(*)from inserted)0) printinsert succ

6、essfully3 实验小结本次试验我理解了存储过程和触发器的作用,并熟悉了使用对象资源管理器和SQL编辑器创建存储过程和使用对象资源管理器和SQL编辑器创建触发器,与此同时,我还练习了存储过程和触发器的管理方法。第九章 事务与游标1 实验目的1) 了解SQL Server 程序设计的方法。2) 学会批处理、流程控制、事务处理、锁、游标的使用方法。2 实验内容(1) 事务处理运用事务处理将student数据库中课程信息表lesson_info中的多媒体技术课程编号course_id由0401010106修改为0401010116.use studentgobegin transaction s

7、tudent_tranupdate lesson_info set course_id=0401010116where course_id=0401010106save tran stud_savepointupdate teach_schedule set course_id=0401010116where course_id=0401010106update stud_grade set course_id=0401010116where course_id=0401010106update teacher_info set course_id=0401010116where course

8、_id=0401010106if(ERROR=1) rollback tran stud_savepointelsecommit tran student_tran(2) 油表的使用1) 定义一个游标stud_cursor,逐行读取stud_info表中的数据(略)2) 定义一个游标stud_cursor,删除stud_info中第一行数据(略)3) 定义一个游标stud_cursor,更新表stud_info中的数据use studentgoselect *from stud_infogodeclare stud_cursor cursor for select * from stud_in

9、foopen stud_cursorfetch next from stud_cursorupdate stud_info set mark=567where CURRENT of stud_cursorclose stud_cursordeallocate stud_cursorgoselect * from stud_info独立实践:定义一个游标stud_sursor,在student数据库中使用使用游标逐行查询stud_info表输出所有的电话号码,最后删除stud_info表中最后一行数据。use studentgodeclare stud_name nvarchar(4),tel_

10、code char(12)declare stud_cursor cursor for select name, telcode from stud_infoopen stud_cursorfetch next from stud_cursor into stud_name,tel_codewhile(FETCH_STATUS=0) begin select stud_name 姓名,tel_code 电话 fetch next from stud_cursor into stud_name,tel_code enddelete from stud_info where name=stud_name and telcode=tel_codeclose st

温馨提示

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

评论

0/150

提交评论