Friday, February 24, 2012

how to combine two different SQL server data instance into one db?

Hi

I'd like to know how I can combine two tables from two different sql instances ito one db?

thanks.

Volkan, can you provide a little more info?

Are you trying move the data from sql instance 1 and sql instance 2 into a new database on sql instance 3?

Are you asking how you can query the data from two different instances?

You can query separate instances by using a four-part qualifier if the instances are defined as linked servers.

select * from [servername].[databasename].[schema].[tablename]

Example: server = MySQL1, database = MyDatabase, schema = dbo, table = MyTable

select * from MySQL1.MyDatabase.dbo.MyTable

|||

If both the DBs are on same Server and the current user have access permission on both database then you can use the following query..

Select SomeColumns From CurrentDBName..TableName
Select SomeColumns From OtherDBName..TableName

If the databases are on different Server then you have to use the Linked Server..

EXEC sp_addlinkedserver @.server = 'SERVER', @.provider = 'SQLOLEDB.1', @.srvproduct = '', @.provstr = 'Privider=SQLOLEDB.1;Data Source=TargetServer;Initial Catalog=Database'

go
Exec sp_addlinkedsrvlogin @.rmtsrvname = 'SERVER', @.useself = true, @.locallogin = null, @.rmtuser = 'Userid', @.rmtpassword = 'Password'


On your SP you can use..

Select * From OpenQuery(MyRemoteServer, 'Select * From Sysobjects')

--OR

Select * From MyRemoteServer.DatabaseName.dbo.Sysobjects

No comments:

Post a Comment