SELECT * FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='Account' SELECT (case when a.colorder=1 then d.name else '' end) as 表名,--如果表名相同就返回空 a.colorder as 字段序号, a.name as 字段名, (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity'
我们有时候会需要查询数据库中包含某字段的所有的表,去进行update,这时就可以用下面的SQL来实现: select object_name(id) objName,Name as colName from syscolumns where (name like'%此次写需要查询的字段名称%')and id in(select id from sysobjects where xtype='u')order by objname; 当然也可以使用游标,把查询出来的Table串接起来,如下: DE
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='subject' --表名 1.利用sysobjects系统表 在这个表中,在数据库中创建的每个对象(例如约束.默认值.日志.规则以及存储过程)都有对应一行,我们在该表中筛选出xtype等于U的所有记录,就为数据库中的表了. 示例语句如下: select * from sysobjects where xtype='U' 注意:在SQL SERVER2005中,出现了sys.ob
一.查询SQL Server中所有的表 SQL语句:SELECT * FROM sys.tables name列表示所有的表名. 二.查询SQL Server中所有的列 SQL语句:SELECT * FROM sys.columns name列表示所有的字段名称. 两张表根据object_id进行关联. 语法: select * from sys.tables t inner join sys.columns c on t.object_id=c.object and c.name='要查询的字
查询数据库空间分配情况: use master go create procedure dbo.proc_getdbspaceused as begin set nocount on create table #dbsize( database_id int ,database_name ) ,size_kb bigint ,space_available_kb bigint ,reserved_kb bigint ,data_kb bigint ,index_kb bigint ,unused
在一次测试过程中,发现有些表一直被锁定,从网上搜集了下资料,可以使用一下语句查看数据库中那些表正被锁定: select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName from sys.dm_tran_locks where resource_type='OBJECT'
SELECT TOP 1000 ST.text AS '执行的SQL语句', QS.execution_count AS '执行次数', QS.total_elapsed_time AS '耗时', QS.total_logical_reads AS '逻辑读取次数', QS.total_logical_writes AS '逻辑写入次数', QS.total_physical_reads AS '物理读取次数',
SELECT a.name, b.rows FROM sysobjects AS a INNER JOIN sysindexes AS b ON a.id = b.id WHERE (a.type = 'u') AND (b.indid IN (0, 1)) ORDER BY a.name,b.rows DESC
方法一: SELECT a.name,b.rows FROM sysobjects a INNER JOIN sysindexes b ON a.id=b.id ,) AND a.Type='u' ORDER BY b.rows desc 方法二: ), RowCnt INT) EXEC sp_MSforeachtable 'INSERT INTO #temp SELECT ''?'', COUNT(*) FROM ?' select * from #temp order by RowCnt d
SELECT B.NAME,A.ROW_COUNT FROM SYS.DM_DB_PARTITION_STATS A,SYS.OBJECTS BWHERE A.OBJECT_ID=B.OBJECT_ID AND A.INDEX_ID<=1AND B.TYPE='U'AND A.ROW_COUNT>8000 ORDER BY ROW_COUNT DESC