Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / General DB Topics / General DB Topics / August 2004

Tip: Looking for answers? Try searching our database.

[MaxDB] Transactions with Foreign Key Constraints

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 31 Aug 2004 12:06 GMT
I have two tables A and B which satisfy various foreign key constraints
( A to B AND B to A).

I would like to add some date to A and some data to B. Once all the data
has been added, A and B will satisfy the foreign key constraints, but
there is no way of achieving this without violating a foreign key
constraint in the process.

The obvious solution is to use transactions, but this makes no difference.

If anyone has managed to get MaxDB to do this, could they please show me
their SQL?

John
Daniel Dittmar - 31 Aug 2004 12:51 GMT
> I have two tables A and B which satisfy various foreign key constraints
> ( A to B AND B to A).
[quoted text clipped - 3 lines]
> there is no way of achieving this without violating a foreign key
> constraint in the process.

MaxDB can't handle deferred constraint checking. Your only chance would
be to
- INSERT INTO A (keycol, bref) VALUES ('a', NULL)
- INSERT INTO B (keycol, aref) VALUES ('b', 'a')
- UPDATE A SET bref = 'b' where keycol = 'a'

or perhaps more general:
- INSERT all rows without references
- UPDATE all rows with their respective references
if you have truly complex cycles, because you don't have to care about
the order of INSERTS.

An even more general solution would be to have a second column with the
reference, which isn't specified as a CONSTRAINT.

You could then patch all the references for each table with one UPDATE
for each table. Using TEMP tables instead to preserve space is left as
an exercise to the reader.

Daniel Dittmar

P.S. You have generally a much better chance of getting qualified
information on MaxDB if you post to maxdb@lists.mysql.com
(http://lists.mysql.com/#maxdb) or
nntp://news.gmane.org/gmane.comp.db.maxdb (if you prefer access as a
newsgroup).

Signature

Daniel Dittmar
SAP Labs Berlin
daniel.dittmar@sap.com

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.