[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by ben oliver:
Hi,
I am learning to write oracle sql trigger. I have a table
STUDENT(ID, name, address, phone), where ID is from STUDENT_SEQ oracle sequence and it is the PK. where I want to make sure is --
when a new row is going to be inserted into the table, first check if there is already a similar row exsiting there. If yes, then don't insert. How about this trigger
create or replace trigger BI_CHECK_EXIST
BEFORE INSERT
if( ** there is already a row whose "name", "address", "phone" is in the table **) THEN
RAISE_EXCEPTION_ERROR(..)
end if;
End;
Does this make sense ? But how to write
** there is already a row whose "name", "address", "phone" is in the table *
?? I have no idea..
Any help will be appreciated.
OCUP UML fundamental and ITIL foundation
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by Jan Cumps:
Paul, why would we prefer using a trigger in stead of constraint?
Would it not be more straightforward to use the declarative unique constraint, rather than the trigger?
Regards, Jan
Lucky you. I tend to fall asleep during meetings.Sometimes when sleep deprived, I become an "over-thinker".
OCUP UML fundamental and ITIL foundation
Originally posted by Jan Cumps:
Lucky you. I tend to fall asleep during meetings.
Originally posted by ben oliver:
Now folks, I am using Oracle 10g XE as many people are using. I found when I create constraint and select "unique" it only allows me to pick 3 columns !! Is this a restriction of 10g XE product or what ? How many column does oracle allow us to specify for such unque constraint ?
Thanks.
No. The ENABLE clause serves to re-enable constraints that you have disabled before.Originally posted by ben oliver:
Do I need to put the syntax of "ENABLE" ??
OCUP UML fundamental and ITIL foundation
Originally posted by Jan Cumps:
No. The ENABLE clause serves to re-enable constraints that you have disabled before.
This article on TECH on the Net explains it nicely.
[ January 11, 2008: Message edited by: Jan Cumps ]
See where your hand is? Not there. It's next to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|