资源描述:
《数据库应用技术实验报告》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、数据库应用技术实验一一、实验目的及要求1、学会定义数据类型、声明局部变量的方法;2、学会批处理和流程控制语句的使用方法;3、了解系统数据库的作用;4、学会用对象资源管理器中创建用户数据库;5、学会SQL编辑器创建用户数据库;6、学会压缩和扩充数据库;7、学会查看和修改数据库选项;8、学会给数据库改名和删除数据库。二、实验内容1.1使用系统存储过程,用户自定义数据类型usestudentgoexecsp_addtypeaddress,'varchar(80)','notnull'execsp_addtypestud_name,'varcha
2、r(8)','null'execsp_addtypepostalcode,'char(6)','notnull'1.2使用declare语句声明局部变量,并使用select或set语句给变量赋值declare@local_variable_intint,@local_variable_charnvarchar(9)select@local_variable_int=40set@local_variable_char='welcometochangsha'select@local_variable_intselect@local_varia
3、ble_charGO1.3、运用流程控制语句编写程序使用if语句求1到10之间累加“和”并输出结果declare@sumint,@countintselect@sum=0,@count=1label:select@sum=@sum+@countselect@count=@count+1if@count<=10gotolabelselect@sum,@count编写计算n!(n=20)的t-sql语句declare@nbigint,@countintselect@n=1,@count=20label:select@n=@count*@nse
4、lect@count=@count-1if@count>=1gotolabelselect@n,@count输出字符串“school”中每一个字符的ascii值和字符declare@positionint,@stringchar(6)set@position=1set@string='School'while@position<=datalength(@string)beginselectascii(substring(@string,@position,1))asasccode,char(ascii(substring(@string,
5、@position,1)))asasccharset@position=@position+1end设置在9:00进行一次查询操作语句:UsestudentGoBeginWaitfortime‘9:00’Select*fromstud_infoEnd2.1、使用T-SQl语句创建数据库语句:createdatabasestudentonprimary(name=student_data,filename='d:mydocstudent.mdf',size=3MB,maxsize=10MB,filegrowth=1MB)logon(na
6、me=cumt_log,filename='d:mydocstudent_ldf',size=3MB,maxsize=10MB,filegrowth=1MB)2.2、使用T-SQL语句将数据库student的初始分配空间大小扩充到40mbUsestudentGoAlterdatabasestudentModifyfile(name=student.mdf,Size=40MB)2.3、压缩空间至最小容量、usestudentgodbccshrinkdatabase('student')2.4设置只读execsp_dboption'stu
7、dent','readonly',true2.5数据库改名execsp_dboption'student','singleuser','scholastic'execsp_dboption'student','scholastic'execsp_dboption'pupil','singleuser'实验体会本次实验主要是书本第二和三章的实验内容和部分课后习题,通过这次的实验主要是对t-sql基本语法进行加深和巩固以及了解并掌楃sqlserver2005软件的一些基础操作。其中t-sql语句和我们之前学习的sql语句有很多相同的地方,因此
8、基础学习起来相对比较简单,只要在原来的基础上补充一些t-sql语句中的差异和补充就可以了。通过这次的实验对sql语言的掌握有了一定的提高,同时也对t-sql有了一个整体上的认识。这次实验中又很