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

后端 未结 30 2593
轮回少年
轮回少年 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:22

    Add a new column to a table:

    ALTER TABLE [table]
    ADD Column1 Datatype
    

    For example,

    ALTER TABLE [test]
    ADD ID Int
    

    If the user wants to make it auto incremented then:

    ALTER TABLE [test]
    ADD ID Int IDENTITY(1,1) NOT NULL
    

提交回复
热议问题