注册 登录
编程论坛 SQL Server论坛

关于添加默认值的问题!

power6d 发布于 2007-01-18 09:53, 1803 次点击
假设有个表中有个字段的数据类型是这样的Numeric(12,2),在建时忘给它设默认值了,现在表开始用了,里面有数据了,我想用SQL语言将默认值给添上去,请问怎么写?
9 回复
#2
Kendy1234562007-01-18 17:33

把表数据里面的NULL值都先update成你的默认值
再去表的设计界面修改默认值设置

#3
power6d2007-01-19 08:35
我想用SQL语言改
#4
棉花糖ONE2007-01-19 10:23
create default aa as 默认值
go
sp_bindefault aa, '表名.列名'
(aa是个标志,你可以随便改)
#5
chenxkfox2007-01-19 16:25


declare @t table
(
id int primary key,
c2 decimal(18,2)
)
declare @i int
set @i=1
while (@i<5)
begin
insert into @t(id) values(@i)
set @i=@i+1
end
insert into @t values(5,8.88)
select * from @t
update @t set c2=9.99 where c2 is null
select * from @t

#6
power6d2007-01-24 09:26
加是加上去了,但跟我想要的还是有点不一样,因为,加上去后就不能Drop Default了。我就想对某列加个默认值,能不能不用绑定,直接对一个列补加默认值。

[此贴子已经被作者于2007-1-24 9:27:18编辑过]


#7
bygg2007-01-24 09:51
在设计里面弄吧...
#8
power6d2007-01-24 11:34
什么设计?
#9
bygg2007-01-24 13:00
忘了你是用代码实现,呵.
#10
power6d2007-01-25 08:43
没办法了吗? 难道只能用企业管理器吗?
1