Alter table query to change identity column from int to bigint in sql2019 server

  • Alter table query to change identity column from int to bigint in sql2019 server

  • sachinleo78 wrote:

    Alter table query to change identity column from int to bigint in sql2019 server

    What is your question?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • have a large Table having Identity column as Int and value has neared the max value so need to make the identity column as BigInt

     

  • Is it so difficult for you to ask a question?

    Can anyone provide the T-SQL code I need to amend an identity column from INT to BIGINT, please?

    I am guessing that this is what you are asking. If not, what are you hoping for?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Yes

  • DROP TABLE IF EXISTS #SomeData;

    CREATE TABLE #SomeData
    (
    SomeId INT IDENTITY(1, 1)
    ,SomeText VARCHAR(10)
    ,CONSTRAINT PK_Nonsense
    PRIMARY KEY CLUSTERED(SomeId)
    );

    ALTER TABLE #SomeData DROP CONSTRAINT IF EXISTS PK_Nonsense;

    ALTER TABLE #SomeData ALTER COLUMN SomeId BIGINT;

    ALTER TABLE #SomeData ADD CONSTRAINT PK_Nonsense PRIMARY KEY(SomeId);

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Thanks Phil

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply