Tuesday, June 15, 2010

Iterate on user tables in SQL server database

Iterate on user tables in SQL server database.

DECLARE @TABLE_NAME sysname

SELECT @TABLE_NAME= MIN(TABLE_NAME)

FROM INFORMATION_SCHEMA.Tables

WHERE TABLE_TYPE= 'BASE TABLE'

AND TABLE_NAME!= 'sysdiagrams'

WHILE @TABLE_NAME IS NOT NULL

BEGIN

PRINT @TABLE_NAME

SELECT @TABLE_NAME = MIN(TABLE_NAME)

FROM INFORMATION_SCHEMA.Tables

WHERE TABLE_NAME > @TABLE_NAME

AND TABLE_TYPE= 'BASE TABLE'

AND TABLE_NAME!= 'sysdiagrams'

END

No comments:

Post a Comment