Grupos de Google ya no admite publicaciones ni suscripciones nuevas de Usenet. El contenido anterior sigue visible.

mutliple refential integrity

1 vista
Ir al primer mensaje no leído

Ravi

no leída,
31 may 2007, 7:57:32 a.m.31/5/2007
para
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?

Carl Kayser

no leída,
31 may 2007, 9:44:05 a.m.31/5/2007
para

"Ravi" <ra.ra...@gmail.com> wrote in message
news:1180612651....@q19g2000prn.googlegroups.com...

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.


--CELKO--

no leída,
1 jun 2007, 12:16:05 p.m.1/6/2007
para
>> 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),
..);


punit arya

no leída,
8 jun 2007, 8:42:22 a.m.8/6/2007
para

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.

0 mensajes nuevos