Advertisement

02.23.2008 at 03:41PM PST, ID: 23187729
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Trigger not firing on cascade delete table

Tags: TSQL, Microsoft SQL Server 2000
Hi,

I have three tables:
BulkMemberHeader - which has a cascade delete on BulkMemberDetail of any related records
BulkMemberDetail  which has a DELETE trigger which gets the member ID from deleted and deletes the member record from the member table
Member

This issue:
> When I delete a record from BulkMemberDetail the trigger fires and deletes the record from the Member table as it should, but....
> If I delete a record from the BulkMemberHeader, all corresponding records in BulkMemberDetail are deleted, but the trigger to delete the record in the Member table does not seem to fire

Is it a limitation on SQLServer 2000 that does not allow triggers to fire in a scenario like this?

Any suggestions or comments would be great.

Thanks,
Mike
Start your free trial to view this solution
Question Stats
Zone: Microsoft
Question Asked By: valon76
Solution Provided By: valon76
Participating Experts: 4
Solution Grade: B
Views: 65
Translate:
Loading Advertisement...
02.23.2008 at 04:06PM PST, ID: 20967444

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.23.2008 at 04:32PM PST, ID: 20967552

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.23.2008 at 07:43PM PST, ID: 20968352

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.23.2008 at 09:01PM PST, ID: 20968722

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.23.2008 at 10:20PM PST, ID: 20968949

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.23.2008 at 11:19PM PST, ID: 20969085

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.25.2008 at 01:21AM PST, ID: 20973826

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.25.2008 at 08:59PM PST, ID: 20981732

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.01.2008 at 10:00PM PST, ID: 21025126

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.02.2008 at 11:16AM PST, ID: 21027086

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.03.2008 at 11:57AM PST, ID: 21035026

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.03.2008 at 12:09PM PST, ID: 21035124

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.03.2008 at 01:51PM PST, ID: 21036082

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.03.2008 at 01:54PM PST, ID: 21036110

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
02.23.2008 at 04:06PM PST, ID: 20967444

Rank: Genius

There is no such limitation...it is likley the manner in which the trigger is written.  Post that code.
 
02.23.2008 at 04:32PM PST, ID: 20967552
Here is the whole trigger - I don't think the only part that is important is the last part of the IF statement - but I am posting it all just in case.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
ALTER TRIGGER mwtrig_tblBulkUpload
ON	tblBulkUpload
FOR INSERT, UPDATE, DELETE
AS
DECLARE	@BulkUploadID		INT,
		@BulkUploadBatchID	INT,
		@EnglishName		VARCHAR( 200 ),		-- tblMember
		@NonEnglishName		NVARCHAR( 200 ),
		@OfficeName			VARCHAR( 500 ),		-- tblMemberLocation
		@StreetAddress		VARCHAR( 200 ),
		@ChineseStreetAddress	NVARCHAR( 200 ),
		@Country			VARCHAR( 200 ),		-- tblLocation
		@Region				VARCHAR( 200 ),
		@City				VARCHAR( 200 ),
		@Zip				VARCHAR( 50 ),		-- tblMemberLocation
		@Email				VARCHAR( 200 ),		-- tblMemberInternetInfo
		@Phone				VARCHAR( 200 ),
		@Description		VARCHAR( 5000 ),	-- tblMember
		@Classification		VARCHAR( 200 ),		-- tblMemberClassification
		@LastUpdateDate		SMALLDATETIME,
		@WhoID				INT,
		@Inserted			BIT,
		@InsertComment		VARCHAR( 8000 ),
		@LocationID			INT,
		@ClassificationID	INT,
		@CompanyID	INT
 
 
IF EXISTS( SELECT BulkUploadID FROM INSERTED )
	BEGIN
 
		SELECT	@BulkUploadID	=	BulkUploadID,
				@BulkUploadBatchID	=	BulkUploadBatchID,
				@EnglishName	=	EnglishName,
				@NonEnglishName	=	NonEnglishName,
				@OfficeName	=	OfficeName,
				@StreetAddress	=	StreetAddress,
				@ChineseStreetAddress	=	ChineseStreetAddress,
				@Country	=	Country,
				@Region	=	Region,
				@City	=	City,
				@Zip	=	Zip,
				@Email	=	Email,
				@Phone	=	Phone,
				@Description	=	Description,
				@Classification	=	Classification,
				@LastUpdateDate	=	LastUpdateDate,
				@WhoID	=	WhoID,
				@Inserted	=	Inserted,
				@InsertComment	= 'Please have a look at this record',		-- used for validation
				@LocationID = dbo.mwfn_getLocationID( Country, Region, City ),
				@ClassificationID = dbo.mwfn_getClassificationID( Classification ),
				@CompanyID = 0		-- will get id if successful insert
 
		FROM	INSERTED
 
		-- location
		IF @LocationID = 0
			BEGIN
				SET @InsertComment = 'Unable to determine location'
			END
 
		-- classification
		SELECT	ID, Value, RelID
		INTO	#ParsedTable
		FROM	dbo.mwfn_getClassificationInsertTable( @Classification )
 
		-- count classification records that couldn't be resolved
		DECLARE @CountClassificationZeros INT
		SELECT @CountClassificationZeros = COUNT( ID ) FROM #ParsedTable WHERE RelID = 0
 
 
		IF @CountClassificationZeros > 0
			BEGIN
				SET @InsertComment = 'Unable to determine classification'
			END
 
		-- get ready for insert
		IF @CountClassificationZeros = 0 AND @LocationID > 0
			BEGIN
				SET @InsertComment	= 'Inserting...'		
 
				--	INSERT COMPANY:
				EXEC mwsp_insertMemberForBulkUpload
					1,	-- typeID: company(1)
					@WhoID,	-- this is parent ID... not sure why we are using a user's ID
					'- none -',
					7,	--  EnglishPrefixID(7)
					'',	--	FirstName (company doesn't have one)
					@EnglishName,
					@NonEnglishName,
					6,	-- Chinese Suffix ID
					@WhoID,
					@CompanyID OUT
						
				--	INSERT PHONE NUMBER:
				DECLARE @Token AS VARCHAR( 8000 )
				SET @Token = @Phone
				DECLARE @Temp  AS VARCHAR(50)
 
				WHILE LEN( @Token ) > 0
					BEGIN
					   IF CHARINDEX('|', @Token) = 0
						  BEGIN
							SET @TEMP =@Token
							SET @Token = ''
 
							-- insert value
							EXEC mwsp_insertMemberContactNumber
								@CompanyID,
								7,	-- Business Phone 1 (id:7)
								@TEMP,
								@WhoID
						  END
					ELSE
					  BEGIN
						SET @Temp = LEFT( @Token, CHARINDEX( '|', @Token )-1 )
						
						-- insert value
						EXEC mwsp_insertMemberContactNumber
							@CompanyID,
							7,	-- Business Phone 1 (id:7)
							@TEMP,
							@WhoID
 
						SET @Token = RIGHT(@Token, LEN(@Token)-LEN(@Temp)-1)
				   END
				END
 
 
				--	EMAIL ADDRESS
				SET @Token = @Email
 
				WHILE LEN( @Token ) > 0
					BEGIN
					  IF CHARINDEX('|', @Token) = 0
					  BEGIN
						SET @TEMP =@Token
						SET @Token = ''
 
						-- insert value
						EXEC mwsp_insertMemberInternetInfo
							@CompanyID,
							1, -- InternetInfoTypeID Email( 1 )
							@TEMP,
							@WhoID
					  END
					ELSE
					  BEGIN
						SET @Temp = LEFT( @Token, CHARINDEX( '|', @Token )-1 )
						
						-- insert value
						EXEC mwsp_insertMemberInternetInfo
							@CompanyID,
							1, -- InternetInfoTypeID Email( 1 )
							@TEMP,
							@WhoID
 
						SET @Token = RIGHT(@Token, LEN(@Token)-LEN(@Temp)-1)
					  END
					END
 
				--	INSERT CLASSIFICATION REL
				DECLARE		@RelID INT
				DECLARE cur_CwClassification	CURSOR LOCAL FORWARD_ONLY STATIC
					FOR (	SELECT 	RelID
							FROM	#ParsedTable	)
				OPEN 	cur_CwClassification
				FETCH 	cur_CwClassification
				INTO 	@RelID
 
				WHILE @@FETCH_STATUS = 0
				BEGIN
					-- insert into classification
					EXEC mwsp_insertMemberClassificationRel @CompanyID, @RelID, @WhoID
 
					FETCH 	cur_CwClassification
					INTO 	@RelID
				END
				CLOSE 	cur_CwClassification
				DEALLOCATE cur_CwClassification
 
				--	INSERT LOCATION
				EXEC mwsp_insertMemberLocationForBulkUpload
					@CompanyID,
					@OfficeName,
					@StreetAddress,
					'',	-- street address 2
					@ChineseStreetAddress,
					@LocationID,
					1,	-- @MainAddressBool_6 	[bit],
					@Zip,
					@WhoID
 
				SET @Inserted = 1
				SET	@InsertComment = 'Successful insert!'
			END
 
		-- update the Bulk Upload File
		EXEC mwsp_updateBulkUpload
			@BulkUploadID,
			@BulkUploadBatchID,
			@EnglishName,
			@NonEnglishName,
			@OfficeName,
			@StreetAddress,
			@ChineseStreetAddress,
			@Country,
			@Region,
			@City,
			@Zip,
			@Email,
			@Phone,
			@Description,
			@Classification,
			@WhoID,
			@Inserted,
			@InsertComment,
			@CompanyID
	END
ELSE
	BEGIN
		DECLARE @CompID	INT
		SELECT @CompID = ISNULL( d.MemberID, 0 )
		FROM	DELETED d
 
		IF @CompID > 0
			BEGIN
				EXEC jcDeleteMember @CompID
			END
	END
GO
Open in New Window
 
02.23.2008 at 07:43PM PST, ID: 20968352

Rank: Genius

Your trigger assumes that there will always be only one record affected at any one time...is that correct?
 
02.23.2008 at 09:01PM PST, ID: 20968722
Hi Chapmandew,

Im not sure if I understand your comment correctly  they are inserted one at a time, but when I delete them, I delete the header which cascade deletes the related records in the details table& is that the issue?  Are they deleted all at once and not individually?  Im not sure how MSSQL does it.

Just for clarity: The details table (tblBulkUpload) has the trigger.  If I do the following the trigger WILL fire:
---------------------------------
DELETE tblBulkUpload
WHERE BulkUploadID = @WhateverID
----------------------------------

If I do the following the trigger does not fire but the details records are deleted:
----------------------------------
DELETE      tblBulkUploadBatch
WHERE      BulkUploadBatchID = @WhateverID
----------------------------------

I have attached the table script for your reference.

Mike
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
CREATE TABLE tblBulkUploadBatch
(
	BulkUploadBatchID	INT PRIMARY KEY IDENTITY( 1, 1 ),
	Guid				UNIQUEIDENTIFIER DEFAULT( NEWID() ),
	Name				NVARCHAR( 400 ),	-- used to name the bulk upload
	WhoID				INT,	-- who did the initial upload
	UploadDate			SMALLDATETIME DEFAULT( GETDATE() ),
	FOREIGN KEY( WhoID )	REFERENCES tblMember( ID ) ON DELETE CASCADE
)
GO
 
CREATE TABLE tblBulkUpload
(
	BulkUploadID		INT PRIMARY KEY IDENTITY( 1, 1 ),
	BulkUploadBatchID	INT,
	EnglishName			VARCHAR( 200 ),		-- tblMember
	NonEnglishName		NVARCHAR( 200 ),
	OfficeName			VARCHAR( 500 ),		-- tblMemberLocation
	StreetAddress		VARCHAR( 200 ),
	ChineseStreetAddress	NVARCHAR( 200 ),
	Country				VARCHAR( 200 ),		-- tblLocation
	Region				VARCHAR( 200 ),
	City				VARCHAR( 200 ),
	Zip					VARCHAR( 50 ),		-- tblMemberLocation
	Email				VARCHAR( 200 ),		-- tblMemberInternetInfo
	Phone				VARCHAR( 200 ),
	Description			VARCHAR( 500 ),		-- tblMember ( should be 5K but row size is exceeded )
	Classification		VARCHAR( 200 ),		-- tblMemberClassification
	LastUpdateDate		SMALLDATETIME DEFAULT( GETDATE() ),
	WhoID				INT,
	Inserted			BIT DEFAULT( 0 ),
	InsertComment		VARCHAR( 1000 ) DEFAULT( 'No attempt yet... please refresh in 10 seconds' ),
	MemberID			INT NULL,	-- is populated with the memberId after an insert is completed
	FOREIGN KEY( BulkUploadBatchID )	REFERENCES tblBulkUploadBatch( BulkUploadBatchID ) ON DELETE CASCADE,
	FOREIGN KEY( WhoID )	REFERENCES tblMember( ID )
)
Open in New Window
 
02.23.2008 at 10:20PM PST, ID: 20968949

Rank: Genius

Ok, the reason for the comment was that the trigger will not work correctly in the case that more than one record is modified at a time.  It is getting late for me now, but I will for sure work on this tomorrow for you.
 
02.23.2008 at 11:19PM PST, ID: 20969085

Rank: Master

I believe ur trigger should be on the details table rather than the header table. Header table already has ON DELETE CASCADE, so if u delete a header record, all its children record will be automatically deleted. But if u delete a child record, then u want to delele all its siblings and the parent too right. Just a thought ...
 
02.25.2008 at 01:21AM PST, ID: 20973826
Hi valon,
       I have tried one example similr to your scenario and it seems working pretty fine.
i will mention the scenario down, check if its same with ur case, if not change the place where it is diff from mine and chk it out.
I craeted a header table

id      HeadName
1      Hd1
2      Hd2
3      Hd3
5      Hd5

details table
HDid      id      DtlName
1      101      Dtl 11
1      102      Dtl 12
1      103      Dtl 13
2      101      Dtl 21
2      102      Dtl 22
3      101      Dtl 31
3      102      Dtl 32

member table
Memid      MemName
102      Mem 102
103      Mem 103
104      Mem 104
105      Mem 105

what i ve done is i ve created the hedaer table id its primary key.
In details table HDid + id will be the primary key with the foreign key to the header table and delete cascade. So when ever i delete a record in the headeer, all the corresponding details record will be deleted. So far fine.
Now i created a trigger in the detail table which will be fired when i tryt o delete any record in the detail and will delet the corresponding member record.
this is my trigger
create trigger tr_DelMem on details
for delete
as begin
      declare @ID int

      select @ID = id from deleted
      print @ID
      delete from member where Memid = @ID
end

This perfectly working fine for me. Please check teh place where you are getting issues.
 
02.25.2008 at 08:59PM PST, ID: 20981732
Thanks for your suggestions, but I was unable to get the trigger to fire, so I had to do a work-around by adding a cursor to my delete proc... in case you are interested I have included the code.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
ALTER PROC dbo.mwsp_deleteBulkUploadBatch
	@BulkUploadBatchID	INT
AS
 
-- get a list of all successful inserts and delete them
DECLARE		@MemberID INT
DECLARE cur_SuccessfulInserts	CURSOR LOCAL FORWARD_ONLY STATIC
	FOR (	SELECT 	MemberID
			FROM	tblBulkUpload
			WHERE	BulkUploadBatchID = @BulkUploadBatchID
			  AND	ISNULL( MemberID, 0 ) >	0 )
OPEN 	cur_SuccessfulInserts
FETCH 	cur_SuccessfulInserts
INTO 	@MemberID
 
WHILE @@FETCH_STATUS = 0
BEGIN
	-- delete it since the cascade delete does not work
	EXEC jcDeleteMember @MemberID
 
	FETCH 	cur_SuccessfulInserts
	INTO 	@MemberID
END
CLOSE 	cur_SuccessfulInserts
DEALLOCATE cur_SuccessfulInserts
 
 
-- Delete batch header
DELETE	tblBulkUploadBatch
WHERE	BulkUploadBatchID = @BulkUploadBatchID
GO
Open in New Window
Accepted Solution
 
03.01.2008 at 10:00PM PST, ID: 21025126

Rank: Genius

I can't imagine that you didn't recieve any help on this question post....
 
03.02.2008 at 11:16AM PST, ID: 21027086
A request has been made in Community Support to close this question:
http://www.experts-exchange.com/Q_23207121.html

If there are no objections, a moderator will finalize this question in approximately 4 days as follows:
PAQ with refund using {http:#a20981732}

Please leave any recommendations here.

kb
Experts Exchange Moderator
 
03.03.2008 at 11:57AM PST, ID: 21035026
Chapmandew,

I am not sure what you mean by your last comment  are you saying that I should have rewarded someone for providing me a solution?  If so, which solution?

Mike
 
03.03.2008 at 12:09PM PST, ID: 21035124

Rank: Genius

I am just curious...did any of the posts that anyone on here help you at all?  If so, you should reward them points....even if it is not the whole amount.  I'm not talking just about my posts, but I would think that you did receive help here.
 
03.03.2008 at 01:51PM PST, ID: 21036082
I think things must have changed somewhat since last time I used EE... should I be awarding points for anyone that posts a comment to show that I appreciate them reading and considering my issue, or for those who give advice that leads to a solution?  The issue was not resolved, and I used my own workaround.

I am open to any suggestions of comments you feel deserve points, but please tell me which ones and why.

I really would like to know for future posts, perhaps the moderator could respond and clarify this for me.

Thanks
 
03.03.2008 at 01:54PM PST, ID: 21036110

Rank: Genius

No, not at all.  Only when you receive help.  If I didn't help you then that is OK, I was just curious.  No worries either way.  

Have a good one,
Tim
 
 
03.06.2008 at 09:21AM PST, ID: 21062565
Closed, 125 points refunded.
Lunchy
Friendly Neighbourhood Community Support Moderator
 
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628