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 2005 Forums
 Transact-SQL (2005)
 database name

Author  Topic 

Sep410
Posting Yak Master

117 Posts

Posted - 2008-05-12 : 12:29:21
Hi

I just know a table name and I am looking for the database name.

Please let me know how should I do that.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-12 : 12:36:45
Exec sp_MSforeachdb 'Select * From ?..sysobjects where xtype= ''U'' And name like ''YourTableName'''
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-05-12 : 13:33:55
A minor 'enhancement'...
Exec sp_MSforeachdb 'if exists (select * From ?..sysobjects where type = ''u'' and name like ''YourTableName'') select ''?'' as db'


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

Sep410
Posting Yak Master

117 Posts

Posted - 2008-05-12 : 14:57:05
Thank U for replying my question but I didi what you said and justchanged YourTableName to My table's name.

It is not working.what should I do?
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-05-12 : 15:00:15
Its working for me. Did you try Ryan's?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-12 : 15:03:47
quote:
Originally posted by Sep410


It is not working.



Care to provide more information?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page
   

- Advertisement -