Monday, March 26, 2012

How to get the list of table names in a SQL2005 database

How to get the list of table names in a SQL2005 database?There's a system catalog view named [sys.tables] that you can query. For more information on this look in SQL Books Online under "catalog views >> sys.objects".

Hope this helps,
Vaughn|||Thanks Vaughn. But when I query this view, it also returns some tables those are not created by myself such as dtproperties table and sysdiagrams table. How can I filter them out?|||

Depending on what exactly you're trying to accomplish you may want to filter out tables for which the "is_ms_shipped" column is "1" or you may want to join against the "sys.schemas" table and filter the results to certain schemas (e.g. owners).

Hope this helps,
Vaughn

|||The problem I have is that the "sysdiagrams" table, that is added when you try to make a diagram, is treated by the database just like a table I personally add. There are no settings that I can see that will identify the table as a microsoft table and not one of mine. I can put in code that excludes it, but are there any other tables that do this too that I should be checking for?

No comments:

Post a Comment