从表B更新表A [英] updating table A from Table B
问题描述
查询是一个跟随
表A
gid(pK)标志Buffer_distance the_geom
1 1 23
2 2 235
3 1 55
4 3 66
5 2 42
6 1 2123
表B
GID(PK)缓冲区距离
1 1000
2 2000
3 3000
表a应该获得距表B的缓冲区距离,并且当我更改表A中的flag的值时,还应该同时更新the_geom colmn
表A
gid(pK)标志Buffer_distance the_geom
1 1 23
2 2 235
3 3 3000
4 3 66
5 2 42
6 1 2123
结果应该是这样,并且the_geom字段也会动态变化
我想要一个触发器,该触发器始终更新表A中的标志,它应从表B中获取缓冲区距离,并用表A中的Buffer_distance替换它,并且其几何字段也应更改.
问候
Manish sharma
The query is a follows
Table A
gid(pK) Flag Buffer_distance the_geom
1 1 23
2 2 235
3 1 55
4 3 66
5 2 42
6 1 2123
Table B
GID (PK) Buffer_distance
1 1000
2 2000
3 3000
table a should get the buffer distance from table B and when I change the value of flag in table A and along with this it should also update the_geom colmn
Table A
gid(pK) Flag Buffer_distance the_geom
1 1 23
2 2 235
3 3 3000
4 3 66
5 2 42
6 1 2123
the result should be like this and the_geom field also change dynamically
i want a trigger that i always update the flag in table A it should fetch the buffer distance from table B and replace it with Buffer_distance in table A and its geometry field should also change.
regards
Manish sharma
推荐答案
您的触发器应该或多或少与此类似..
Your trigger should be more or less like this one..
Alter TRIGGER rowInsteadOfupDATE ON [dbo].[Table_1]
INSTEAD OF Update
AS
declare @flag int;
declare @distance int;
declare @gid int;
select @flag =i. flag from inserted i;;
select @gid =i.gid from inserted i;
BEGIN
Select @distance=distance from Table_2 where gid=@flag
print @distance
print @flag
update Table_1 set flag=@flag, distance=@distance where gid=@gid;
PRINT 'Record Updated ';
END
GO
这篇关于从表B更新表A的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!