SQL SERVER 2008 R2 – How to Get the List of All the Tables for All Databases Using System Tables Concept

To accomplish this task its simple with the below script :

sp_msforeachdb ‘select “?” AS db, * from [?].sys.tables’

By executing the Above script you can get a list of all the tables in all the databases in separate window.

Any Comments regarding this post is welcome.

Reference : Dilip Kumar Jena ( https://sqlexplore.wordpress.com )

Advertisements

4 thoughts on “SQL SERVER 2008 R2 – How to Get the List of All the Tables for All Databases Using System Tables Concept

  1. sp_msforeachdb ‘select “?” AS db, * from [?].sys.tables’

    Error comes, while executing this.

    Incorrect syntax near ‘“’.

    • I understood Your doubt when u directly copy and paste the it it might not get the things as we want see ” is not equal to “ so its a double quotes button check it carefully and then do it ans also ’ replace it with ‘ single quote this will work fine if it dosen’t then write to me sp_msforeachdb ‘select “?” AS db, * from [?].sys.tables’

  2. sp_msforeachdb ‘select “?” AS db, * from [?].sys.tables’

    May be it works only in KJ.

    Sorry, I am using Katmai.

  3. sp_msforeachdb ‘select “?” AS db, * from [?].sys.tables’ works nicely..users must edit the command line using ( ‘ ) and ( ” ) without format, ‘cose SQL don’t recognize text formats.

    oh…by the way, the script works in MC too.. 🙂

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s