首先,列出服务器上所有数据库。
-- 获取数据库列表
SELECT name FROM master.dbo.sysdatabases ORDER BY name
SELECT name FROM master.dbo.sysdatabases ORDER BY name
其次,这是一种让所有的用户从数据库中创建存储过程。
-- 获取存储过程列表
-- Type = 'P' --> 存储过程
-- Category = 0 --> 用户创建的
SELECT * FROM sysobjects WHERE type = ' P ' AND category = 0 ORDER BY name
-- Type = 'P' --> 存储过程
-- Category = 0 --> 用户创建的
SELECT * FROM sysobjects WHERE type = ' P ' AND category = 0 ORDER BY name
然后我们就可以检索查询与存储过程内容如下:
-- 获取存储过程内容
-- Name = Stored Procedure Name.
SELECT text
FROM syscomments
WHERE id = ( SELECT id FROM sysobjects WHERE name = ' 存储过程名称 ')
-- Name = Stored Procedure Name.
SELECT text
FROM syscomments
WHERE id = ( SELECT id FROM sysobjects WHERE name = ' 存储过程名称 ')