




已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
数据库应用数据库应用 实验报告 总四次 实验报告 总四次 目录目录 实验一 3 第二章 T SQL 语言基础 3 1 实验目的 3 2 实验内容和步骤 3 3 实验小结 4 第三章 数据库及其管理 4 1 实验目的 4 2 实验内容和步骤 4 3 实验小结 5 实验二 5 第四章 数据表与表数据 5 1 实验目的 5 2 实验内容和步骤 6 第五章 数据查询 7 1 实验目的 7 2 实验内容和步骤 7 3 实验小结 9 实验三 10 第六章 试图及其应用 10 1 实验目的 10 2 实验内容 10 3 实验小结 11 第七章 索引及其应用 11 1 实验目的 11 2 实验内容 11 实验四 12 第八章 存储过程与触发器 12 1 实验目的 12 2 实验内容 12 3 实验小结 14 第九章 事务与游标 14 1 实验目的 14 2 实验内容 14 3 实验小结 15 实验一实验一 第二章第二章 T SQL 语言基础语言基础 1 实验目的实验目的 1 学会定义数据类型 声明局部变量的方法 2 学会批处理和流程控制语句的使用方法 2 实验内容和步骤实验内容和步骤 1 使用系统存储过程 用户自定义数据类型 自定义一个地址 address 数据类型 EXEC sp addtype address varchar 80 not null 创建两个自定义类型 stud name 和 postalcode Use student Go Exec sp addtype stud name varchar 8 null Exec sp addtype postalcode char 6 not null Go 2 使用 DECLARE 语句声明局部变量 并使用 SELECT 或 SER 语句给变量赋值 定义一个整型局部变量和一个可变长字符型局部变量并赋值 略 3 使用流程控制语句编写程序 编写计算 n 20 的 T SQL 语句 并显示计算结果 输出字符串 School 中每一个字符的 ASCII 值和字符 设置在五分钟后进行一次查询操作 使用 CASE 语句 输出教师基本信息表 teacher info 中的所有教师所在的年龄段 每 6 年划分一个段 并说明对应教师的职称 use student go select tech title 职称 areaofage case when age 18 and 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 transaction end 执行 delete from teacher info where teacher id 010101 独立实践 编写一个触发器 在对 student 数据库中的数据表 stud info 执行插入 更新 和删除三种操作后作出相应提示 use student go create trigger teacher tri3 on stud info for insert update delete as if select count from inserted inner join deleted on inserted stud id deleted stud id 0 print update successfully if select count from deleted 0 print delete successfully if select count from inserted 0 print insert successfully 3 实验小结实验小结 本次试验我理解了存储过程和触发器的作用 并熟悉了使用对象资源管理器和 SQL 编辑器创建 存储过程和使用对象资源管理器和 SQL 编辑器创建触发器 与此同时 我还练习了存储过程和 触发器的管理方法 第九章第九章 事务与游标事务与游标 1 实验目的实验目的 1 了解 SQL Server 程序设计的方法 2 学会批处理 流程控制 事务处理 锁 游标的使用方法 2 实验内容实验内容 1 事务处理 运用事务处理将 student 数据库中课程信息表 lesson info 中的多媒体技术课程编号 course id 由 0401010106 修改为 0401010116 use student go begin transaction student tran update lesson info set course id 0401010116 where course id 0401010106 save tran stud savepoint update teach schedule set course id 0401010116 where course id 0401010106 update stud grade set course id 0401010116 where course id 0401010106 update teacher info set course id 0401010116 where course id 0401010106 if ERROR 1 rollback tran stud savepoint else commit tran student tran 2 油表的使用 1 定义一个游标 stud cursor 逐行读取 stud info 表中的数据 略 2 定义一个游标 stud cursor 删除 stud info 中第一行数据 略 3 定义一个游标 stud cursor 更新表 stud info 中的数据 use student go select from stud info go declare stud cursor cursor for select from stud info open stud cursor fetch next from stud cursor update stud info set mark 567 where CURRENT of stud cursor close stud cursor deallocate stud cursor go select from stud info 独立实践 定义一个游标 stud sursor 在 student 数据库中使用使用游标逐行查询 stud info 表输出所有的电话号码 最后删除 stud info 表中最后一行数据 use student go declare stud name nvarchar 4 tel code char 12 declare stud cursor cursor for select name telcode from stud info open stud cursor fetch next from stud cursor into stud name tel code while FETCH STATUS 0 begin select stud name 姓名 tel code 电话 fetch next from stud cursor into stud name tel code end delete from stud info where name stud name and telcode tel code close
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论