sys.syscomments:包含数据库中每个视图、规则、默认值、触发器、CHECK 约束、DEFAULT 约束和存储过程的项。text 列包含原始的 SQL 定义语句。(简单点说,这个系统表存储了我们创建的存储过程、视图等的源码,通过查询该系统表可以查看创建的存储过程等源码。SQL Server2000引入)
sys.sql_modules:对每个 SQL 语言定义的模块对象都返回一行。类型为 P、RF、V、TR、FN、IF、TF 和 R 的对象均有关联的 SQL 模块。在此视图中,独立的默认值,即 D 类型的对象也具有 SQL 模块定义。(SQL Server 2005引入)
select b.[ name ],a.[text]
from syscomments A
inner join sysobjects B on A.ID = B.ID
where b.xtype = 'P'
--导出所有表中自定义方法
select b . [name] , a . [text]
from syscomments A
inner join sysobjects B on A . ID = B . ID
where b . xtype = 'FN'
![031135437628499.png](https://i-blog.csdnimg.cn/blog_migrate/8b5556a8c46e25bf5f647115410ae344.png)
后续版本的 Microsoft SQL Server 将删除该功能。请不要在新的开发工作中使用该功能,并尽快修改当前还在使用该功能的应用程序。 我们建议您改用 sys.sql_modules。 有关详细信息,请参阅 sys.sql_modules (Transact-SQL)。
/www.w3.org/1999/xhtml:sentencetext xmlns="http://www.w3.org/1999/xhtml">//www.w3.org/1999/xhtml:sentencetext>
/www.w3.org/1999/xhtml:sentencetext xmlns="http://www.w3.org/1999/xhtml">使用sys.sql_modules来导出所有自定义函数,存储过程//www.w3.org/1999/xhtml:sentencetext>
/www.w3.org/1999/xhtml:sentencetext xmlns="http://www.w3.org/1999/xhtml">
SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS object_name, o.type, o.type_desc, sm.definition
FROM sys.sql_modules AS sm
JOIN sys.objects AS o ON sm.object_id = o.object_id
ORDER BY o.type;
GO
//www.w3.org/1999/xhtml:sentencetext>
/www.w3.org/1999/xhtml:sentencetext xmlns="http://www.w3.org/1999/xhtml">//www.w3.org/1999/xhtml:sentencetext>
系统视图(sys.syscomments): http://msdn.microsoft.com/zh-cn/library/ms186293.aspx
系统视图(sys.sql_modules):http://msdn.microsoft.com/zh-cn/library/ms175081.aspx