表中有一字段 ID 为标识 现有另一字段 IDXH 要求 IDXH 和 ID 的值 一样 (IDXH 以后可以修改)
我自己写了个触发器 系统老说不行?请指教!!!
CREATE TRIGGER upidxh ON table1
FOR INSERT
ASbegin
set idxh=id
end请帮忙修正!!!!! 附带注解!!
我自己写了个触发器 系统老说不行?请指教!!!
CREATE TRIGGER upidxh ON table1
FOR INSERT
ASbegin
set idxh=id
end请帮忙修正!!!!! 附带注解!!
FOR INSERT
AS
declare @xuhao int(4)
begin
select @xuhao=id from inserted
update [dbo].[gongyjd] set idxh=@xuhao
end
FOR INSERT
AS
declare @xuhao int
begin
select @xuhao=id from inserted
update [dbo].[gongyjd] set idxh=@xuhao where id=@xuhao
end
FOR INSERT
AS
declare @xuhao int
begin
select @xuhao=id from inserted
update a set idxh=@xuhao where id=@xuhao
end
那还需要触发器做什么?在插入的时候id和idxh用一个变量不就可以了。
或是 create table [dbo].[table_name]
(
[id] [int] null,
[colanme] [int] null,
[idxh] as (id)
) on [primary] insert into [table_name] select 1,2
select * from [table_name]
/*
id colanme idxh
----------- ----------- -----------
1 2 1
*/
select @id,@col1,@col2,@id
在插入的时候处理,或者在存储过程中都可以,貌似没有必要用触发器。