作者:快乐宝宝的哭泣_826 | 来源:互联网 | 2023-05-19 18:14
xtype:对象类型。可以是下列对象类型中的一种:
C = CHECK 约束
D = 默认值或 DEFAULT 约束
F = FOREIGN KEY 约束
L = 日志
FN = 标量函数
IF = 内嵌表函数
P = 存储过程
PK = PRIMARY KEY 约束(类型是 K)
RF = 复制筛选存储过程
S = 系统表
TF = 表函数
TR = 触发器
U = 用户表
UQ = UNIQUE 约束(类型是 K)
V = 视图
X = 扩展存储过程
1.用SQL语句查找包含有某个关键字的存储过程、触发器、函数等
SELECT NAME FROM sysobjects AS s
INNER JOIN syscomments AS s2 ON s2.id = s.id
WHERE TEXT LIKE '%关键字%' and s.xtype = 'P'
--查询存储过程与函数
SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%关键字%'
AND ROUTINE_TYPE='PROCEDURE'
--查询存储过程与函数的参数
select * from INFORMATION_SCHEMA.PARAMETERS
--查询数据库的表与视图
select * from INFORMATION_SCHEMA.TABLES
2.查询外键关系
SELECT PT.name 引用表名,PC.name 引用列名,RT.name 被引用表名,RC.name 被引用列名
FROM sys.foreign_key_columns JOIN sys.objects PT ON sys.foreign_key_columns.parent_object_id=PT.object_id
JOIN sys.objects RT ON sys.foreign_key_columns.referenced_object_id=RT.object_id
JOIN sys.columns PC ON sys.foreign_key_columns.parent_object_id=PC.object_id AND sys.foreign_key_columns.parent_column_id=PC.column_id
JOIN sys.columns RC ON sys.foreign_key_columns.referenced_object_id=RC.object_id AND sys.foreign_key_columns.referenced_column_id=RC.column_id
where RT.name='Biz_Audit_MaterialBill'