Thursday, February 9, 2012

about catalog view

I can find all databases i created from sys.databases view

but i could not find tables info under relevant database by sys.tables view? and I do not know why sys.tables,sys.columns and other views do not have database_id attribute? any idea? thanks

As the sys.tables and sys.columns are catalog views within a database, they are only relevant to THAT database. Therefore, you don't need a database_id attribute. There are instances of these views in every database.

If you do want to return that attribute when querying the table, just add db_id() to your select statement.

However, if you want to list all tables on an instance, try using the undocumented proc sp_MsForEachDB.

sp_msforeachdb 'select * from ?.sys.tables'

Hope this helps!

|||

thanks in advance

but i could not find any instruction about this from books online?

any advice about useful undocumented proc in MSSQL? thanks

No comments:

Post a Comment