34,575
社区成员
发帖
与我相关
我的任务
分享
ALTER TABLE #temp add @i numeric(18,2) null
declare @sql nvarchar(200)
set @sql='ALTER TABLE #temp ADD ['+rtrim(@i)+'] numeric(18,2) null'
exec(@sql)
EXEC(N'ALTER TABLE #temp add ' + @i + ' numeric(18,2) null')
create table tb(col int)
insert tb
select 1
select * from tb
/*
col
-----------
1
*/
alter table tb add col2 as col*2 --默认值
insert tb(col)
select 2
select * from tb
/*
col col2
----------- -----------
1 3
2 4
*/
drop table tb
create table tb(col int)
insert tb
select 1
select * from tb
/*
col
-----------
1
*/
alter table tb add col2 int default 2 --默认值
insert tb(col)
select 2
select * from tb
/*
col col2
----------- -----------
1 NULL
2 2
*/
drop table tb