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 表名 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…
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…
sql server在执行查询语句时会锁表.在锁表期间禁止增删改操作. 如果不想锁表,那就再表名或别名后面加上WITH(NOLOCK) 如下所示:…
一.查询数据库(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…
大家都知数据库表中的列可以自增长,但是有时候我们需要插入数据的时候会指定这一列的数据. 这时候我们可以很简单的利用sql语句来执行新增一条的数据,如下: set IDENTITY_INSER 表名 on insert into 表名(列1,列2,...)values (值1,值2,...); 当然咯,不能忘记还原这一列的自增长啊 Set IDENTITY_INSERT 表名 OFF 我们大家都只知道,批量插入语句有一条比较简单的SQL insert into 表1 select 列1,列2,..…
DECLARE @what varchar(800) SET @what='lll' --要搜索的字符串 DECLARE @sql varchar(8000) DECLARE TableCursor CURSOR LOCAL FOR SELECT sql='IF EXISTS ( SELECT 1 FROM ['+o.name+'] WHERE ['+c.name+'] LIKE ''%'+@what+'%'' ) PRINT ''所在的表及字段:['+o.name+'].['+c.name+'…
a) 插入新表 select * into newtable from table b) 插入已经存在的表 insert into table select * from table2 where...…
delete from TABLEA A where A.FIELD1=10        (ORACLE适用)delete TABLEA from TABLEA A where A.FIELD1=10 (SQLSERVER适用)delete  from TABLEA where TABLEA.FIELD1=10    (Ora/SQL均适用)…
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…