473,472 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trigger to delete record from one table with check on another table.

Hi. I want to create a trigger that only allows delete from table A if
corresponding record in table B does not exist. Any idea on how this
can be done? Thanks, Kenneth.
Jul 19 '05 #1
6 7627
Is there a column in table B that references the primary key of table A?

If so, won't the constraint prevent the deletes you want to prevent?
Jul 19 '05 #2
Don't you wanna use referential integrity constraints to achieve this?

ke***************@telenor.com (Kenneth Osenbroch) wrote in message news:<ce*************************@posting.google.c om>...
Hi. I want to create a trigger that only allows delete from table A if
corresponding record in table B does not exist. Any idea on how this
can be done? Thanks, Kenneth.

Jul 19 '05 #3
ke***************@telenor.com (Kenneth Osenbroch) wrote in message news:<ce*************************@posting.google.c om>...
Hi. I want to create a trigger that only allows delete from table A if
corresponding record in table B does not exist. Any idea on how this
can be done? Thanks, Kenneth.


Sounds more like you want a reference constraint.
Do you have Primary keys and Foreign Keys set up on the corredsponding
tables? Looks like from the description table A is the parent table
(wiht a primary key) and table B is the child table (with a foreign
key that references the primary key of table A)

HTH,
ed
Jul 19 '05 #4
ed********@magicinterface.com (Ed prochak) wrote in message news:<4b**************************@posting.google. com>...
ke***************@telenor.com (Kenneth Osenbroch) wrote in message news:<ce*************************@posting.google.c om>...
Hi. I want to create a trigger that only allows delete from table A if
corresponding record in table B does not exist. Any idea on how this
can be done? Thanks, Kenneth.


Sounds more like you want a reference constraint.
Do you have Primary keys and Foreign Keys set up on the corredsponding
tables? Looks like from the description table A is the parent table
(wiht a primary key) and table B is the child table (with a foreign
key that references the primary key of table A)

HTH,
ed


Hi, and thanks for your reply.

The thing is that it is not possible to use constraints based on PK's
and FK's in this database (the relations are placed on the applicaton
layer - hence it doesn't exist any PK's or FK's).

So: I figure trigger is the only solution to ensure the above
scenario. Any ideas on how the trigger would look?

Thanks,
Kenneth
Jul 19 '05 #5
ke***************@telenor.com (Kenneth Osenbroch) wrote in message news:<ce**************************@posting.google. com>...
ed********@magicinterface.com (Ed prochak) wrote in message news:<4b**************************@posting.google. com>...
ke***************@telenor.com (Kenneth Osenbroch) wrote in message news:<ce*************************@posting.google.c om>...
Hi. I want to create a trigger that only allows delete from table A if
corresponding record in table B does not exist. Any idea on how this
can be done? Thanks, Kenneth.


Sounds more like you want a reference constraint.
Do you have Primary keys and Foreign Keys set up on the corredsponding
tables? Looks like from the description table A is the parent table
(wiht a primary key) and table B is the child table (with a foreign
key that references the primary key of table A)

HTH,
ed


Hi, and thanks for your reply.

The thing is that it is not possible to use constraints based on PK's
and FK's in this database (the relations are placed on the applicaton
layer - hence it doesn't exist any PK's or FK's).

So: I figure trigger is the only solution to ensure the above
scenario. Any ideas on how the trigger would look?

Thanks,
Kenneth


I cannot think of any way for a trigger to STOP a delete, other than
maybe throwing an exception?

What do you mean the relations are in the application layer?
(CAUTION: That's the path to hell!)

Do you have two tables in the database or not?

It looks like you are using a screwdriver as a hammer. It doesn't work
well and in the end both the nail and the screwdriver are in bad
shape.

Sorry I cannot be more help, but I have a genetic disorder that
debilitates my programming skills when faced with an absurd
assignment. 8^)

Good luck! you are going to need it.
Ed
Jul 19 '05 #6
ed********@magicinterface.com (Ed prochak) wrote in message news:<4b**************************@posting.google. com>...
ke***************@telenor.com (Kenneth Osenbroch) wrote in message news:<ce**************************@posting.google. com>...
ed********@magicinterface.com (Ed prochak) wrote in message news:<4b**************************@posting.google. com>...
ke***************@telenor.com (Kenneth Osenbroch) wrote in message news:<ce*************************@posting.google.c om>...
> Hi. I want to create a trigger that only allows delete from table A if
> corresponding record in table B does not exist. Any idea on how this
> can be done? Thanks, Kenneth.

Sounds more like you want a reference constraint.
Do you have Primary keys and Foreign Keys set up on the corredsponding
tables? Looks like from the description table A is the parent table
(wiht a primary key) and table B is the child table (with a foreign
key that references the primary key of table A)

HTH,
ed


Hi, and thanks for your reply.

The thing is that it is not possible to use constraints based on PK's
and FK's in this database (the relations are placed on the applicaton
layer - hence it doesn't exist any PK's or FK's).

So: I figure trigger is the only solution to ensure the above
scenario. Any ideas on how the trigger would look?

Thanks,
Kenneth


I cannot think of any way for a trigger to STOP a delete, other than
maybe throwing an exception?

What do you mean the relations are in the application layer?
(CAUTION: That's the path to hell!)

Do you have two tables in the database or not?

It looks like you are using a screwdriver as a hammer. It doesn't work
well and in the end both the nail and the screwdriver are in bad
shape.

Sorry I cannot be more help, but I have a genetic disorder that
debilitates my programming skills when faced with an absurd
assignment. 8^)

Good luck! you are going to need it.
Ed


:o)

I know! Consider the case closed.

Cheers,
Kenneth
Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Neil Rutherford | last post by:
During testing of an application, i noticed a difference between SQL 2000 and SQL 7, both with identical config. In a nutshell: A table has a trigger for UPDATE and DELETE. When a column in the...
5
by: Peter Erickson | last post by:
I am running postgresql 7.4.2 and having problems creating a trigger function properly. I keep getting the following error: ERROR: OLD used in query that is not in rule I have a table called...
2
by: R.Welz | last post by:
Hello. I want to discuss a problem I have with my database design becourse I feel I cannot decide wheather I am on the right way of doing things. First of all, I am writing a literature and...
1
by: Robert Fitzpatrick | last post by:
I am running PostgreSQL 7.4.5 and have a trigger on a table called tblriskassessors which inserts, updates or delete a corresponding record in tblinspectors by lookup of a contact id and license...
6
by: Jchick | last post by:
Im a newbie with a sql table in a MSDE database that contains fields of CustName, BrokerName, Type, Status. I am trying to write a trigger that does this: 1. When a new record in a table is...
8
by: Benzine | last post by:
Hi, I have an issue with my replication at the moment. I will try to describe the scenario accurately. I am using MS SQL 2000 SP4 with Merge Replication. Subscribers connect to the publisher...
3
by: orakelvin | last post by:
Hi I am geting an error ORA-04091 table is mutuating, trigger cannot seen it. The situation arise because I am having two table employee Id empcol 101 ...
1
by: veasnamuch | last post by:
I have a problem while I create a trigger to my table. My objective is getting any change made to my table and record it in to another table . My have thousands records before I add new trigger to...
6
by: Kenneth Osenbroch | last post by:
Hi. I want to create a trigger that only allows delete from table A if corresponding record in table B does not exist. Any idea on how this can be done? Thanks, Kenneth.
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.