Featured post
django - Automate the generation of natural keys -
i'm studying way serialize part of data in database , deserialize in database b (a sort of save/restore between different installations) , i've had django natural keys avoid problems due duplicated ids.
the issue should add custom manager , new method models. there way make django automatically generate natural keys looking @ unique=true
or unique_togheter
fields?
please note answer has nothing django, give alternative think about.
you didn't mention database, however, in sql server there binary_checksum() keyword can use give unique value data held in row. think of hash against fields in row. checksum method can used update database checking if local row checksum <> remote row checksum.
this sql below update local database remote database. won't insert new rows, use insert ... id > @maxlocalid
select delivery_item_id, binary_checksum(*) bc #di [remote.network.local].yourdatabase.dbo.delivery_item di select delivery_item_id, binary_checksum(*) bc #di_local delivery_item di -- rid of items match delete #di_local delivery_item_id in (select l.delivery_item_id #di x, #di_local l l.delivery_item_id = x.delivery_item_id , l.bc = x.bc) drop table #di update di set engineer_id = x.engineer_id, ... -- set other fields here delivery_item di, [remote.network.local].yourdatabase.dbo.delivery_item x, #di_local l x.delivery_item_id = l.delivery_item_id , di.delivery_item_id = l.delivery_item_id drop table #di_local
for above work, need linked server between local database , remote database:
-- create linked server if don't have 1 if not exists ( select srv.name sys.servers srv srv.server_id != 0 , srv.name = n'remote.network.local' ) begin exec master.dbo.sp_addlinkedserver @server = n'remote.network.local', @srvproduct = n'sql server' exec master.dbo.sp_addlinkedsrvlogin @rmtsrvname = n'remote.network.local', @useself = n'false', @locallogin = null, @rmtuser = n'your user name', @rmtpassword = 'your password' end go
- Get link
- X
- Other Apps
Comments
Post a Comment