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

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

    First create a table with name student:

    CREATE TABLE STUDENT (STUDENT_ID INT NOT NULL)
    

    Add one column to it:

    ALTER TABLE STUDENT 
    ADD STUDENT_NAME INT NOT NULL DEFAULT(0)
    
    SELECT * 
    FROM STUDENT
    

    The table is created and a column is added to an existing table with a default value.

提交回复
热议问题