create table table_3
(
table3_num int not null,
table3_count as (table4_num)
)
go我的意思是,怎么设置 table3_count 的默认值为 table3_num 的值? 我要做到以后能修改的,貌似用计算列实之后,就不能改了?忘指点!! 谢谢!
(
table3_num int not null,
table3_count as (table4_num)
)
go我的意思是,怎么设置 table3_count 的默认值为 table3_num 的值? 我要做到以后能修改的,貌似用计算列实之后,就不能改了?忘指点!! 谢谢!
(
table3_num int not null,
table3_count int
)
gocreate trigger tr_table_3
on table_3 instead of insert
as
set nocount on
insert table_3 select table3_num, isnull(table3_count, table3_num) from inserted
set nocount off
goinsert table_3(table3_num) select 1
insert table_3 select 2,10select * from table_3
/*
table3_num table3_count
----------- ------------
1 1
2 10
*/
create table table_3
(
table3_num int ,
table3_count INT
)
GO
---DROP TRIGGER trig_tab3
CREATE TRIGGER trig_tab3
ON table_3 INSTEAD OF INSERT
AS
INSERT INTO table_3 SELECT table3_num,table3_num FROM inserted
GOINSERT INTO table_3 (table3_num) SELECT 5SELECT * FROM table_3 ttable3_num table3_count
----------- ------------
1 1
5 5(2 row(s) affected)
建表就不用要 table3_count 列建个视图使用时直接调用视图
没必要对一条记录 进行两次 insert 或 一次insert 一次update
个人意见
这样?
create table table_3
(
table3_num int not null,
table3_count as table3_num
)
go
create table table_3
(
table3_num int not null,
)
go
alter table table_3 add check ALTER TABLE table_3 --增加一列
ADD table3_count int NULL
CONSTRAINT table3_countConstraint
DEFAULT table3_num WITH VALUES