¾È±Ô °øºÎ¹æ

MS-SQL > ±âÁ¸ Ä÷³À» IDENTITY ¼Ó¼ºÀ¸·Î º¯°æÇϱâ

µî·ÏÀÏ : 2019-09-04 19:47 Á¶È¸¼ö : 52,528

CREATE TABLE DBO.TMP_TBL1(
COL1 INT NOT NULL IDENTITY (1, 1),
COL2 DATETIME NULL)
ON [PRIMARY]
 
GO
 
ALTER TABLE DBO.TMP_TBL1 SET (LOCK_ESCALATION = TABLE)
 
GO
 
SET IDENTITY_INSERT DBO.TMP_TBL1 ON
 
GO
 
IF EXISTS(SELECT * FROM DBO.TBL1)
        EXEC('INSERT INTO DBO.TMP_TBL1 (COL1, COL2)
        SELECT COL1, COL2 FROM DBO.TBL1 WITH (HOLDLOCK TABLOCKX)')
 
GO
 
SET IDENTITY_INSERT DBO.TMP_TBL1 OFF
 
GO
 
DROP TABLE DBO.TBL1
 
GO
 
EXECUTE SP_RENAME N'DBO.TMP_TBL1', N'TBL1', 'OBJECT'


±âÁ¸¿¡ µ¥ÀÌÅÍ°¡ µé¾î°¡ ÀÖ´Â identity Ä®·³À» Äõ¸®¸¦ ÅëÇØ (Alter Table) ¹Ù·Î ¼Ó¼ºÀ» º¯°æÇÏ´Â ¹æ¹ýÀº ¾ø½À´Ï´Ù.

¾Æ·¡¿Í °°Àº ¹æ½ÄÀ¸·Î °¡´ÉÇÕ´Ï´Ù.

1.Tmp_TBL1À» ¸¸µé°í
2.TBL1ÀÇ µ¥ÀÌÅ͸¦ Tmp_TBL1¿¡ ºÎ¾î ³ÖÀº ´ÙÀ½
3.±âÁ¸ TBL1Àº DROP ÇÏ°í
4.Tmp_TBL1ÀÇ À̸§À» ¼öÁ¤ÇÏ´Â °ÍÀ̾ú½À´Ï´Ù.


 
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.