blah blah blah is here! blah blah » Close

up0down
link

Hi,

Im writing an application that uses SQL Server 2005. I have two tables CLIENT and CLIENT_PURCHASES
The tables are joinned by the client_id field. I would like to delete a client but if a client has some purchases I'm receiving an exception

"The DELETE statement conflicted with the REFERENCE constraint "FK_CLIENT_CLIENT_PURCHASES". The conflict occurred in database "test", table "dbo.CLIENT", column 'client_id'.
The statement has been terminated."

Is there any way to catch this exception in order to show a message that this record cannot be deleted or check if this row can be deleted?

last answered 6 months ago

2 answers

up0down
link

yes there is but you should delete the purchases which i don't prefer. in order to make things better, make a column that contains an activity flag, like the client is active or not. so if its not active then you don't have to show it. you should avoid delete as much as you can in database in my opinion.

up0down
link

you have to delete client purchases where the client id is the one you are deleting. do this first then delete the client.

cypro21
30

Thanks for your reply. I think you misunderstand what I have said. I don't want to delete a record if that is used. The only thing that I need is to show a message that this record is being used and it cannot be deleted. Thanks again

Feedback