Question:
Oracle SQL constraints.?
WYSIWYG
2009-04-25 15:57:23 UTC
Hi, ok... I have created constraints in oracle. aka.... a relationship between two entities. Is it possible to actually give the constraing a name such as (constraing between table 1 and table 2 = pay)... thanks.
Three answers:
2009-04-25 16:10:15 UTC
Um ... I've never made a foreign key constraint that wasn't named.



http://www.techonthenet.com/oracle/foreign_keys/foreign_keys.php
2016-10-17 13:53:17 UTC
it is right:verify constraints in Oracle are extremely constrained while in comparison with different databases. the only verify you're able to do is on columns of the present table. the customary way (as indicated with the aid of rachetr is to apply a sequence off). something like here. notice which you would be able to no longer use a subquery immediately in a IF assertion, so which you want a separate opt for to verify the existence of your POLICE_ID. create or replace set off police_id_check until eventually now insert or replace of police_id on your_table for each row declare police_id_count variety; initiate opt for count variety(*) into police_id_count from police the place police_id = :NEW.police_id and rank_id = 2; if police_id_count = 0 then raise_application_error (-20000, 'police_id no longer in police table'); end if; end; / teach errors in case you attempt and replace or insert a row with an invalid police_id, you will get an errors. working example: replace your_table set police_id = 9999 the place .... (the place 9999 would not exist in the POLICE table - or exists with a RANK different than 2) will fail like this: errors at line a million: ORA-20000: 'police_id no longer in police table ORA-06512: at "SCOTT.POLICE_ID_CHECK", line 9 ORA-04088: errors for the duration of execution of set off 'SCOTT.POLICE_ID_CHECK'
Every drop counts
2009-04-27 23:52:17 UTC
alter table table2

add constraint pay

FOREIGN KEY (table1_id) REFERENCES table1 (id);


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...