473,472 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with delete trigger

I have a table, SecurityMasterUnderlying, that has a 2 foreign key
constraints to the same table (SecurityMaster). The first one is a
one-to-one relationship. The second being a many-to-one.

* All securities (equities, options, futures) will have ONE row in
SecurityMaster.
* All derivatives (options) will also have ONE row in
SecurityMasterUnderlying.
* All derivatives will have an underlying security (think of it as a
parent) in SecurityMaster. The underlying security CAN have multiple
childs.

I cannot use ON DELETE CASCADE on both FK definitions since that
creates a circular reference so I need to use a trigger on one of
them.

I am having trouble writing the trigger that will delete the
derivative (from SecurityMaster) if the underlying security is
deleted. (With the sample data -- DIAXL should be deleted if DIA is)
CREATE TABLE [SecurityMaster] (
[Symbol] VARCHAR(15) NOT NULL,
[Identity] VARCHAR(15) NOT NULL,
[Name] VARCHAR(50) NULL
) ON [PRIMARY]

CREATE TABLE [SecurityMasterUnderlying] (
[Symbol] VARCHAR(15) NOT NULL,
[Identity] VARCHAR(15) NOT NULL,
[UnderlyingSymbol] VARCHAR(15) NOT NULL,
[UnderlyingIdentity] VARCHAR(15) NOT NULL,
[Shares] INT NOT NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[SecurityMaster]
ADD
CONSTRAINT [PK_SecurityMaster] PRIMARY KEY NONCLUSTERED (
[Symbol], [Identity]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[SecurityMasterUnderlying]
ADD
CONSTRAINT [FK_SMUnderlying_SM] FOREIGN KEY (
[Symbol], [Identity]
)
REFERENCES [dbo].[SecurityMaster] (
[Symbol], [Identity]
) ON DELETE CASCADE
ALTER TABLE [dbo].[SecurityMasterUnderlying]
ADD
CONSTRAINT [FK_SMUnderlying2_SM] FOREIGN KEY (
[UnderlyingSymbol], [UnderlyingIdentity]
)
REFERENCES [dbo].[SecurityMaster] (
[Symbol], [Identity]
)
GO

INSERT INTO SecurityMaster VALUES ('MSFT', '00764G53A', 'Microsoft')
INSERT INTO SecurityMaster VALUES ('DIA', '654FE32', 'Diamond')
INSERT INTO SecurityMaster VALUES ('DIAXL', '7635TRS', 'DIA Option')

INSERT INTO SecurityMasterUnderlying VALUES ('DIAXL', '7635TRS',
'DIA', '654FE32', 100)
Jul 20 '05 #1
0 2230

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

Similar topics

2
by: Bob Ganger | last post by:
Hello, I am working on a project using SQL Server 2000 with a database containing about 10 related tables with a lot of columns containing text. The total current size of the database is about...
8
by: Jason | last post by:
I have a table that matches up Securities and Exchanges. Individual securities can belong on multiple exchanges. One of the columns, named PrimaryExchangeFlag, indicates if a particular exchange is...
1
by: Matik | last post by:
Hello to all, I have a small question. I call the SP outer the DB. The procedure deletes some record in table T1. The table T1 has a trigger after delete. This is very importand for me, that...
4
by: Marie-Christine | last post by:
i want to audit transactions done to table TOrig. I created table TAudit same as TOrig in addition to ActionID (1 for insert, 2 for update, 3 for delete), System Date and System User. I created...
6
by: ilo | last post by:
When I want to delete a data from a table that this tabl has a trigger and this trigger reached another tables to delete the data in cursor I have this messeage: DELETE failed because the...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
4
by: Alexis | last post by:
Hello, I'm facing oracle trigger problem. Anyone can help or advise how to resolve it? Below are the explaination on my problem I've created a trigger for my program. When there is a new...
11
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG'...
11
by: Ed Dror | last post by:
Hi there, I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro. I have a Price page (my website require login) with GridView with the following columns PriceID, Amount, Approved,...
3
by: lenygold via DBMonster.com | last post by:
Hi everybody! I have an INSERT stattement like this: insert into ELIGIBLE_PAY select from ELIGIBLE_PAY_B where cust_id = 999999; after insert i would like to delete row from source table by...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
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?

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.