sqlserver命令

插数据
declare @i int
set @i=1
while @i<1000000
begin
insert into jy3(a,s,d,g,h,j,k,l)
values((select @i),left(newid(),7),getdate(),left(newid(),8),left(newid(),9),1314.14,'<Person><ID>1</ID><Name>贾哥</Name></Person>','true')
set @i=@i+1
print @i
end

查询数据库大小:

SELECT name 'database_name',((size * 8) / 1024) 'size(MB)'
FROM sys.master_files where type_desc='ROWS' and name like 'test%' order by 'Size(MB)' desc
##size 当前文件大小(以 8 KB 为单位的页数)。 对于数据库快照来说,size 表示该快照可以一直用于文件的最大空间。

select sum(((size * 8) / 1024)) from sys.master_files where type_desc='ROWS' and name in('tpcc1','test12','test1','test4','test6','AdventureWorks2017')

查询行数超过100万的表名:

select a.name 'schema',b.name 'table_name', c.rows from sys.objects b
INNER JOIN sysindexes c ON b.object_id=c.id
INNER JOIN sys.schemas a ON a.schema_id=b.schema_id
where c.rows>=1000000 and b.type='U' order by c.rows desc

原文地址:https://www.cnblogs.com/jiayan666/p/14282837.html