x

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, 2010 at 10:53 AM in Default

avatar image

Katie 1
1.4k 132 164 205

(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, 2010 at 11:00 AM

avatar image

Pavel Pawlowski
22.7k 10 15 26

Thank you !

Nov 30, 2010 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

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x2075
x1066
x992
x76
x24

asked: Nov 30, 2010 at 10:53 AM

Seen: 2187 times

Last Updated: Nov 30, 2010 at 11:19 AM

Copyright 2016 Redgate Software. Privacy Policy