第7章 示例


--常用系统存储过程的使用
EXEC sp_databases                   --列出当前系统中的数据库
EXEC sp_renamedb  'MyBank' ,'bank'--改变数据库的名称(单用户访问)
use MySchool
go
EXEC sp_tables               --当前数据库中可查询对象的列表
EXEC sp_columns Student--查看Student表中列中的信息
EXEC sp_help student--查看Student表中的所有的信息
EXEC sp_helpconstraint student--查看Student表中的约束
EXEC sp_helptext view_Student_result--查看视图的语句文件
EXEC sp_stored_procedures  --返回当前数据库中存储过程的列表


--示例2
--Purpose :xp_cmdshell扩展存储过程的使用
use master
go
/*若xp_cmdshell作为服务器安全配置的一部分而被关闭,则请使用如下语句启用*/
EXEC sp_configure 'show advanced options',1    --显示高级配置信息
go
reconfigure   --重新配置
go
EXEC sp_configure 'xp_cmdshell',1    --打开xp_cmdshell选择
go
reconfigure   --重新配置
go
/*--创建数据库bankDB,要求保存在D:\bank目录下--*/
exec xp_cmdshell 'mkdir E:\bank',No_output    --创建文件夹D:\bankDB
--创建数据库bankDB
if exists (select *from sysdatabases where name='bankDB')
DROP database bankDB
go
create database bankDb
ON
(
name='bankDB_data',
filename='E:\bank\bankDB_data.mdf',
size=3mb,
filegowth=15%
)
log on
(
name='bankDB_log',
filename='E;\bank\bankDB-log.ldf',
size=3mb,
filegrowth=15%
)
go

exec xp_cmdshell 'dir E:\bank\'     --查看文件

select top 2 * from Student where studentNo not in(select top 2 studentNO from  student order by studentNO)order by studentNo
select *from (select *,ROW_NUMBER () over (order by studentNO)as myid from student )as temp where myid betWeen 3 and 4


 

posted @ 2016-04-06 21:49  吴玄坤  阅读(211)  评论(0编辑  收藏  举报