SQL Server update two different server by trigger - sql

I have two SQL Server
1st - 10.101.102.133
2nd - 10.101.102.155
Both having the different database with different names and fields.
My application will update in the 1st server.
Can I actually configure the 1st server that once it received update query, it will update in 2nd server as well?
I want to insert data from 1st server to 2nd server by using trigger. when my Application insert data in a table in 1st server database a trigger will fire (insert trigger). and it pass the data in 2nd server by its user id and password.
How I write the script of this trigger?

Solved here: Selecting data from two different servers in SQL Server
You can use sp_addlinkedserver or Linked Servers approach.
Using sp_addlinkedserver would be something like this once you have set up the linked server:
select
*
from
LocalTable,
[OtherServerName].[OtherDB].[dbo].[OtherTable]

Related

SQL update two different server

I have two SQL server [example]:
1st - 10.101.102.133
2nd - 10.101.102.155
Both having the same database with same names and fields.
My application will update in the 1st server.
Can I actually configure the 1st server that once it received update query, it will update in 2nd server as well?
I do not wish to change my application source code but instead want to make configuration on the server itself.

How to export from one Server to another Server Database table in SQL Server?

I want to move data from one server database to another server database.
I hope the following code will work.
But I don't know what is my DestinationServerName and SourceServerName. Where I can find those names.
INSERT INTO [DestinationServerName].[DatabaseName1].[dbo].[TableName]
SELECT
[FieldName]
FROM
[SourceServerName].[DatabaseName2].[dbo].[TableName]
In 4 parts name Servername is a name given to a linked server. You may create linked servers with SSMS or by using sp_addlinkedserver

Run a Sql Query on multiple Servers and each server has different databases(database name is diff on each server) with same tables

Run a Sql Server Query on multiple Servers and each server has different databases(database name is diff on each server) with same tables
In the management studio, you can register multiple servers into one group. Then you can run query on the group.
In SSMS open Registered Servers and create a New Server Group under Local Server Groups.
Under this group create New Server Registration for each server you wish to query. If the DB names are different ensure to set a default for each in the properties. You can register a server/instance multiple times with different default DBs.
Now go back to the Group you created in the first step, right click and select New Query. A new query window will open and any query you run will be executed on each server in the group. The results are presented in a single data set with an extra column name indicating which server the record came from. If you use the status bar you will note the server name is replaced with multiple.

How to select a table from one machine to another using sql server 2008 r2?

I have explained the scenario below:
I am having two servers:
server 1
server 2
In both the servers I have Sql Server 2008 r2.
In server 1, I have a database named "DB_Server1" and in server 2, a database named "DB_Server2".
In DB_server1 database, I have a table named "TB_Server1" and in DB_Server2, a table named "TB_Server2".
My requirement is, in DB_Server1, I'm going to write a stored procedure which selects the table "TB_Server2" from DB_Server2 which is located in the server 2.
How can I achieve the above requirement?
you can use linkserver
at first select Server1
step 1: exec sp_addlinkedserver 'Server2'
step 2: select * from [Server2].[DB_Server2].TB_Server2
You can create linked server (http://msdn.microsoft.com/library/ff772782.aspx)
Use Linked Server:
Allows you to query databases and tables on remote servers as though they are part of the local database. Very easy to setup (just call exec sp_addlinkedserver) and once defined uses nothing but plain old SQL.
Here is a simple tutorial about how to create a linked server. After creating linked server, we can query it as follows:
select * from LinkedServerName.DatabaseName.dbo.TableName
Click here for another tutorial.
Read more about Linked Servers here.

Conditional Trigger and Insert to a remote SQL Server Database server

How can I set up a conditional trigger to be fired when a particular condition is met after an update or insert and then insert some of the inserted values into another table located on another SQL Server database on SQL Server 2005?
Read here about creating triggers. In your case it will be a normal data manipulation language (DML) event trigger.
In order to insert data to a remote server you need to configure a linked server. You have a few tools for that: you can either use SQL via sp_addlinkedserver, or you can use SQL Server Management Studio (SSMS). In latter case you will be able to do it via GUI. See this article for the instructions.
Once you configure the linked server, you can access its tables directly from SQL (In the example below a linked server SRVR002\ACCTG is used):
SELECT name FROM [SRVR002\ACCTG].master.sys.databases