none
T-SQL Reference FAQ: Bagaimana cara memasukkan nilai ke dalam atau mengatur ulang nilai identitas kolom?

    General discussion

  • Kita kita mengeset  property IDENTITY_INSERT menjadi ON untuk memasukkan nilai pada identity column.

     

    <div style="BORDER-BOTTOM: windowtext 1pt solid; BORDER- PADDING-BOTTOM: 1pt; PADDING- WIDTH: 600px; PADDING-RIGHT: 4pt; MARGIN- BORDER- BORDER-RIGHT: windowtext 1pt solid; PADDING->

    SET IDENTITY_INSERT dbo.Test ON

    GO

    INSERT INTO dbo.Test (IdentityID, TestName) VALUES (1, 'Name1')

    GO

    SET IDENTITY_INSERT dbo.Test OFF

    GO

    </div>

     

    Kita bisa mereset identity value dengan DBCC CHECKIDENT.

     

    <div style="BORDER-BOTTOM: windowtext 1pt solid; BORDER- PADDING-BOTTOM: 1pt; PADDING- WIDTH: 600px; PADDING-RIGHT: 4pt; MARGIN- BORDER- BORDER-RIGHT: windowtext 1pt solid; PADDING->

    DBCC CHECKIDENT ("Test");

    </div>

     

    Dokumen terkait:

      

    SET IDENTITY_INSERT (Transact-SQL)

    http://msdn.microsoft.com/en-us/library/ms188059.aspx

      

    DBCC CHECKIDENT (Transact-SQL)

    http://msdn.microsoft.com/en-us/library/ms176057.aspx


    Agnes Sannie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 30, 2012 5:59 AM