Following the last SQL Server spatial task,
The author also received a new task:
When the Database property field changes, the spatial data is automatically updated without changing the business code.
The first solution that comes to mind is the trigger.
Basic ideas:
After the data has been updated or inserted, the spatial field data is updated when the value of any one of the X, Y fields of the table changes.
The following is an example of camera table Videopointinfo
varchar
Field |
type |
|
videoid |
varchar |
primary key ID |
videoname |
camera name |
clientx |
number |
Longitude |
clienty |
Number |
latitude |
geom |
geometry |
actual coordinates |
-- add a coordinate field to the table alter table videopointinfo add geom geometry;-- create or modify a trigger, Created with Create, modified with Alteralter trigger tri_videopointinfo on videopointinfoafter update, insert as-- call If update (clientx) or update (clienty) when Clientx or clienty has an update begin -- set Geom to null when either Clientx or clienty has a null value if (select clientx from inserted) is null or (select clienty from inserted) is null begin update v set geom=null from videopointinfo v where exists (Select 1 from inserted where videoflag=v.videoflag) Return end update&nBsp;v set geom=geometry::stgeomfromtext (' point ' (' +convert (Varchar,CLIENTX) + ') ' +convert (varchar,clienty) + ') ', 4326 from videopointinfo v where exists (Select 1 from inserted where videoflag=v.videoflag) End
Finally, you can try to update a few data to test the effect.
Another way to open and disable a trigger statement
Disable trigger Trigdb on database--disable trigger enable trigger TRIGDB on database--open trigger
Reference Document: Msdn-create Trigger
On SQL Server triggers