删除
DELETE FROM table_name WHERE id < 10000;
DELETE FROM [allmedia_restore] WHERE [SYS_DOCUMENTID] < 10000;
清空表
truncate table tableA
truncate table [allmedia_restore].[dbo].[DOM_4_DOCLIB]
倒序排序
order by [字段] desc
SELECT TOP 1000 [SYS_DOCUMENTID]
,[SYS_CREATED]
FROM [allmedia_restore].[dbo].[DOM_4_DOCLIB] order by SYS_DOCUMENTID desc
--查询所有表大小,大小倒序排序
选中对应的数据库,执行
SELECT
TableName = obj.name,
TotalRows = prt.rows,
[DataSize(KB)]=SUM(alloc.data_pages)*8, --这里返回的是数据页个数,1页是8K,所以乘以8
[DataSize(MB)]=SUM(alloc.data_pages)*8/1024.0,
[DataSize(GB)]=SUM(alloc.data_pages)*8/1024.0/1024.0,
[SpaceUsed(KB)] = SUM(alloc.used_pages)*8,--这里返回的是数据页个数,1页是8K,所以乘以8
[SpaceUsed(MB)] = SUM(alloc.used_pages)*8/1024.0,
[SpaceUsed(GB)] = SUM(alloc.used_pages)*8/1024.0/1024.0
FROM sys.objects obj
JOIN sys.indexes idx ON obj.object_id = idx.object_id
JOIN sys.partitions prt ON obj.object_id = prt.object_id
JOIN sys.allocation_units alloc ON alloc.container_id = prt.partition_id
WHERE obj.type = 'U' AND idx.index_id IN (0, 1)
--AND idx.object_id=OBJECT_ID('tablename')
GROUP BY obj.name, prt.rows
ORDER BY TotalRows desc