x
login about faq Site discussion (meta-askssc)

Maintaining constraints across different databases

What are the different approaches to maintain constraints accross different databases? what are the pro's and con;s of the process, If creating constraints is not possible, what is the best way of doing it? I was also wondering if there is a possibility that, we create a trigger on a datasbase table A residing in the database 1 To insert a new record in the table B in the database 2, When ever there is a new record in the table A?

Any advice is appreciated.

Thanks,

more ▼

asked Nov 30 '10 at 10:53 AM in Default

Katie 1 gravatar image

Katie 1
1.4k 110 161 202

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Constraints between tables among different databases are only possible using the Triggers.

The ON UPDATE and ON DELETE rules you can simply implement by the AFTER UPDATE, DELETE triggers. The referential integrity you can enforce by the INSTEAD OF triggers.

There was a similar question in past about this.

You can create a simple AFTER INSERT Trigger, which will insert data to a table in other database.

CREATE TRIGGER dbo.trg_aTable_AI
   ON  dbo.aTable
   AFTER INSERT
AS 
BEGIN
    SET NOCOUNT ON;

    INSERT INTO [otherdb].[dbo].[OtherTable](Col1, Col2)
    SELECT
       Col1,
       Col2
    FROM INSERTED
END
GO
more ▼

answered Nov 30 '10 at 11:00 AM

Pavel Pawlowski gravatar image

Pavel Pawlowski
20.3k 5 10 20

Thank you !

Nov 30 '10 at 11:15 AM Katie 1
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x1612
x916
x609
x107
x19

asked: Nov 30 '10 at 10:53 AM

Seen: 1271 times

Last Updated: Nov 30 '10 at 11:19 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.