Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 how can I query an entire schema?

Author  Topic 

SQLIsTheDevil
Posting Yak Master

177 Posts

Posted - 2008-04-29 : 13:42:57
Say I wanted to query an entire schema. How may I go about this and are there any consequences or pitfalls executing such as task? That is, and I'm probably being paranoid, I don't wish to *break* the database.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-29 : 13:45:22
What do you mean by "query an entire schema"? Show us a data example to be more clear.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

SQLIsTheDevil
Posting Yak Master

177 Posts

Posted - 2008-04-29 : 14:26:03
Let me rephrase my question. Let's use the Northwind database for this discussion. I'd like to select all user tables. I came across this query here:

SELECT name FROM sysobjects WHERE xtype = ‘U’

But I'm concerned if this is dangerous and combining so many tables will somehow crash the server (I'm being very paranoid, but I figure just ask).

Thank you.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-29 : 14:30:07
SELECT * FROM INFORMATION_SCHEMA.TABLES
SELECT * FROM INFORMATION_SCHEMA.COLUMNS




E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SQLIsTheDevil
Posting Yak Master

177 Posts

Posted - 2008-04-29 : 14:32:46
thank you. I'll try it. where can information_schema be found exactly, as I can't seem to locate it in query analzyer.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-29 : 14:35:28
The views are stored in the master database, but when you run them from your database, you get the data from that database instead of master. Check out the INFORMATION_SCHEMA views in Books Online for more details.

The queries are not dangerous as you are just returning metadata and not actual data from the tables. If you were to return every single row from every single table, now that would be dangerous.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -