Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Foreign Key Constraint error on Delete Statement

Status
Not open for further replies.

Work23

Technical User
Mar 8, 2005
94
US
Hello. I have these few Delete Statements below. I then get the server message below the code. Below the Server Message, I have listed the actual Foreign Key Constraint. Is there any way to actually Process the Delete Statements with the Foreign Key Constraint enabled? And, how would I do so programmatically? Please let me know your ideas. Thank you very much. Take care.


DELETE FROM HS_EVENT
WHERE HSE_ID <= (SELECT MAX(EVENTID)FROM FINALTABLEMERGE)

DELETE FROM HS_STRING_PARAMETER
WHERE HSPS_E_ID <=(SELECT MAX(EVENTID) FROM FINALTABLEMERGE)





Server: Msg 547, Level 16, State 1, Line 5
DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_HS_STRING_PARAMETER_HS_EVENT'. The conflict occurred in database 'STATS', table 'HS_STRING_PARAMETER', column 'HSPS_E_ID'.
The statement has been terminated.


"FK_HS_STRING_PARAMETER_HS_EVENT"
 
Reverse the order of your deletes. You have to delete from the HS_String_Parmeter table first.
 
I'm sorry, I'm a bit confused. Can you explain as to why I would have to do that? Bit confused on your logic. Thank you very much!
 
Becasue of the foreign key constratint yoiu have to delete from the foreign table(HS_String_Parmeter) first, then the primary table(HS_Event)

First:
DELETE FROM HS_STRING_PARAMETER
WHERE HSPS_E_ID <=(SELECT MAX(EVENTID) FROM FINALTABLEMERGE)

Second:
DELETE FROM HS_EVENT
WHERE HSE_ID <= (SELECT MAX(EVENTID)FROM FINALTABLEMERGE)
 
Thank you very much for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top