Rowcounts in PS tables

Your rating: None Average: 1 (1 vote)

Here is the SQL that you can use to fetch the number of rows in the PS tables in MS SQL Server database.

SET NOCOUNT ON
DECLARE @tablename VARCHAR (128)
-- Declare cursor
DECLARE TABLES CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = 'dbo'
AND TABLE_NAME LIKE 'PS_%'
-- Create the table
CREATE TABLE #tables (
tablet CHAR (255),
RecordCount INT)
-- Open the cursor
OPEN TABLES
-- Loop through all the tables in the database
FETCH NEXT
FROM TABLES
INTO @tablename

WHILE @@FETCH_STATUS = 0
BEGIN
-- Do the showcontig of all indexes of the table
INSERT INTO #tables
exec('SELECT '+''''+ @tablename + ''''+ ', COUNT(*) FROM '+ @tablename)

FETCH NEXT
FROM TABLES
INTO @tablename
END

-- Close and deallocate the cursor
CLOSE TABLES
DEALLOCATE TABLES

SELECT * FROM #tables order by 2 desc

Please try to help out with unanswered topics on the forum. Chances are you have had the same issue/question some time in your IT career!

Comments

Have a question? Please ask it on the forum instead.
mirhuma's picture
User offline. Last seen 10 years 9 weeks ago. Offline
Joined: 04/09/2008
Posts: 2
Regarding workflow

Can we start a discussion on workflow....

CompShack's picture
User offline. Last seen 3 years 38 weeks ago. Offline
Joined: 12/09/2007
Posts: 167
Take a look at this

There is a thread on the forum about new topics and workflow is one of them - take a look here

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog

Guest's picture
Guest (not verified)
Re: Rowcounts in PS tables

Hey,

No sweat man....i think there is a delivered app engine for this....its upgcount..check it out..

Post new comment

CAPTCHA
The question below is to prevent automated spam submissions.
6 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.