은 매우 일반적입니다.
IDENTITY_INSERT에는 세션 범위가 있으므로 세션 만 ID 행에 명시 적으로 삽입 할 수 있습니다. 세션의 한 테이블 만 IDENTITY_INSERT를 (를) 한 번에 사용할 수 있습니다.
그럼 성능은 어떻습니까? 나는 실제로 당신에게 대답을하지는 않지만, 당신에게 대답을 줄 수있는 몇 가지 코드가 있습니다.
/* Create a table with an identity value */
CREATE TABLE test_table
(
auto_id INT IDENTITY(1, 1),
somedata VARCHAR(50)
)
GO
/* Insert 10 sample rows */
INSERT INTO test_table
SELECT 'x'
GO 10
/* Get the current identity value (10) */
SELECT Ident_current('test_table') AS IdentityValueAfterTenInserts
GO
/* Disable the identity column, insert a row, enable the identity column. */
SET identity_insert test_table ON
INSERT INTO test_table(auto_id, somedata)
SELECT 50, 'x'
SET identity_insert test_table OFF
GO
/* Get the current identity value (50) */
SELECT Ident_current('test_table') AS IdentityValueAfterIdentityInsertWithIdentityEnabled
GO
/* Disable the identity column, insert a row, check the value, then enable the identity column. */
SET identity_insert test_table ON
INSERT INTO test_table(auto_id, somedata)
SELECT 100, 'x'
/*
Get the current identity value (?)
If the value is 50, then the identity column is only recalculated when a call is made to:
SET identity_insert test_table OFF
Else if the value is 100, then the identity column is recalculated constantly and your
performance problems remain.
*/
SELECT Ident_current('test_table') AS IdentityValueAfterIdentityInsertWithIdentityDisabled
SET identity_insert test_table OFF
GO
/* Get the current identity value (100) */
SELECT Ident_current('test_table') AS IdentityValueAfterIdentityInsertWithIdentityEnabled
GO
DROP TABLE test_table
내가 이것을 실행할 수있는 편리한 SQL Server를, 그래서 내가 어떻게되는지 알려하지 않습니다 내가 here을 발견 무언가의 수정 된 버전입니다. 희망이 도움이됩니다.
신원을 없애기 위해 열을 변경할 수없는 경우 정확히 동일한 열은 있지만 신원이없는 두 번째 테이블을 작성한 다음 기존 데이터를 모두 삽입 한 다음 이전 데이터를 삭제하십시오. 이 모든 것은 코드 조각에 의해 자동으로 수행 될 수도 있습니다. – Krumelur
Microsoft SQLServer를 사용하고있는 것으로 보입니다. 그 맞습니까? –
@jon_darkstar, 맞습니다. :) @Krumelur, 마이 그 레이션 된 데이터에 대한 ID가 필요하기 때문에 테이블에 의해 생성되는 것을 원하지 않습니다. – thomaux