(4.48)sql server添加列并使用默认值填充已有记录

【1】问题:当我们在已经有数据行的表上面添加带默认值的新列时,现存数据行新列值为null 而不是默认值

(1)原表 =》添加列后

alter table test103 add phone varchar(15) default ''

           =》      

(2)新增行默认值可以出现

insert into test103(num1) values(100)

  

 

 

【2】解决 在alter table 后面加上 with values

(1)添加 Int 列

alter table test103 add [外观] int default 0  WITH VALUES;

  

 

 (2)添加 varchar 列

alter table test103 add new varchar(15) default '' WITH VALUES;

   

 

 

  

 

posted @ 2020-09-01 14:15  郭大侠1  阅读(633)  评论(0编辑  收藏  举报