求SQL语句: 添加int型新列 默认值为0,并修改已有数据为默认值0 如题!求解!谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ALTER TABLE dbo.tbname ADD columnname int NULL DEFAULT 0 GO update tbname set columnname=0 已有数据是指 之前表中存储的。添加这个列后,该列值为默认值表Tid name 1 wang变为表T1id name age1 wang 0 alter table aa add 列名 int default 0 update aa set 列名=0 有没有一句话搞定的啊?哈哈 我也想到了你的办法!我google到这么一句话alter table table_name add column_name nvarchar(20) default ('') with values 1.with values用于修改已有记录。 但是看不懂! create table tb(id int,col int)insert into tb select 1,3 union all select 2,6goalter table tb add col1 int not null default 0goselect * from tb /*id col col1----------- ----------- -----------1 3 02 6 0(2 行受影响)*/godrop table tb 嗯 是的!加个not null 确实能搞定!嘎嘎!谢谢! mssql查询问题 如何取一个变量的后两位 升级到SQL server 2005,发现个问题? 在线求助关于SqlServer2005的数据库连接问题 获取【日期段】的问题! SQL 分区 急!!在线等!高分诚心求助各位sql精英,一条sql汇总语句该如何写,有点难度,功力好的请进! 根据时间删除数据的问题 关于sql server2000附加时的错误 如何建,把2007年6月份的每一个日期,插入到表A的字段AA中? 关于SQL语句中where子句真假值判断 8点做了备份,10点故障,那么这两个小时的数据丢失有没有专业术语啊?
columnname int NULL DEFAULT 0
GO
id name
1 wang
变为
表T1
id name age
1 wang 0
update aa set 列名=0
哈哈 我也想到了你的办法!
我google到这么一句话alter table table_name add column_name nvarchar(20) default ('') with values 1.with values用于修改已有记录。 但是看不懂!
insert into tb select 1,3 union all select 2,6
go
alter table tb add col1 int not null default 0
go
select * from tb
/*
id col col1
----------- ----------- -----------
1 3 0
2 6 0(2 行受影响)
*/
go
drop table tb
嗯 是的!加个not null 确实能搞定!
嘎嘎!谢谢!