经常用的命令
exec sp_help --查看数据库中对象存储过程/函数,表等信息(不是create语句)
exec sp_helptext --显示存储过程,函数,触发器,计算列,check约束视图系统对象的create语句(没有表的)
dbcc help('?') --显示所有dbcc命令,并查找特定命令用法
select OBJECT_DEFINITION(OBJECT_ID('dbo.v_t1')) --与sp_helptext意思差不多,同样不能查看表的定义
select * from sys.sql_modules --同样可以查看存储过程,函数,触发器,视图的定义
查看存储过程依赖对象
USE db_name;
SELECT DISTINCT OBJECT_NAME(object_id), OBJECT_NAME(referenced_major_id)
FROM sys.sql_dependencies
WHERE object_id = object_id('xxx')
查看与外键相关的表和列信息
use db_name
select object_name(constraint_object_id) fk_name,
object_name(fk.parent_object_id) parent_name,
c.name p_column_name,
object_name(fk.parent_object_id)+'('+c.name+')' p_info,
object_name(fk.referenced_object_id) ref_tab_name,
c1.name,
object_name(fk.referenced_object_id)+'('+c1.name+')' ref_info
from sys.foreign_key_columns fk
left join sys.all_columns c
on fk.parent_object_id=c.object_id and fk.parent_column_id=c.column_id
left join sys.all_columns c1 on fk.referenced_object_id=c1.object_id
and fk.referenced_column_id=c1.column_id