Solution for DELETE SQL

There is a table called a man. which has personid and contactid.

If the person is deleted, then I want to remove the person from db, as well as the contacts associated with him for that person.

Are you better off doing the DELETES routine in the ONE Store or is my business layer calling pContactDelete first and then calling pPersonDelete ???????

thanks niall

+5
source share
5 answers

Assuming you are using MS SQL Server:

You should probably use one ON DELETE CASCADEfor your foreign key.

ALTER TABLE Contact
ADD CONSTRAINT FK_PersonContact FOREIGN KEY (PersonId)
REFERENCES Person(PersonId) ON DELETE CASCADE

This will delete the contact line when deleting the user line. This is a limitation that always runs in the database.

SQL Management Studio " ", " INSERT UPDATE", " " → " ".

, Contact -, .

+12

+1

, , . , . , , , , , .

+1

Oracle, .

  • PERSON CONTACT .

  • ON DELETE . .., , - .

.

+1

, . . . Business, -

0

All Articles