Home » SQL & PL/SQL » SQL & PL/SQL » Foreign key
Foreign key [message #224747] Thu, 15 March 2007 05:50 Go to next message
pham
Messages: 17
Registered: August 2006
Junior Member
I have to create this foreign key:

ALTER TABLE tab1
ADD CONSTRAINT fk_tab1_tab2
FOREIGN KEY(col1, col2) REFERENCES tab2(col1, BETWEEN min_val_col AND max_val_col);

and don't know the correct syntax.

Help, help, help

thank for your help
Re: Foreign key [message #224755 is a reply to message #224747] Thu, 15 March 2007 06:07 Go to previous messageGo to next message
michael_bialik
Messages: 611
Registered: July 2006
Senior Member
Foreign key matches a value of table A to a single value of table B.
You have to use trigger to implement your logic.

HTH.
Michael
Re: Foreign key [message #224761 is a reply to message #224755] Thu, 15 March 2007 06:30 Go to previous messageGo to next message
pham
Messages: 17
Registered: August 2006
Junior Member
here more info:

the tab1 has 2 columns col1 and col2
the tab2 has a primary key with 3 columns: col1, col2_1 and col2_2

It is a foreign key to build between this two tables, where
tab1.col1 = tab2.col1 and
the value of tab1.col2 is between tab2.col2_1 and tab2.col2_2

how is the syntax for "ALTER TABLE tab1 ..."

thank in advance
Re: Foreign key [message #224788 is a reply to message #224747] Thu, 15 March 2007 08:24 Go to previous messageGo to next message
michael_bialik
Messages: 611
Registered: July 2006
Senior Member
You can NOT do it with FK - define a trigger.
Re: Foreign key [message #224792 is a reply to message #224788] Thu, 15 March 2007 08:55 Go to previous message
pham
Messages: 17
Registered: August 2006
Junior Member
ok, ok
I'm wrong, I make a mistake. It can't work with that.
I have to redesign the tables.

Thank a lot
Previous Topic: Is it possible to determine if a column has been updated inside a trigger
Next Topic: need how to make of exists operator
Goto Forum:
  


Current Time: Thu Dec 08 12:30:33 CST 2016

Total time taken to generate the page: 0.09050 seconds