Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


USE Database


USE Database

Author
Message
Minnu
Minnu
Old Hand
Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)

Group: General Forum Members
Points: 305 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
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1788 Visits: 1728
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
SSCarpal Tunnel
SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)

Group: General Forum Members
Points: 4449 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
SSC-Addicted
SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)SSC-Addicted (483 reputation)

Group: General Forum Members
Points: 483 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