BEGIN TRAN BEGIN END DROP TABLE IF EXISTS tempdb..#t CREATE TABLE #t ( spid int, dbid int, ObjId int, IndId int, Type ), Resource ), Mode ), Status ), CREATEDT DATETIME DEFAULT(GETDATE()) ) BEGIN INSERT INTO #t ( spid,dbid,ObjId,IndId,Type,Resource,M…
sql server在执行查询语句时会锁表.在锁表期间禁止增删改操作. 如果不想锁表,那就再表名或别名后面加上WITH(NOLOCK) 如下所示:…
SELECT 表名 then d.name else '' end, 表说明 then isnull(f.value,'') else '' end, 字段序号=a.colorder, 字段名=a.name, 标识 then '√'else '' end, 主键 FROM sysobjects where xtype='PK' and name in ( SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexk…
一.查询数据库(sys.databases —— select *from sys.databases where name='<数据库名>') select *from sys.databases where name='MyDatabase' 二.查询表(sysobjects —— select *from sysobjects where id=OBJECT_ID('<表名>')) select *from sysobjects where id=OBJECT_ID('Stu…
a) 插入新表 select * into newtable from table b) 插入已经存在的表 insert into table select * from table2 where...…
;with cte as ( select * from Associator where No = 'mc1007' union all select air.* from Associator as air inner join cte on air.ParentNo = cte.No ) select * from cte;…
select object_name(id) tablename, 8*reserved/1024 reserved, rtrim(8*dpages)+'kb' used, 8*(reserved-dpages)/1024 unused, 8*dpages/1024-rows/1024*minlen/1024 free, rows --,* from sysindexes where indid=1 order by tablename,reserved desc…
select name from sysobjects where xtype='u' order by name…
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 obj.name tablename, CAST ( CASE WHEN (SELECT COUNT() FROM sys.indexes WHERE object_id= obj.OBJECT_ID AND is_primary_key=) >= THEN ELSE END AS BIT) HasPrimaryKey from 数据库名.sys.objects obj where type='U' or type='V' order by obj.name…