Home > Database > Mysql Tutorial > SqlServer查询数据库所有用户表的记录数

SqlServer查询数据库所有用户表的记录数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:52:11
Original
1644 people have browsed it

--创建临时表 create table #temp(Recordcount int ,tableName varchar(30)) --用游标将查询的记录数,插入临时表 declare @tablename varchar(30) declare @sql varchar(100) declare @str varchar(30) declare tablecursor cursor for select name from sy

--创建临时表

 

create table #temp(Recordcount int ,tableName varchar(30))

 

--用游标将查询的记录数,插入临时表


declare @tablename varchar(30)
declare @sql varchar(100)
declare @str varchar(30)
declare tablecursor cursor for
select name from sysobjects where xtype='u'
open tablecursor
fetch next from tablecursor into @tablename
while @@fetch_status=0
begin
set @str=@tablename
set @sql='insert into #temp(recordcount,tablename) select count(*),'+''''+@tablename+''''+' from 
'+@tablename
exec(@sql)
fetch next from tablecursor into @tablename
end
close tablecursor
deallocate tablecursor

 

--查询临时表,即可看见一个数据库的每个表的记录数

 

select * from #temp

 

 

--最后删除临时表


drop table #temp

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Problem with tp6 connecting to sqlserver database
From 1970-01-01 08:00:00
0
0
0
Unable to connect to SQL Server in Laravel
From 1970-01-01 08:00:00
0
0
0
Methods of parsing MYD, MYI, and FRM files
From 1970-01-01 08:00:00
0
0
0
SQLSTATE: User login failed
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template