IT개발/Database
MSSQL에서 DELETE CASCADE 설정방법
딸바보아재
2018. 1. 4. 15:37
반응형
출처 : https://stackoverflow.com/questions/6260688/how-do-i-use-cascade-delete-with-sql-server
방법1.
You will need to,
- Drop the existing foreign key constraint,
- Add a new one with the
ON DELETE CASCADE
setting enabled.
Something like:
ALTER TABLE dbo.T2
DROP CONSTRAINT FK_T1_T2 -- or whatever it's called
ALTER TABLE dbo.T2
ADD CONSTRAINT FK_T1_T2_Cascade
FOREIGN KEY (EmployeeID) REFERENCES dbo.T1(EmployeeID) ON DELETE CASCADE
방법2.
To add "Cascade delete" to an existing foreign key in SQL Server Management Studio:
First, select your Foreign Key, and open it's "DROP and Create To.." in a new Query window.
Then, just add ON DELETE CASCADE
to the ADD CONSTRAINT
command:
And hit the "Execute" button to run this query.
방법3.
You can do this with SQL Server Management Studio.
→ Right click the table design and go to Relationships and choose the foreign key on the left-side pane and in the right-side pane, expand the menu "INSERT and UPDATE specification" and select "Cascade" as Delete Rule.
반응형