日期:2014-05-18 浏览次数:20576 次
alter table t drop column b alter table t add b as a
------解决方案--------------------
alter table t drop column A2 alter table t add A2 as A1
------解决方案--------------------
1楼的方法叫计算列,不过与默认值是不同的,计算列不能修改
楼主的功能要实现,看来只能触发器
------解决方案--------------------
可以在程式中判断A2是否有值,如果没有值的话就以A1的值为准就好了呀
------解决方案--------------------
if object_id('tb','U') is not null
drop table tb
go
create table tb
(
A1 varchar(10),
A2 AS A1,
A3 varchar(10)
)
go
insert into tb (A1,A3) values ('1','3')
select * from tb
/*
A1 A2 A3
---------- ---------- ----------
1 1 3
(1 行受影响)
*/
------解决方案--------------------
触发器
------解决方案--------------------
直接用计算列啊
create table tb
(
a int,
b as a,
c int
)
------解决方案--------------------
用触发器
Create trigger tr_A_insert on A
instead of insert
as
set nocount on;
insert A(A1,A2,A3 )
select A1,A1,A3 from inserted