实验八14124016Word格式.docx
《实验八14124016Word格式.docx》由会员分享,可在线阅读,更多相关《实验八14124016Word格式.docx(16页珍藏版)》请在冰点文库上搜索。
重命名数据库用的SQL(sp_renamedb'
SPJ_14124016'
'
实验八_14124016'
)
4.查看所有数据库用户登录信息(sp_helplogins)
查看所有数据库用户所属的角色信息(sp_helpsrvrolemember)
5.查看某数据库下某个数据对象的大小(sp_spaceused@objname)
还可以用sp_toptables过程看最大的N(默认为50)个表
查看某数据库下某个数据对象的索引信息(sp_helpindex@objname)
6.查看数据库里所有的存储过程和函数
use@database_name
sp_stored_procedures
查看存储过程和函数的源代码
sp_helptext'
@procedure_name'
7.查看数据库里用户和进程的信息(sp_who)
查看SQLServer数据库里的活动用户和进程的信息(sp_who'
active'
8.显示表的相关信息(sp_help)
2、自定义存储过程
1.为S表创建查询所有信息的存储过程,不带参数
createprocedures1
asselect*
froms
execs1
2.创建一个不带参数的存储过程,从P中选择所有零件重量大于20的记录,输入如下语句,单击“执行”,
createprocgetp1
fromP
whereweight>
20
execgetp1
3.创建一个带参数的存储过程,从P表中选择零件重量介于15到30之间的记录,输入如下语句,单击“执行”,
createprocgetp2
@minint,@maxint
asselect*frompwhereweightbetween@minand@max
declare
@minint,@maxint
execgetp215,30
4.创建与执行带输入、输出参数的存储过程,实现显示P表中给定零件号的信息,并输出SPJ中该零件使用的最高数量和最低数量。
createprocgetpj3
@pnovarchar(20),@maxintoutput,@minintoutput
asselect*
frompwherepno=@pno
select@max=max(qty)fromspjwherepno=@pno
select@min=min(qty)fromspjwherepno=@pno
declare
@x1int,@x2int
execgetpj3'
'
@x1output,@x2output
select@x1as最高数量,@x2as最低数量
5.创建一个存储过程proc_(本人学号),查询S表中所有所在城市为北京的供应商的相关信息。
createprocs1*******
wherecity='
北京'
execs1*******
6.创建一个名为P_QTY_(本人学号)的存储过程,可查询出某段零件号在spj表中的总数量(零件号起始号与终止号在调用时输入,可设默认值)。
createprocp_qty_14124016
@pminchar
(2)='
p1'
@pmaxchar
(2)='
p6'
as
selectsum(qty)as零件总数量
fromspj
wherepnobetween@pminand@pmax
execp_qty
execp_qty'
'
p3'
7创建一个存储过程proc_J_(本人学号),能够根据工程名查询供应商名。
(当工程名不存在时给出提示信息)
createprocproc_J_14124016
@jnamechar(10),@jnochar(4)=null
as
select@jno=jnofromjwherejname=@jname
if@jnoisnotnull
selectdistinctsname供应商名
fromspj,s,j
wherespj.sno=s.snoandspj.jno=j.jnoandj.jname=@jname
elseprint'
Error:
该工程不存在'
execproc_J_14124016'
三建'
二船厂'