Last active
December 26, 2015 18:09
-
-
Save okazbb/7191794 to your computer and use it in GitHub Desktop.
全テーブルの件数表示 for SQLServer7.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @TABLE_NAME NVARCHAR(100) | |
DECLARE @SQL NVARCHAR(100) | |
DECLARE @ROW_COUNT int | |
CREATE TABLE #T_RESULT( | |
TABLE_NAME NVARCHAR(100), | |
ROW_COUNT int | |
) | |
DECLARE C_TABLES CURSOR FOR | |
SELECT name | |
FROM sysobjects | |
WHERE (type = 'U') | |
OPEN C_TABLES | |
FETCH NEXT FROM C_TABLES INTO @TABLE_NAME | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
SET @SQL = N'SELECT @ROW_COUNT = COUNT(*) FROM ' + @TABLE_NAME | |
EXEC SP_EXECUTESQL @SQL, N'@ROW_COUNT int OUTPUT', @ROW_COUNT OUTPUT | |
INSERT INTO #T_RESULT VALUES (@TABLE_NAME, @ROW_COUNT) | |
FETCH NEXT FROM C_TABLES INTO @TABLE_NAME | |
END | |
CLOSE C_TABLES | |
DEALLOCATE C_TABLES | |
SELECT * FROM #T_RESULT ORDER BY TABLE_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment