It does not use a loop. Hope this helps!
Note that "TABLE_OWNER" matches the "SCHEMA Owner" and "TABLE_TYPE" will determine if the item is a table or view.
--This will return all tables, table owners and table types for all database(s) that are NOT 'Offline' --Offline database information will not appear Declare @temp_table table( DB_NAME varchar(max), TABLE_OWNER varchar(max), TABLE_NAME varchar(max), TABLE_TYPE varchar(max), REMARKS varchar(max) ) INSERT INTO @temp_table (DB_NAME, TABLE_OWNER, TABLE_NAME, TABLE_TYPE,REMARKS) EXECUTE master.sys.sp_MSforeachdb 'USE [?]; EXEC sp_tables' SELECT DB_NAME, TABLE_OWNER, TABLE_NAME, TABLE_TYPE FROM @temp_table --Uncomment below if you are seaching for 1 database --WHERE DB_NAME = '<Enter specific DB Name>' --For all databases other than 'System Databases' WHERE DB_NAME not in ('master','model','msdn','tempdb') order by 1,2,3
Jeremy F.
source share