473,804 Members | 3,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inserting data to tables belonging to different databases

Hi all,

we are developing an internal application that involves "Timesheets ",
"Support" and "Project Management".
Imagine that there are 3 different databases for the above scenario,
under SQL Server 2000.
My task is to create one or a few table triggers for
INSERT/UPDATE/DELETE operations. For example:
- if a row is added in Table A of "Timesheets " database, then Table B
of "Project Management" needs to be updated.

The concept is clear i think. The question is how we do the above.
Note that I am a new progremmer to SQL Server (I have been dealing
with Oracle so far), and I don't know how we programmaticall y connect
to different database within a trigger, how do we check the
priviledges etc.

Can someone help me?

Thanks
Christos Andronicou
Jul 23 '05 #1
1 1488
The most important point to understand about triggers in SQL Server is
that they are triggered at statement level - there are no row-level
triggers. So you should write code that will perform correctly whether
there are 0,1 or N rows affected. To do this you reference two virtual
tables called DELETED and INSERTED, which expose the Before and After
states of the changed rows.

Copying data between databases is easy. Just specify the three-part
name: database.owner. object.

Example:

CREATE TRIGGER trg_tablea ON DB1.dbo.tableA FOR INSERT AS

INSERT INTO DB2.dbo.TableB (key_col, x, y, z)
SELECT key_col, x, y, z
FROM Inserted AS I
WHERE NOT EXISTS
(SELECT *
FROM DB2.dbo.TableB
WHERE key_col=I.key_c ol)

GO

If the databases are on different servers then you will need to be
running the Distributed Transaction Coordinator service and specify a
four-part name, including the linked server name.

Hope this helps.

--
David Portas
SQL Server MVP
--

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3353
by: djc | last post by:
I need to use data from multiple tables that are located in 2 different databases. Most of the tables are in SQL Server 2000 but 1 one the tables I need to include in my query resides in an Access2002 mdb file. I need to do this via ASP/ADO on IIS5. How do I combine (join in a query) tables from different databases? they are each opened from a different connection object? I have only had to access tables from one source before and I...
0
2426
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish, Swedish or English). There are about a dozen tables with columns that need localization. Doing this in the application level was a no-goer. It would have taken far too much time (there is a *lot* of code and unfortunately most of the...
3
2277
by: crespoh | last post by:
Hi, How do I select data from two tables from two different databases and compare them? using dbi,odbc
2
2322
by: Sara | last post by:
Hi - I've been reading the posts for a solution to my query, and realize that I should ask an "approch" question as well. We receive our production data from a third party, so my uers import the data from Excel into the appropriate tables. There are 6 different databases that receive data, though 4 of them only get one table each. I have learned how to automate the data import through
9
12614
by: gopi | last post by:
when installing db2, it only asks for installation directory and does not ask where it is going to store data files. how can i change the default directory after installation.
8
2206
by: AA Arens | last post by:
Hi I do have a products table and products-parts table in my Access 2003 database and log all services into a form. I do have at least the following two combo boxes on my form: - Choose Product where as the Row Source (See properties): SELECT tblProducts.ProductName, tblProducts.ProductName FROM tblProducts ORDER BY ProductName;
3
3879
by: Ralph Smith | last post by:
I have two identical databases on two different servers and I need to add the data in tables from one server to the tables in the other server. Is there a way to do that in mysql? thanks, Ralph
9
2189
by: karenjfrancis | last post by:
I have 4 Access databases, all with the same data model but different data. I want to build a front end that brings all of the data in the 4 databases together into one. Assuming my table of interest is called Removals, if I create linked tables I end up with Removals1, Removals2, Removals3 and Removals4. I could easily write a query to base a form or report upon to concatenate all of these tables' data into one view. However, the...
4
4102
by: sganeshsvk | last post by:
sir, i want to store the same data values in two different databases at that same time in mysql using php programming. suppose any one databases data will lose then we use the other databases. suppose there is any query for store the same data values in two different databases at the same time. for eg: databases sample1
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10326
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.