dbTalk Databases Forums  

mutliple refential integrity

comp.databases comp.databases


Discuss mutliple refential integrity in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ravi
 
Posts: n/a

Default mutliple refential integrity - 05-31-2007 , 06:57 AM






Suppose I want a column in my table to reference two other columns of
other two tables (of course datatypes are same, and the other two
columns are primary key in their respective relations). How can I
enforce this using SQL?


Reply With Quote
  #2  
Old   
Carl Kayser
 
Posts: n/a

Default Re: mutliple refential integrity - 05-31-2007 , 08:44 AM







"Ravi" <ra.ravi.rav (AT) gmail (DOT) com> wrote

Quote:
Suppose I want a column in my table to reference two other columns of
other two tables (of course datatypes are same, and the other two
columns are primary key in their respective relations). How can I
enforce this using SQL?

What do you mean?

If you mean that it must be in the intersection of the two tables then two
foreign key declarations suffice. If you mean the union of the two tables
then you'll probably have to with triggers in your (unspecifed) RDBMS.




Reply With Quote
  #3  
Old   
--CELKO--
 
Posts: n/a

Default Re: mutliple refential integrity - 06-01-2007 , 11:16 AM



Quote:
Suppose I want a column in my table to reference two other columns of other two tables (of course data types are same, and the other two columns are primary key in their respective relations). How can I enforce this using SQL? <<-
CREATE TABLE Foo
(foo_id INTEGER NOT NULL PRIMARY KEY,
..);

CREATE TABLE Bar
(_id INTEGER NOT NULL PRIMARY KEY,
..);

CREATE TABLE Foobar
(foo_id INTEGER NOT NULL
REFERENCES Foo(foo_id),
bar_id INTEGER NOT NULL
REFERENCES Bar(bar_id),
..);




Reply With Quote
  #4  
Old   
punit arya
 
Posts: n/a

Default Re: mutliple refential integrity - 06-08-2007 , 07:42 AM



On May 31, 4:57 pm, Ravi <ra.ravi.... (AT) gmail (DOT) com> wrote:
Quote:
Suppose I want a column in my table to reference two other columns of
other two tables (of course datatypes are same, and the other two
columns are primary key in their respective relations). How can I
enforce this using SQL?
CREATE TABLE <TABLE_NAME>
(
<COLUMN 1> <TYPE>,
<COLUMN 2> <TYPE>,
....
<COLUMN N> <TYPE>
FOREIGN KEY (<COLUMN NAME BEING REFERENCED>) REFERENCES
<OTHER_TABLE_NAME> (<COLUMN NAME BEING REFERENCED>),
FOREIGN KEY (<COLUMN NAME BEING REFERENCED>) REFERENCES
<OTHER_TABLE_NAME> (<COLUMN NAME BEING REFERENCED>)
);

This will do. & if you want to give this constraint a name, so that
you can later on remove or modify it, you can give it a name by
CONSTRAINT <CONSTRAINT NAME> FOREIGN KEY...

this constraint name should be unique within a schema.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.