惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Help Net Security
B
Blog RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
Netflix TechBlog - Medium
S
SegmentFault 最新的问题
The Cloudflare Blog
I
InfoQ
美团技术团队
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 司徒正美
L
LangChain Blog
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog

博客园 - 我想去长安

玩玩 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 用户中心 - 博客园 javascript guid(uuid) 用户中心 - 博客园 SQL Server 2012 管理新特性:AlwaysOn【转】 用户中心 - 博客园 SevenArmsSeries.Repositories 用户中心 - 博客园
SQL Server 查询表的记录数(3种方法,推荐第一种)
我想去长安 · 2013-08-02 · via 博客园 - 我想去长安
http://blog.csdn.net/smahorse/article/details/8156483

--SQL Server 查询表的记录数 --one: 使用系统表. SELECT object_name (i.id) TableName, rows as RowCnt FROM sysindexes i INNER JOIN sysObjects o ON (o.id = i.id AND o.xType = 'U ') WHERE indid < 2 ORDER BY TableName --****************** --two: 使用未公开的过程 "sp_MSforeachtable " CREATE TABLE #temp (TableName VARCHAR (255), RowCnt INT) EXEC sp_MSforeachtable 'INSERT INTO #temp SELECT ''?'', COUNT(*) FROM ?' SELECT TableName, RowCnt FROM #temp ORDER BY TableName DROP TABLE #temp --****************** -- three: 使用游标.cursor SET NOCOUNT ON DECLARE @tableName VARCHAR (255), @sql VARCHAR (300) CREATE TABLE #temp (TableName VARCHAR (255), rowCnt INT) DECLARE myCursor CURSOR FAST_FORWARD READ_ONLY FOR SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'base table ' OPEN myCursor FETCH NEXT FROM myCursor INTO @tableName WHILE @@FETCH_STATUS = 0 BEGIN EXEC ( 'INSERT INTO #temp (TableName, rowCnt) SELECT ''' + @tableName + ''' as tableName, count(*) as rowCnt from ' + @tableName) FETCH NEXT FROM myCursor INTO @tableName END SELECT TableName, RowCnt FROM #temp ORDER BY TableName CLOSE myCursor DEALLOCATE myCursor DROP TABLE #temp