473,769 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with delete trigger

I have a table, SecurityMasterU nderlying, 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
SecurityMasterU nderlying.
* 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 [SecurityMasterU nderlying] (
[Symbol] VARCHAR(15) NOT NULL,
[Identity] VARCHAR(15) NOT NULL,
[UnderlyingSymbo l] VARCHAR(15) NOT NULL,
[UnderlyingIdent ity] VARCHAR(15) NOT NULL,
[Shares] INT NOT NULL
) ON [PRIMARY]
GO

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

ALTER TABLE [dbo].[SecurityMasterU nderlying]
ADD
CONSTRAINT [FK_SMUnderlying _SM] FOREIGN KEY (
[Symbol], [Identity]
)
REFERENCES [dbo].[SecurityMaster] (
[Symbol], [Identity]
) ON DELETE CASCADE
ALTER TABLE [dbo].[SecurityMasterU nderlying]
ADD
CONSTRAINT [FK_SMUnderlying 2_SM] FOREIGN KEY (
[UnderlyingSymbo l], [UnderlyingIdent ity]
)
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 SecurityMasterU nderlying VALUES ('DIAXL', '7635TRS',
'DIA', '654FE32', 100)
Jul 20 '05 #1
0 2239

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

Similar topics

2
11800
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 2 Gig. When I delete data from the database, it takes a lot of system resources and monopolizes the database so that all other query requests are slow as mud! Ideally, I would like to be able to issue delete commands to the database on a...
8
8614
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 the primary exchange for that symbol. Each symbol can only have one primary exchange. I am trying to write a insert/update/delete trigger that enforces this rule. The rules I have thought of are as follows: Insert If new row has flag...
1
2004
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 the SP will be finished ASAP, that's why, I do not want, and I do not need to wait for a trigger.
4
1537
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 triggers on TOrigto insert into TAudit in case of insert, update & delete. TOrig contains text column. So i created instead of Trigger like: Create TRIGGER TrigDelete ON dbo.TOrig
6
25001
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 following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. My trigger : CREATE TRIGGER ON . FOR DELETE
15
2581
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 determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the same messages because each thread gets the recors then sends the message. I need somehow to prevent...
4
2359
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 data insert into table moto_pvs_pulse_daily_yield_tmp, my program will checking and copy the data by each row and insert into table mt_pulse_daily_yield_tmp which is in other instance. After I success insert into table mt_pulse_daily_yield_tmp, I...
11
7879
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' does not exist drop table log_errors_tab;
11
4079
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, CrtdUser and Date And Edit and Delete buttons
3
1654
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 creating the following TRIGGER:
0
9590
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9424
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10000
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.