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
 USE ?

Author  Topic 

sharankruthi
Starting Member

22 Posts

Posted - 2009-07-16 : 03:15:01
I need to know what is the function of USE ?; in
sp_msforeachdb @command1 = "USE ?;select name, type from sys.objects where type in ('U', 'P')"

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-16 : 03:17:02
it changes the current database context
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-16 : 03:17:15
in sp_msforeachdb ? will be replace by database name
so this will be executed for each of the db

use <database name>
select name, type from sys.objects where type in ('U', 'P')



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-16 : 03:17:55
quote:
Originally posted by russell

it changes the current database context


And this too . . missed out this point.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sharankruthi
Starting Member

22 Posts

Posted - 2009-07-16 : 03:19:49
'Use ?' can only be used with sp_msforeachdb is it?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-16 : 03:34:24
quote:
Originally posted by sharankruthi

'Use ?' can only be used with sp_msforeachdb is it?


The "?" is specially handled in sp_msforeachdb. It will be replace with the database name.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sharankruthi
Starting Member

22 Posts

Posted - 2009-07-16 : 03:35:28
ok ok thankx..
Go to Top of Page
   

- Advertisement -