[英]What is the best way to anonymize ID values in sql server 2008
I got 2 tables in sql 2008 我在SQL 2008中有2张表
Table1
Id Name Surname City
1000 Alex White London
1001 John Brown Brussels
..
Table2
Id Surgeon Room aId
1 Mike J. A104 1000
2 Jack S. C144 1001
...
And I have a query like: 我有一个查询,如:
Select a.Id,b.Id,
a.Name,a.Surname,a.City,b.Surgeon,b.Room
into #results
from Table1 a
inner join Table2 b on a.Id = b.aId
What I want to do is to anonymize the a.Id and b.Id values for privacy, by using dummy ones instead of the real ones. 我想要做的是通过使用虚拟值而不是真实值来匿名化a.Id和b.Id值的隐私。 I added a random mathematical operations before, like:
我之前添加了随机数学运算,例如:
Select aId = a.Id * 22 / 5 + 14 * 2
,bId = b.Id * 12 / 4 + 7 * 3
...
but honestly I am not really happy what I am doing here and I am looking for a more professinal way to provide this. 但老实说,我对自己在这里所做的事情并不满意,我正在寻找一种更专业的方法来提供此服务。 Any advice would be appreciated.
任何意见,将不胜感激。
If you don't need to be sure the anonymized IDs are unique and you don't need to find a real ID based on an anonymized ID, you could use the CheckSum() or HashBytes() function with the strings from your Table1 and Table2: 如果不需要确保匿名ID是唯一的,并且不需要基于匿名ID查找真实的ID,则可以将CheckSum()或HashBytes()函数与Table1和表2:
Select aId = CheckSum(a.Name + a.Surname) % 10000
,bId = HashBytes('SHA1', b.Surgeon) % 10000
,a.Name,a.Surname,a.City,b.Surgeon,b.Room
into #results
from Table1 a
inner join Table2 b on a.Id = b.aId
If you need to be sure you have a unique value for each of the Id values in your table and you also need to find a real ID based on an anonymized ID, you can construct a lookup table as follows: 如果需要确保表中的每个Id值都有唯一的值,并且还需要基于匿名ID查找真实的ID,则可以按以下方式构造查找表:
CREATE TABLE Anon
(
ID INTEGER NOT NULL PRIMARY KEY,
AnonID UNIQUEIDENTIFIER DEFAULT NewID()
);
this can then be used in queries where the actual ID should not be returned: 然后可以在不返回实际ID的查询中使用它:
Select aID = Anona.AnonID,
bID = Anonb.AnonID,
a.Name,a.Surname,a.City,b.Surgeon,b.Room
into #results
from Table1 a inner join Table2 b on a.Id = b.aId
inner join Anon Anona on a.Id = Anona.Id
inner join Anon Anonb on b.Id = Anonb.Id
The Anon table would need to be maintained to ensure it contains all IDs from your Table1 and Table2. 将需要维护Anon表,以确保它包含表1和表2中的所有ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.