您的位置:首页 > 数据库

Day 8(11.15):存储过程(3)--扩展存储过程

2015-11-15 16:49 274 查看
-- 3 ****************************************************

-- 扩展存储过程

-- 是 DLL 内的函数,用于增加 SQL Server 的功能,访问数据库外部例程,只能存在于 master 库中

-- 3.1 --------------------------------------------------

-- xp_logevent 在事件查看器中记录用户自定义信息

/*

xp_logevent {error_number, 'message'} [, 'severity']

error_number

    是用户定义的大于 50,000 的错误号。最大值为 1073741823 (230 - 1)。

'message'

    是少于 8,000 个字符的字符串。

'severity'

    是以下三个字符串之一:INFORMATIONAL、WARNING 或 ERROR。severity 是可选的,其默认值为 INFORMATIONAL。

*/

exec master..xp_logevent 50001, 'xp_logevent_testing informational'

exec master..xp_logevent 50002, 'xp_logevent_testing warning','WARNING'

exec master..xp_logevent 50003, 'xp_logevent_testing error','ERROR'

-- 3.2 --------------------------------------------------

-- xp_cmdshell 执行给定的命令字符,作为操作系统命令,返回文本的输出参数

EXEC master..xp_cmdshell 'dir d:\'

EXEC master..xp_cmdshell 'md d:\DeleteMe'

EXEC master..xp_cmdshell 'echo a piece of cake >d:\DeleteMe\xp_cmdshell.txt'

EXEC master..xp_cmdshell 'net send 127.0.0.1 Windows is shuting down in 30 seconds! Please save your data.'

-- 练习 --------------------------------------------------

-- 1 使用 xp_cmdshell ,将刚才创建的 d:\DeleteMe\xp_cmdshell.txt 在原路径打包成 rar 文件,并加上密码 'TomSawyer'

-- 2 使用 xp_cmdshell ,在操作系统中生成 具有管理员权限的帐号:Tom 密码:TomSawyer
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sql server 数据库