MSSQL에서 DELETE CASCADE 설정방법
2018. 1. 4. 15:37ㆍIT개발/Database
반응형
출처 : 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.
반응형
'IT개발 > Database' 카테고리의 다른 글
MSSQL 데이터 내보내기 오류( 엑셀 export 오류 발생 ) - 'Microsoft.ACE.OLEDB.12.0' 공급자는 로컬 컴퓨터에 등록할 수 없습니다. (System.Data) (0) | 2019.03.21 |
---|---|
Oracle -> Mssql 데이터 마이그레이션하기(SQL Server Migration Assistant For Oracle) (6) | 2018.04.06 |
MICROSOFT SQL SERVER MIGRATION ASSISTANT FOR ORACLE 사용시 오류사항 공유 (2) | 2018.03.20 |
피연산자 유형 충돌: varbinary은(는) text과(와) 호환되지 않습니다. (0) | 2018.01.09 |
[MSSQL] 날짜 형식 변환(날짜변환표) (0) | 2014.08.27 |