전체 문장이 커밋되지 않았습니다. 다음과 같이 쉽게 테스트 할 수 있습니다.
Create Table #Target (Id Int Primary Key)
Insert Into #Target Values(1)
Insert Into #Target Values(3)
Insert Into #Target Values(5)
Insert Into #Target Values(7)
Create Table #Source (Id Int)
Insert Into #Source Values(1)
Insert Into #Source Values(2)
Insert Into #Source Values(3)
Insert Into #Source Values(4)
Insert Into #Source Values(5)
Insert Into #Source Values(6)
Insert Into #Source Values(7)
Insert Into #Source Values(8)
Insert Into #Target(Id)
Select Id From #Source
Select * From #target
Drop Table #Target
Drop Table #Source
위의 코드는 기본 키가있는 대상 테이블을 만듭니다. 그런 다음 동일한 컬럼이지만 다른 값을 갖는 소스 테이블을 작성합니다. 그런 다음 소스 테이블에서 목표 테이블로 행을 삽입 할 때 게시 한 명령과 유사한 명령이 실행됩니다.
그러면 대상 테이블에서 선택합니다. 보시다시피 원래 값만 있습니다.
이 코드를 대신 사용하면 누락 된 행만 삽입됩니다.
Insert
Into #Target
Select #Source.*
From #Source
Left Join #Target
On #Source.Id = #Target.Id
Where #Target.Id Is NULL