Add a column with a default value to an existing table in SQL Server

后端 未结 30 2624
轮回少年
轮回少年 2020-11-22 12:00

How can I add a column with a default value to an existing table in SQL Server 2000 / SQL Server 2005?

30条回答
  •  日久生厌
    2020-11-22 12:04

    ALTER TABLE Protocols
    ADD ProtocolTypeID int NOT NULL DEFAULT(1)
    GO
    

    The inclusion of the DEFAULT fills the column in existing rows with the default value, so the NOT NULL constraint is not violated.

提交回复
热议问题