List of schemas and tables on SQL server

I needed to show all tables and schemas in actual database so I have created following script.

Script:


declare Tbl_Cursor cursor for
select o.name, s.name from sys.objects o 
join sys.schemas s on s.schema_id = o.schema_id
where type='U';
declare @tbl_name as varchar(50);
declare @tbl_schema as varchar(50);
open tbl_cursor;
fetch next from tbl_cursor 
  into @tbl_name, @tbl_schema;
while @@FETCH_STATUS=0
  begin
    print @tbl_schema + '.' + @tbl_name
    fetch next from tbl_cursor
      into @tbl_name, @tbl_schema;
  end;
close tbl_cursor;
deallocate tbl_cursor;


	

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s