实验八14124016.docx

上传人:b****4 文档编号:4324934 上传时间:2023-05-07 格式:DOCX 页数:16 大小:590.70KB
下载 相关 举报
实验八14124016.docx_第1页
第1页 / 共16页
实验八14124016.docx_第2页
第2页 / 共16页
实验八14124016.docx_第3页
第3页 / 共16页
实验八14124016.docx_第4页
第4页 / 共16页
实验八14124016.docx_第5页
第5页 / 共16页
实验八14124016.docx_第6页
第6页 / 共16页
实验八14124016.docx_第7页
第7页 / 共16页
实验八14124016.docx_第8页
第8页 / 共16页
实验八14124016.docx_第9页
第9页 / 共16页
实验八14124016.docx_第10页
第10页 / 共16页
实验八14124016.docx_第11页
第11页 / 共16页
实验八14124016.docx_第12页
第12页 / 共16页
实验八14124016.docx_第13页
第13页 / 共16页
实验八14124016.docx_第14页
第14页 / 共16页
实验八14124016.docx_第15页
第15页 / 共16页
实验八14124016.docx_第16页
第16页 / 共16页
亲,该文档总共16页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

实验八14124016.docx

《实验八14124016.docx》由会员分享,可在线阅读,更多相关《实验八14124016.docx(16页珍藏版)》请在冰点文库上搜索。

实验八14124016.docx

实验八14124016

一、系统存储过程

1.查看数据库的版本(select@@version)

方法一:

方法二:

方法三:

2.查看数据库启动的参数(sp_configure)

3.查看所有数据库名称及大小(sp_helpdb)

 

重命名数据库用的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

asselect*

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*******

asselect*

froms

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'p1','p1'

execp_qty'p1','p3'

execp_qty'p3','p1'

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'三建'

execproc_J_14124016'二船厂'

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2