alter column with default value

This question already has an answer here:

  • Add a column with a default value to an existing table in SQL Server 36 answers
  • Alter column, add default constraint 4 answers

  • ALTER TABLE查询为拒绝登录添加默认值0


    If you want to affect existing rows, then use with values :

    alter table enquiry
        add constraint dft_enquiry_rejectreason default 0 with values;
    

    This is explained in the documentation:

    . . . WITH VALUES can be used to store the default value in the new column for each existing row in the table.


    Use ADD CONSTRAINT like

    ALTER TABLE enquiry ADD CONSTRAINT some_name DEFAULT 0 FOR RejectReson;

    链接地址: http://www.djcxy.com/p/24704.html

    上一篇: 如何为现有列设置默认值

    下一篇: 使用默认值更改列