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
 General SQL Server Forums
 New to SQL Server Programming
 Show the name of the DB being queried

Author  Topic 

ecpro
Starting Member

2 Posts

Posted - 2007-01-06 : 00:06:38
Hello. I work on a proprietary software package at work that has a SQL query engine. I'm able to query tables that I know exist but I would like to know what other tables are there in the db. Unfortunately I don't know the name of the database. Is there a SQL statement that will show me the name of the database that I'm running my query on?

Thanks for your help.

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-01-06 : 00:46:31
to get the db name in sql server:

select db_name()

if you want to know what tables there are, you can use the INFORMATION_SCHEMA views, which are supported by many RDBMS (sql server included). eg:

select * from INFORMATION_SCHEMA.TABLES

will show you all tables and views.


www.elsasoft.org
Go to Top of Page

ecpro
Starting Member

2 Posts

Posted - 2007-01-08 : 11:34:38
Thanks!!! That did the trick. Appreciate your help!!!
Go to Top of Page
   

- Advertisement -