//////////////////查询指定表外键约束select a.name as 约束名, object_name(b.parent_object_id) as 外键表, d.name as 外键列, object_name(b.referenced_object_id) as 主健表, c.name as 主键列 from sys.foreign_keys A inner join sys.foreign_key_columns B on A.object_id=b.constraint
--SQL查询每个表的字段数量select b.[name], count(*) As AllCount,ISNULL(ISNULL(sum(case when isnullable=0 then 1 end),null),null) as NotNullCountfrom syscolumns aINNER JOIN( select [id], [name] from [sysobjects] where [type] = 'u' ) AS b ON a.id = b.[id] GROUP b
1.查询某个表被哪些存储过程(以下简称 SP)使用到 : select distinct object_name(id) from syscomments where id in (select object_id from sys.objects where type ='P') and text like'%TableName%' 2.查找那些过程对该表做了更新操作: select distinct object_name(id) from syscomments where id in (
-- 获得存储过程创建语句 select o.xtype,o.name,cm.text from syscomments cm inner join sysobjects o on o.id=cm.id where xtype ='p' order by o.xtype,o.name,cm.text -- 获得视图程创建语句 select o.xtype,o.name,cm.text from syscomments cm inner join sysobjects o on o.id=cm.i
◆Oracle查询用户表空间:select * from user_all_tables ◆Oracle查询所有函数和储存过程:select * from user_source ◆Oracle查询所有用户:select * from all_users.select * from dba_users ◆Oracle查看当前用户连接:select * from v$Session ◆Oracle查看当前用户权限:select * from session_privs ◆Oracle查看用户表空间
SQL语句查询某表的所有字段及数据类型 SELECT name AS column_name , TYPE_NAME(system_type_id) AS column_type , max_length , is_nullable FROM sys.columns WHERE object_id = OBJECT_ID(N'customerbase') --customerbase 为表名
-- 获得存储过程创建语句 select o.xtype,o.name,cm.text from syscomments cm inner join sysobjects o on o.id=cm.id where xtype ='p' order by o.xtype,o.name,cm.text -- 获得视图程创建语句 select o.xtype,o.name,cm.text from syscomments cm inner join sysobjects o on o.id=cm.i
例1:查询某个文章及其对应的评论(单个详情) ) FROM A; 例2:查询分类表中,每种分类各包含多少商品(汇总) SELECT category_id, (SELECT count(goods_id) FROM Goods WHERE category_id = A.category_id) FROM category; 部分参考:http://zhidao.baidu.com/link?url=FAZU7UHkC-qZXm4rPm5SNzHtVPf_YzINFsM-sNIeVSXungAt
--1.查询某个表被哪些存储过程使用到 : select distinct object_name(id) from syscomments where id in (select object_id from sys.objects where type ='P') and text like'%TableName%' --2.查找那些过程对该表做了更新操作: select distinct object_name(id) from syscomments where id in(select
查询指定表结构的表名.列名.类型.说明.字段长度 select o.name as tableName,c.name as columnName,t.name as columnType,p.value as columnDescription,c.prec from sysobjects o left join syscolumns c on o.id=c.idleft join sys.extended_properties p on p.major_id=c.id and p.mino