Share via

alter column

Surendra Adhikari 211 Reputation points
2022-10-15T16:33:23.037+00:00

alter column in large table takes lot of time and sometimes does not complete(needs restart of server). Please help me by informing which data type conversions execute instantly and which conversions take time.

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories

0 comments No comments

Answer accepted by question author

  1. Erland Sommarskog 134.1K Reputation points MVP Volunteer Moderator
    2022-10-15T22:01:11.717+00:00

    There are three levels of ALTER TABLE ALTER COLUMN:

    1. Pure metadata change.
    2. Metadata change, but needs to be validated.
    3. Table has to be rebuilt entirely.

    Pure metadata changes are when you are making a varchar, nvarchar or varbinary column longer.

    But if you change to a datatype with a different format or size, the table has to be rebuild. For instance int to bigint requires the table to be rebuilt. Same goes for changing from char(4) to char(6).

    The middle ground, when validation is required is when you change a column from permitting NULL to be NOT NULL. Validation is also required when you make a varchar, nvarchar or varbinary column shorter. The validation is required to make sure that there no values that violate the new definition.

    Was this answer helpful?

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.