![]() | |
#11
| |||
| |||
|
|
So in real life it turned out to be changing in about 0.5% cases. |

#12
| |||
| |||
|
|
I also had a friend who worked overseas with a "February-30" guest worker id card number that was treated as a forgery when he tried to rent a car. Yea and after personal id change we as IT workers will have some work |

|
I am waiting for the day that I have very-smart card with my medical history on it that can tie itself to me via a DNA match, so i do not have to give any further information. Yea and when you'll lose it happy finder or thief will know so much |

#13
| |||||
| |||||
|
|
Michael Zedeler wrote: dananrg (AT) yahoo (DOT) com wrote: [...] There are a few exceptions, such as here in Denmark where each citizen has a personal id number that _never_ changes and is guaranteed to be unique. It consist of the birth date and a serial number (subject to certain checksum constraints), which can easilly be implemented as a two-part key. In certain applications I would use that number as primary key. Khe, khe are you really working with this database or just heard of it, that personal id is never changing? Funnily we in Latvia had our db created with help of Denmark consultants and as a result I assume recieved more or less the same data model. So in real life it turned out to be changing in about 0.5% cases. So I'd be interested how you in Denmark bypass at least following problems we had: 1) person finds out that his birthday has changed or was incorrectly written in his identification documents |
|
2) operator simply enters incorrect birthdate |
|
3) two persons get the same personal id - this probably was our problem only because initially there wasn't all data enetered online in central db |
|
4) a person get personal id two times - this is probably a bigger problem and mostly for foreigners. |
|
So now we have a new system and personal id isn't primary key there, it is just the same attribute as name, sex and address for example. So after such cases I'm very sceptical about natural keys as primary keys and tend to use surrogate keys everywhere and use unique constraints for natural keys. I'm ready to accept that natural keys for the first 80 elements of periodic table probably are immutable ) |
#14
| |||
| |||
|
|
I am waiting for the day that I have very-smart card with my medical history on it that can tie itself to me via a DNA match, so i do not have to give any further information. |
#15
| |||
| |||
|
|
--CELKO-- wrote: I am waiting for the day that I have very-smart card with my medical history on it that can tie itself to me via a DNA match, so i do not have to give any further information. You'd still have to give enough information to ensure you couldn't be confused with your identical twin. If you don't have an identical twin then you'd have to supply that information too. Of course you might be mistaken or lying so the recipient may require additional identification to prove that you aren't impersonating your twin. |
|
-- David Portas, SQL Server MVP [...] -- |
#16
| |||
| |||
|
|
You'd still have to give enough information to ensure you couldn't be confused with your identical twin. If you don't have an identical twin then you'd have to supply that information too. |
|
I heard about a strange phenomenon where a person could carry two different sets of genes as a result of a fusion between non-identical twins in the womb, thus creating a lot of problems wrt to DNA-based forensics. |
#17
| |||||||||||
| |||||||||||
|
|
This means that a surrogate ought to act like an index; created by the user, managed by the system and NEVER seen by a user. That means never used in queries, DRI or anything else that a user does. That's your personal interpretation and not a lot of others and you've actually missed out what Codd really said, I've summarised this in my blog: http://sqlblogcasts.com/blogs/tonyro...05/11/427.aspx. Your ideas around surrogate key usage is completely wrong. You can still use surrogate keys in an application and they do not need to be exposed to the application, surrogates are a good way of getting round the problem when the natural key (primary key) changes - in that situation |
|
you need to stop all user access to your database do the primary key update and allow users back in, but first - expiring any cache; why do this? Well, if you have used the primary key as the access through to the data from the app then there might be old primary key floating around that when a user clicks update may in fact update the wrong data! Let's look at the logical problems. First try to create a table with two columns and try to make them both IDENTITY. If you cannot declare more than one column to be of a certain data type, then that thing is not a data type at all, by definition. It is a property which belongs to the PHYSICAL table, not the LOGICAL data in the table. It also has to be NULL-able to be a data type in SQL. First, IDENTITY is a property of a column in the same way a PRIMARY KEY is the property one or more columns - you can only have 1 primary key, you can only have 1 identity property! |
|
Again, IDENTITY is not a data type, its a property! Its a property I say, sunk in yet? Its a property I say!!! and, it can exist on a nullable column. |
| Next, create a table with one column and make it an IDENTITY. Now try to insert, update and delete different numbers from it. If you cannot insert, update and delete rows from a table, then it is not a table by definition. You cannot update the value of IDENTITY, you can delete rows or insert rows using SET IDENTITY_INSERT <tbl> ON. What is the property of a surrogate key again? Not changeable!!! So, the IDENTITY property suddenly becomes valid in both COdd and Dates definitions of a surrogate key. |
| Finally create a simple table with one IDENTITY and a few other columns. Use a few statements like INSERT INTO Foobar (a, b, c) VALUES ('a1', 'b1', 'c1'); INSERT INTO Foobar (a, b, c) VALUES ('a2', 'b2', 'c2'); INSERT INTO Foobar (a, b, c) VALUES ('a3', 'b3', 'c3'); To put a few rows into the table and notice that the IDENTITY sequentially numbered them in the order they were presented. If you delete a row, the gap in the sequence is not filled in and the sequence continues from the highest number that has ever been used in that column in that particular table. This is how we did record numbers in pre-allocated sequential files in the 1950's, by the way. A utility program would then "pack" or "compress" the records that were flagged as deleted or unused to move the empty space to the physical end of the physical file. IDENTITY leaves the gaps. But now use a statement with a query expression in it, like this: INSERT INTO Foobar (a, b, c) SELECT x, y, z FROM Floob; Since a query result is a table, and a table is a set which has no ordering, what should the IDENTITY numbers be? The entire, whole, completed set is presented to Foobar all at once, not a row at a time. There are (n!) ways to number (n) rows, so which one do you pick? The answer has been to use whatever the *physical* order of the result set happened to be. That non-relational phrase "physical order" again! But it is actually worse than that. If the same query is executed again, but with new statistics or after an index has been dropped or added, the new execution plan could bring the result set back in a different physical order. Indexes and statistics are not part of the logical model. Can you explain from a logical model viewpoint why the same rows in the second query get different IDENTITY numbers? In the relational model, they should be treated the same if all the values of all the attributes are identical. Just how does that prevent usage as a surrogate key? |
|
Using IDENTITY as a primary key is a sign that there is no data model, only an imitation of a sequential file system. Since this "magic, all-purpose, one-size-fits-all" pseudo-identifier exists only as a result of the physical state of a particular piece of hardware at a particular time as read by the current release of a particular database product, how do you verify that an entity has such a number in the reality you are modeling? What do you do when you have no usable natural key, for instance a member table of a user group? You can't ask people for their national insurance number - you need to create your own membership id! I'd be interested to know what primary key you'd create when you are only capturing FullName and Address? |
|
Remember - there are data protection rules for capturing data that is not necessary for the purpose you are using it, well here in the UK anyway., |
| Another cute way to destroy data integrity: BEGIN ATOMIC DELETE FROM Foobar WHERE id = <<some row>>; INSERT INTO Foobar VALUES ( <<recreate deleted row>>) END; Logically this should do nothing, but since IDENTITY has gaps, it trashes the data. SET IDENTITY_INSERT Foobar ON |
|
INSERT INTO Foobar ( always specify your columns you are inserting into!!! ) VALUES ( <<recreate deleted row>>) SET IDENTITY_INSERT Foobar OFF Its REALLY BAD PRACTICE not specifying the columns you are inserting into on the INSERT - you should know that and should set a good example. |
| Now you are REALLY thinking about relations and keys instead of 1950's sequential record numbering. Adding an IDENTITY column to either of these tables as a candidate key would be dangerously redundant; one query uses the IDENTITY and another uses the real key, and like a man with two watches, you are never sure what time it is. Daniel Wetzler found out the hard way that IDENTITY changed behavior in SQL 2000 and SQL 2005. If you perform the statement below you get only one dataset which has the described properties. SELECT DISTINCT IDENTITY (INTEGER) AS fake_id, title1, .. FROM Foobar WHERE title1 IS NOT NULL AND .. The IDENTITY function makes each row unique so DISTINCT doesn't eliminate the duplicates in this case. Interestingly, this behavior seems to have changed in SQL Server 2005. If Iupoi run this as a SELECT INTO on 2005, the execution plan computes the IDENTITY value after DISTINCT. For 2000 the kludge is a bit hard to see. The following should insert just one row into the target table. CREATE TABLE Foobar (title1 VARCHAR(10), ..); INSERT INTO Foobar VALUES ('1', ..); INSERT INTO Foobar VALUES ('1', ..); SELECT IDENTITY (INTEGER) AS fake_id, title1, .. INTO Foobar2 FROM (SELECT DISTINCT title1, .. FROM Foobar WHERE ..); Since we are dealling with a proprietary feature, this is subject to change without noti ce again. Thats because people have relied not on documented behaviour as specified in books online but believing the product behaves that way, which, given another example, people have come unstuck with the ORDER BY in a view! You really need to get a handle on your bias against IDENTITY, you still do not understand (after 5 years now, your post is an old canned answer by the way) the implementation and make fundemental mistakes which is why your answer is just out and out wrong. |
|
-- Tony Rogerson SQL Server MVP http://sqlblogcasts.com/blogs/tonyrogerson - technical commentary from a SQL Server Consultant http://sqlserverfaq.com - free video tutorials "--CELKO--" <jcelko212 (AT) earthlink (DOT) net> wrote in message news:1149954078.691147.177750 (AT) y43g2000cwc (DOT) googlegroups.com... [simple, surrogate keys for PKs in all tables] I personally think it's a good rule of thumb to create surrogate keys for almost all tables. No, absolutley no. First of all, they do not create surrogate keys; they create exposed physical locators, like IDENTITY or other auto-numbering schemes. Let me maker an appeal to authority, with a quote from Dr. Codd: "..Database users may cause the system to generate or delete a surrogate, but they have no control over its value, nor is its value ever displayed to them ..."(Dr. Codd in ACM TODS, pp 409-410) and Codd, E. (1979), Extending the database relational model to capture more meaning. ACM Transactions on Database Systems, 4(4). pp. 397-434. |
#18
| |||
| |||
|
|
2) operator simply enters incorrect birthdate See above. |
#19
| |||
| |||
|
|
"Michael Zedeler" wrote in message 2) operator simply enters incorrect birthdate See above. If an operator captures Joe Bloggs' ID number for Jake Bloggs, how does your earlier ("see above") comment help? |
![]() |
| Thread Tools | |
| Display Modes | |
| |