기본 콘텐츠로 건너뛰기

6월, 2016의 게시물 표시

[Microsoft][ODBC SQL Server Driver][SQL Server]Violation of PRIMARY KEY

[Microsoft][ODBC SQL Server Driver][SQL Server]Violation of PRIMARY KEY constraint 'PK_tLSvrNIC'. Cannot insert duplicate key in object 'dbo.tLSvrNIC'. Push Replication등을 사용하면 많이 발생하는 문제인데.. Slave DB를 Primary로 바꿀 경우 Identity값이 리셋되므로 다음 값을 넣으려고 하면 PK중복 에러가 발생한다. 강제적으로 마지막 값다음 값부터 시작을 시키려면 아래와 같이 넣어주면 된다. tLSvrNIC이란 테이블의 마지막 값 다음부터 identity를 설정한다. 물론 이 쿼리를 날리기 전에 PK를 삭제하고 아래 쿼리를 실행 한 뒤에 다시 PK를 생성하는 순서대로 해야 한다. declare @stpoint bigint select @stpoint = COUNT(1) + 1 from tLSvrNIC DBCC CHECKIDENT('tLSvrNIC', RESEED, @stpoint) Free Infrastructure automation & management tool Global Infrastructure Integration Platform http://giip.littleworld.net  Subscribe and publish your links as a book with friends My Favorite Link Share http://link.littleworld.net