要查找project相关的表、视图、主键、外键、存储过程、函数等
1、select * from sysobjects 查找到库中所有的表、视图、触发器、函数、存储过程、主键、外键;
2、筛选找到该主键(xtype=pk)的parent_obj编号,并通过该编号该主键所在的列名:
select a.name 表名,a.name 主键名,c.name 列名 from sys。key_constraints a
left join sys.index_column b on a.parent_object_id =b.object_id
left join sys.column c on b.object_id =c.object_id and b.culumn_id =c.column_id
left join sysobjects d on a.parent_object_id=d.id
where b.index_id=1 ----- parent_obj(父对象的对象标识号(例如,对于触发器或约束,该标识号为表 ID))
3、知道列名找表名
select * from sysobjetcs where id in
(select id from syscolumns where name =列名)
4、查找特定对象
select name from sysobjects where type=‘u’
注:
type对象类型。可以是下列值之一:
C = CHECK 约束 D = 默认值或 DEFAULT 约束
F = FOREIGN KEY 约束 FN = 标量函数
IF = 内嵌表函数 K = PRIMARY KEY 或 UNIQUE 约束
L = 日志 P = 存储过程
R = 规则 RF = 复制筛选存储过程
S = 系统表 TF = 表函数
TR = 触发器 U = 用户表
V = 视图 X = 扩展存储过程
5、查询数据库中有哪些表
select table_name from 库名.information_schema.tables where table_type=''base table'