SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


USE Database


USE Database

Author
Message
Minnu
Minnu
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1299 Visits: 950
Hi Team,

Am having two datbases in one instance,

whenever i execute any scripts, i'll use "USE DATABASE" and execute the scripts,

Is there any way to mention instance name, instead of Database name.

Eg:
USE INSTANCE
GO
USE DATABASE
GO
EXEC Store_spoc..


Please Suggest...
DBA From The Cold
DBA From The Cold
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3321 Visits: 1757
Hi,

If you have the one instance as a linked server, you can reference it from the other instance by:-

[Server Name].[Database Name].[Schema Name].[Object Name]

Andrew
MarkusB
MarkusB
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10037 Visits: 4208
You could open a query window in SQLCMD mode and then use the following syntax

:CONNECT Server\InstanceName
USE DATABASE
GO
EXEC STORED PROC...

Markus Bohse
Steven Willis
Steven Willis
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1893 Visits: 1721
Minnu (7/16/2013)
Hi Team,

Am having two datbases in one instance,

whenever i execute any scripts, i'll use "USE DATABASE" and execute the scripts,

Is there any way to mention instance name, instead of Database name.

Eg:
USE INSTANCE
GO
USE DATABASE
GO
EXEC Store_spoc..


Please Suggest...

This script should do it:



-- this sets up a linked server (or you can right-click "Server Objects|Linked Servers"
-- and set up the link manually using the wizard)

USE [YOUR_DATABASE]
GO

EXEC master.dbo.sp_addlinkedserver
@server = N'[LINKED_SERVER_NAME]'
,@srvproduct = N'SQL Server'
/* For security reasons the linked server remote logins password is changed with ######## */
GO

EXEC master.dbo.sp_addlinkedsrvlogin
@rmtsrvname = N'[LINKED_SERVER_NAME]'
,@useself = N'False'
,@locallogin = NULL
,@rmtuser = N'[USER_NAME]'
,@rmtpassword = '[PASSWORD]'
GO






-- Once you have the server link set up then you can connect to it
-- just like any other object but you must provide a fully qualified reference

SELECT
*
FROM
[YOUR_DATABASE].[DBO].[YOUR_TABLE] AS a
INNER JOIN
[LINKED_SERVER_NAME].[LINKED_DB_NAME].[DBO].[LINKED_TABLE] AS b
ON a.ID = b.ID




 
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search