Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

A script - row number

Participant ,
Mar 18, 2009 Mar 18, 2009
I need a cf script that finds out the total row count of a sql database...Any idea?
The reason I need is to compare our current db (on SQL05) with the new one that will be attached to the SQL 05....
332
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 18, 2009 Mar 18, 2009
I don't know about a CF script, but a pretty damn simple SQL script is:

SELECT count(*)
FROM aTable
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 18, 2009 Mar 18, 2009
LATEST
I have found a stored procedure that does what I need... thank you all
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER PROCEDURE [dbo].[listTableRowCounts]
AS
BEGIN
SET NOCOUNT ON

DECLARE @SQL VARCHAR(255)
SET @SQL = 'DBCC UPDATEUSAGE (' + DB_NAME() + ')'
EXEC(@SQL)

CREATE TABLE #foo
(
tablename VARCHAR(255),
rc INT
)

INSERT #foo
EXEC sp_msForEachTable
'SELECT PARSENAME(''?'', 1),
COUNT(*) FROM ?'

SELECT tablename, rc
FROM #foo
ORDER BY tablename,rc ASC

DROP TABLE #foo
END
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources