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

来源:互联网 发布:离线下载软件 知乎 编辑:程序博客网 时间:2024/06/06 13:07
-- 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
0 0