June 6, 2011 at 7:54 am
We all know the command to change from one table to another in SQL code:
USE Table1
GO
USE Table2
GO
My question is this: Is there a way to change from one database to another using code like this?
Thanks.
Steve
June 6, 2011 at 8:00 am
sdownen05 (6/6/2011)
We all know the command to change from one table to another in SQL code:USE Table1
GO
USE Table2
GO
My question is this: Is there a way to change from one database to another using code like this?
Thanks.
Steve
you cannot "use" a table, only a database is valid after the USE command; the commands you posted onyl work if you have two databases named 'Table1] and [Table2]
you can use a semicolon instead of the GO if you want:
USE SandBox; SELECT * FROM sys.tables ; --returns tables int he sandbox database
USE master; SELECT * FROM sys.tables --returns tables in the master database
[/code]
Lowell
June 6, 2011 at 8:21 am
It is definitely Monday morning.
Thanks for the correction. You are right. What I want to do is change to a different instance. Does this make sense?
June 6, 2011 at 8:34 am
Disconnect and reconnect. Or look at SQLCMD mode. There's no T-SQL command that will let you switch instances
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 6, 2011 at 9:25 am
What you need to do in new query window is right click > Connection > Change Connection, this will change the instance you are connected to.
__________________________________________________________________________________
Steve J
Jnr Developer
BSc(Hon)
June 6, 2011 at 11:55 am
I'm trying to automate a process. That wouldn't work.
June 6, 2011 at 11:59 am
GilaMonster (6/6/2011)
Or look at SQLCMD mode. There's no T-SQL command that will let you switch instances
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 6, 2011 at 12:19 pm
So sorry Gail. I forgot to thank you for your answer. I have already created a program that calls SQLCMD to do what I need to do. You have been a great help.
Steve
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply