Wednesday, March 7, 2012

PK Generation Or Data Synchronization - Repost

Sorry for repost, but there was a problem with my MSDN posting alias.
I would appreciate some advice on generating a PK and/or synchronizing data
between two (maybe three) locations.
Simplified scenario.
Using SQL Server 2005 (could got to 2008 if needed).
Client has two locations (central and remote).
Item record would containseven fields - six int fields (id's from component
tables) and a seventh field that would be the PK.
Most of the time the PK would be generated at central, however, should the
connection be lost, remote must be able to generate a PK also and then when
connection is restored, any new PK generated by remote must be added to
central.
The PK needs to be the same for the same combination of the six fields, no
matter which server generated it, in case both servers happened to create a
record with the same six fields. Therefore using a GUID would not work.
Since the PK will be used by another system (Great Plains), it's length is
limited to 30 characters.
I am hoping for some algorathym that would combine the six column values
and always generate the same value from the same six values. Something like
a hash code. However, I am limited to 30 characters and I do believe a hash
code is 64.
Another idea is to write routines to do the 'replication', instead of using
SQL replication.
Then add all new rows in 'remote' via a stored procedure. If the sp can't
connect to 'central' it would generate it's own PK and also record that in
another table. Then when connectivity is restored, my replication routine
would check for duplicate rows and if necessary, update the PK in 'remote'
with the PK from 'central'.
Aside from the complexity, the problem with that is I don't know if Great
Plains can use cascade update to update its' detail tables that would be
referencing my PK as an FK.

AG
Email: discussATadhdataDOTcom
Hi AG,
Appreciate your understanding that this is not a dedicated SQL Server
related question. Regarding such algorithm related consulting question, I
am afraid that we could only give you some general suggestions here. For
your requirements, I think that it is better to use cryptographic hash
function to generate PK. Though the output length is 64, you can just
retrieve the first 30 bytes. I think that the opportunity of retrieving
same PK value is also very rare. You know that GUID is just a 16 byte
value, however you are getting a 30 byte value from the hash code. You may
perform a test to insert 1 million rows to your table to see if there are
any duplicated PK values generated.
Please feel free to let me know if you have any other questions or
concerns. Have a nice day!
Best regards,
Charles Wang
Microsoft Online Community Support
================================================== =========
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msdnmg@.microsoft.com.
================================================== =========
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
================================================== ==========
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== =======
|||Thanks for the reply Charles.
I did not expect someone to write an algorithm for me. Although if someone
already had something similar and wanted to share, that would be great.
I understand about GUID, but the problem is that, should each server
generate a new PK for the same combination of the six fields, I would want
the PK generated to be the same.
Using the hash, are you saying that it is extremely likely for the first 30
bytes to be unique and to use the million row test to confirm that?
I guess the main question here is, what do others do in similar situation? I
can't believe that this situation is so uncommon.
AG
Email: discussATadhdataDOTcom
"Charles Wang[MSFT]" <changliw@.online.microsoft.com> wrote in message
news:ManMJWMlIHA.3756@.TK2MSFTNGHUB02.phx.gbl...
> Hi AG,
> Appreciate your understanding that this is not a dedicated SQL Server
> related question. Regarding such algorithm related consulting question, I
> am afraid that we could only give you some general suggestions here. For
> your requirements, I think that it is better to use cryptographic hash
> function to generate PK. Though the output length is 64, you can just
> retrieve the first 30 bytes. I think that the opportunity of retrieving
> same PK value is also very rare. You know that GUID is just a 16 byte
> value, however you are getting a 30 byte value from the hash code. You may
> perform a test to insert 1 million rows to your table to see if there are
> any duplicated PK values generated.
> Please feel free to let me know if you have any other questions or
> concerns. Have a nice day!
> Best regards,
> Charles Wang
> Microsoft Online Community Support
> ================================================== =========
> Delighting our customers is our #1 priority. We welcome your
> comments and suggestions about how we can improve the
> support we provide to you. Please feel free to let my manager
> know what you think of the level of service provided. You can
> send feedback directly to my manager at: msdnmg@.microsoft.com.
> ================================================== =========
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
> Note: The MSDN Managed Newsgroup support offering is for
> non-urgent issues where an initial response from the community
> or a Microsoft Support Engineer within 1 business day is acceptable.
> Please note that each follow up response may take approximately
> 2 business days as the support professional working with you may
> need further investigation to reach the most efficient resolution.
> The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by
> contacting Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ================================================== ==========
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> ================================================== =======
>
|||Hi AG,
> Using the hash, are you saying that it is extremely likely for the first
30
> bytes to be unique and to use the million row test to confirm that?
Yes, I think so. You may use .NET to develop a CLR stored procedure or user
function to generate a hash code or you may use third party extended stored
procedures like this:
MD5 Hash SQL Server Extended Stored Procedure
http://www.codeproject.com/KB/database/xp_md5.aspx
Best regards,
Charles Wang
Microsoft Online Community Support
================================================== =======
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msdnmg@.microsoft.com.
================================================== =======
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== =======
|||Thanks Charles, I will give that a try.
How about responding to my last question/comment?
What do others do in similar situation?
I can't believe that this situation is so uncommon.
AG
Email: discussATadhdataDOTcom
"Charles Wang[MSFT]" <changliw@.online.microsoft.com> wrote in message
news:EPjgFQXlIHA.3756@.TK2MSFTNGHUB02.phx.gbl...
> Hi AG,
> 30
> Yes, I think so. You may use .NET to develop a CLR stored procedure or
> user
> function to generate a hash code or you may use third party extended
> stored
> procedures like this:
> MD5 Hash SQL Server Extended Stored Procedure
> http://www.codeproject.com/KB/database/xp_md5.aspx
> Best regards,
> Charles Wang
> Microsoft Online Community Support
> ================================================== =======
> Delighting our customers is our #1 priority. We welcome your
> comments and suggestions about how we can improve the
> support we provide to you. Please feel free to let my manager
> know what you think of the level of service provided. You can
> send feedback directly to my manager at: msdnmg@.microsoft.com.
> ================================================== =======
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> ================================================== =======
>
|||Hi AG,
Honestly I did not see others having such requirements before. For most
cases, you can use SQL Server replication to replicate data among different
servers. If you want high availability, you can use SQL failover cluster or
Database Mirroring? Since there is failover function on SQL Server Failover
cluster and Database Mirroring, the data consistency can be ensured on
different servers. It seems that your requirements can be fitted by using
SQL Server failover cluster or Database Mirroring (only for SQL Server 2005
or 2008).
You may refer to:
SQL Server 2005 Failover Clustering White Paper
http://www.microsoft.com/downloads/details.aspx?FamilyID=818234dc-a17b-4f09-
b282-c6830fead499&displaylang=en
Database Mirroring in SQL Server 2005
http://www.microsoft.com/technet/prodtechnol/sql/2005/dbmirror.mspx
Please feel free to let me know if you have any other questions or
concerns. Have a nice day!
Best regards,
Charles Wang
Microsoft Online Community Support
================================================== =======
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msdnmg@.microsoft.com.
================================================== =======
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== =======
|||Thanks, I will check those out.
AG
Email: discussATadhdataDOTcom
"Charles Wang[MSFT]" <changliw@.online.microsoft.com> wrote in message
news:qq9FvrhlIHA.7196@.TK2MSFTNGHUB02.phx.gbl...
> Hi AG,
> Honestly I did not see others having such requirements before. For most
> cases, you can use SQL Server replication to replicate data among
> different
> servers. If you want high availability, you can use SQL failover cluster
> or
> Database Mirroring? Since there is failover function on SQL Server
> Failover
> cluster and Database Mirroring, the data consistency can be ensured on
> different servers. It seems that your requirements can be fitted by using
> SQL Server failover cluster or Database Mirroring (only for SQL Server
> 2005
> or 2008).
> You may refer to:
> SQL Server 2005 Failover Clustering White Paper
> http://www.microsoft.com/downloads/details.aspx?FamilyID=818234dc-a17b-4f09-
> b282-c6830fead499&displaylang=en
> Database Mirroring in SQL Server 2005
> http://www.microsoft.com/technet/prodtechnol/sql/2005/dbmirror.mspx
> Please feel free to let me know if you have any other questions or
> concerns. Have a nice day!
> Best regards,
> Charles Wang
> Microsoft Online Community Support
> ================================================== =======
> Delighting our customers is our #1 priority. We welcome your
> comments and suggestions about how we can improve the
> support we provide to you. Please feel free to let my manager
> know what you think of the level of service provided. You can
> send feedback directly to my manager at: msdnmg@.microsoft.com.
> ================================================== =======
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> ================================================== =======
>

No comments:

Post a Comment