all groups > sql server programming > november 2007 >
You're in the

sql server programming

group:

hmmmmmmmmmm


hmmmmmmmmmm Michael C
10/31/2007 12:00:00 AM
sql server programming:
"Q7: I would like to change my user name, how can I do it?
A: Unfortunately, it is not possible due to technical reasons (because of
the way GameKnot stores and references the user data on the server) -- your
user name is permanent and cannot be changed."

Gotta love the natural key crowd :-)

Re: hmmmmmmmmmm Roy Harvey (SQL Server MVP)
10/31/2007 12:00:00 AM
On Wed, 31 Oct 2007 10:34:01 -0400, "Sylvain Lafontaine" <sylvain aei
[quoted text, click to view]

Against hackers, of course not. But the original complaint was that
the application did not support name changes. If the application
supports changing names I can change Roy to X, Sylvain to Roy, and X
to Sylvain. That's not hacking. It is something that the application
requirements must choose to allow or prevent.

[quoted text, click to view]

Of course it is only an assumption that it is based on a natural key.
The only thing we really know is that changes are not permitted.

Natural keys and surrogate keys both have their uses, but it always
requires knowing the requirements, and understanding how they might
change.

Roy Harvey
Re: hmmmmmmmmmm Sylvain Lafontaine
10/31/2007 12:00:00 AM
[quoted text, click to view]

Of course, it's only an assumption. However, the given reason for not
permitting the change was: « Unfortunately, it is not possible due to
technical reasons (because of the way GameKnot stores and references the
user data on the server) ... ». Like the old proverb say: "When it looks
like a duck, walk like a duck and quack like a duck, then it's probably a
duck. ".

In this case, the GameKnot is either based on natural keys or someone is
making a big lie.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


[quoted text, click to view]

Re: hmmmmmmmmmm Roy Harvey (SQL Server MVP)
10/31/2007 12:00:00 AM
On Wed, 31 Oct 2007 11:44:56 -0400, "Sylvain Lafontaine" <sylvain aei
[quoted text, click to view]

Yes, I should have remembered that this was the explanation given.

Of course the reason that gets put into a FAQ and what was in the
designer's mind when deciding to not support name change might not
have a lot to do with each other.

Roy Harvey
RE: hmmmmmmmmmm Bob
10/31/2007 4:29:00 AM
Laziness. It's the same for the PS3 too.

[quoted text, click to view]
Re: hmmmmmmmmmm Roy Harvey (SQL Server MVP)
10/31/2007 8:51:39 AM
Or a deliberate design choice to prevent anyone from swapping names
(and scores).

Roy Harvey
Beacon Falls, CT

On Wed, 31 Oct 2007 04:29:00 -0700, Bob
[quoted text, click to view]
Re: hmmmmmmmmmm Sylvain Lafontaine
10/31/2007 10:34:01 AM
Do you really believe that the use of natural keys offer a better protection
against hackers than surrogate keys? If someone is hacking into a system,
any system, the use of either key should be the last of concern for anyone.

However, here's something that I believe: if the big boss of GameKnot ever
come down from his chair and now say that he wants his clients to be able to
change their user names; then the database(s) will become a big piece of
s**t in no time if it's based on natural key.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


[quoted text, click to view]

Re: hmmmmmmmmmm --CELKO--
10/31/2007 11:17:41 AM
[quoted text, click to view]

This is not a Natural versus Artificial keys problem; this is a lack
of DRI actions to CASCADE changes. I would bet that they use an auto-
increment as a "mock pointer chain" from a Users table to the rest of
the schema. Changing the user_id occurrence will not help if all
references are made to the auto-increment value.
Re: hmmmmmmmmmm Scott Morris
10/31/2007 2:01:28 PM
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
[quoted text, click to view]

Sounds like you have never had to provide tech support for a production
system.

[quoted text, click to view]

From a technical standpoint, there is nothing to prevent the designers of
the system from providing the ability to change the username, regardless of
whether it is used a primary key.

From a technical support standpoint, the originally reported statement is
probably completely accurate. The tech support person cannot do something
that the system did not implement. Place the blame where it belongs - on
the system design (and perhaps lazy or sloppy programming).

Re: hmmmmmmmmmm Sylvain Lafontaine
10/31/2007 2:48:43 PM
The DRI is not the kill all solution to everything. First, with SQL-Server,
it won't work with cyclic relations nor with related databases (you will
have to use a complex mixture of triggers and other pleasant things). The
problem with related databases could be even harder because these databases
might be related to other databases, too; either as primary or secondary.
They are other things like backup and history databases, too.

Finally, there might be also a legal constraint: in many countries, it's
often illegal to change the value of a primary key of any table used
directly or indirectly for taxes purposes.

For me, the choice look simple: use a surrogate key and make it easy to
change the user name of a client or use a natural key and make it hard,
difficult, nearly impossible or even illegal to change it later.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


[quoted text, click to view]

Re: hmmmmmmmmmm Roy Harvey (SQL Server MVP)
10/31/2007 8:58:29 PM
On Thu, 1 Nov 2007 11:49:44 +1100, "Michael C" <mike@nospam.com>
[quoted text, click to view]

Exactly. Sylvain's scores would go with the name changes and be
associated with Roy, and Roy's scores would stay with him under his
new name of Sylvain. And either Roy or Sylvain - or both, if a third
party made the swap - might not be happy about it.

Roy Harvey
Re: hmmmmmmmmmm Tony Rogerson
10/31/2007 9:16:16 PM
[quoted text, click to view]

Oh, but it is.

The designer has obviously followed YOUR advice and NOT used surrogate keys.

This highlights the danger of just relying on the natural key - natural keys
change.

[quoted text, click to view]

"mock pointer chain"; you mean "surrogate key"

[quoted text, click to view]

create table users (
user_name varchar(50) not null primary key
)

create talbe user_permissions (
user_name ... references users( user_name )
...
)

When user_name changes it needs to change everywhere; only, you will be
using it in the plumbing for the communication between the application tiers
and the database.

Now, if only they had used a surrogate key then the natural key becomes just
meta data, the plumbing is done using the surrogate key, the user NEVER
needs to see that surrogate key either.

create table users (
user_name varchar(50) not null unique
user_id int not null IDENTITY primary key
)
create talbe uiserr_permissions ()
user_id int not null references users( user_id ),
...
)

Only one column in one table needs to change, the app concurrency is
protected because of the surrogate key.


--
Tony Rogerson, SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson
[Ramblings from the field from a SQL consultant]
http://sqlserverfaq.com
[UK SQL User Community]


[quoted text, click to view]
Re: hmmmmmmmmmm Michael C
11/1/2007 12:00:00 AM
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
[quoted text, click to view]

There's also the issue that changing a username will impact on other users
who are playing against them. This is a chess site where people can log on
and make their move at any time during the day. If they open a page and that
page stores a reference to another's username, then they will get problems
if the username is changed. Especially if 2 people swap usernames for some
reason.

Michael

Re: hmmmmmmmmmm Michael C
11/1/2007 12:00:00 AM
[quoted text, click to view]

I don't think that would be a huge issue. It wouldn't really matter if Roy
and Sylvain swapped their ratings, their entire history would go along with
them.

Michael

Re: hmmmmmmmmmm Michael C
11/1/2007 12:00:00 AM
[quoted text, click to view]

I'm sure if a third party made any swap that user would not be happy.
[quoted text, click to view]

Re: hmmmmmmmmmm --CELKO--
11/2/2007 10:23:55 AM
[quoted text, click to view]

Validation and verification. Consider a VIN on your automobile. No
matter where I go on the entire planet, it identifies that one
particular vehicle. Would you like to let everyone give their
automobile a nickname? Sure, kids do it ("Greased Lightning" if you
are into musicals). Why not let every database create a local key,
unknown to anyone else on Earth?

This fails in the real world; local created keys do not work for
manufacturing or a legal title system, law enforcement, etc. Natural
keys work but they require more effort on the part of the programmers
and DBAs. Cowboy coders hate research and work -- they want to "git
'er done" to quote Larry the Cable Guy.

The performance argument is a few decades out of date. We have much
bigger, faster machinery today --32 and 64 bits versus 16 bit
hardware; nanosecond speeds; massive parallelism; etc. Do you think it
will be worse, the same, better or MUCH better in 5 years?

Re: hmmmmmmmmmm --CELKO--
11/2/2007 10:38:13 AM
[quoted text, click to view]

Solid?? You are being local, dialect and lazy. First of all, what you
are talking about are NOT surrogate keys (look up Dr. Codd's articles
-- surrogates are not exposed) butexposed physical locators (generated
by the hardware and software on one machine with one particular
release of one particular product).

If I have to do an artificial key, then I would take the time to
carefully design my key; I have a few thousand words about that in my
books. IT IS HARD WORK. That is why we SQL Gurus make the big bucks.


Re: hmmmmmmmmmm Trey Walpole
11/2/2007 10:53:59 AM
[quoted text, click to view]

Natural keys will always have to be used - just not necessarily for RI.

You must use natural keys to prevent duplicate data. Sure, there are the
occasional "hall closet" log tables where it doesn't matter, but those
are typically not "real" data - i.e., not directly externally provided.

The fact is, I use both natural and surrogate during implementation -
there is the primary key discovered during design (no arbitrary
surrogate keys at this point), and possibly a row identifier to use for
RI. Not having to cascade updates - which isn't always allowed in DRI,
due to possible cyclic relations - is a huge performance gain.

For implementation, I prefer using identities for surrogates - they're
solid (as long as the column is constrained to be unique), they're
efficient, and they generate quickly (I don't have to roll my own).
I don't make the row ID the PK constraint, however. I put the PK
constraint on the primary key. After all, the row ID isn't real data,
it's just an arbitrary ID - like a bolt holding together a frame. RI can
be done on a unique constraint. Sure, you *can* put the PK on the row ID
and a unique constraint on the logical primary key - but how do you
identify the logical PK if you have multiple unique constraints? By
constraint name? ick.
I also don't use identities on every table, even on those that are
referenced. e.g., Domain definition tables (lookups) are often more
efficient to use later if they are human readable.

I have yet to find a logical data model design application that I like
to use. I identify that "x relates to y 1:n," not that this relation is
"on column z". In design apps, you have to identify the relating
column(s), so you either have to give a surrogate key during logical
design, which seems a knee-jerk reaction; or you have to let it
Re: hmmmmmmmmmm Sylvain Lafontaine
11/2/2007 11:07:35 AM
Good question, I suppose that the same could be asked about religions, wars,
politicians and some others more or less pleasant things that you encounter
in life.

There are three things in database design that I stopped using many years
ago wherever it's possible (ie., when it's me who is taking the decision) :
natural keys, composite keys and Ascii. Now, if I found someone who is
storing foreign caracters in a composite key based itself on natural keys; I
will tell him that's probably a bad idea. However, if he wants to persist,
do you really think that I would care or bother about him or her?

I won't care no more about him (or her) that I would care about someone
willing to give his money to a sect (or a church) in order that his gourou
can change his collection of luxury 2007 cars for a collection of new luxury
2008 cars. Hey, it's his money (and time), not mine.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


[quoted text, click to view]

Re: hmmmmmmmmmm Michael C
11/2/2007 9:15:31 PM
[quoted text, click to view]

There's been several very good issues raised relating to natural keys that
have gone unanswered here. I have to ask, if the natural key crowd don't
have answers to these questions, why do they still use them?

[quoted text, click to view]

Re: hmmmmmmmmmm Hugo Kornelis
11/2/2007 11:41:56 PM
[quoted text, click to view]

Hi Michael,

I'm not sure if I am in the "natural key crowd", nor in the "surrogate
key crowd". I'm one of those silly types that thinks that there is no
one-size-fits-all solution and you have to decide on a case by case
basis.

I don't have time to check the entire thread for unanswered good issues,
so let me just spill some of my thoughts and then you can come back to
me if you feel I have left things unaddressed.

First, I think that developers should let the end users dictate how the
computer works, not the other way around. Since I am convinced that end
users already have some system to distinguish one customer from another,
one order from another, one payment from another, and one product from
another, I prefer to follow their method. Most people call this a
natural key; I prefer the term business key (after all, there is nothing
natural about my SSN, it's nowhere found on my body - but it is the key
that the government "business" uses). Only when there is no adequate key
in use in the business will I work with the end users to help them find
a good key.

But after this first step comes the second: implementation. There are
cases where the business key just doesn't cut it for use in the
database. The most obvious ones are:
* Business key is subject to frequent change
* Business key is very long (e.g. varchar(300)) or composed of many
(three or more) columns
In such cases, I will check if the table is referenced elsewhere. Unless
there are no of very little references, I will introduce a surrogate key
as defined by Dr.Codd, implemented in SQL Server with an IDENTITY
column. I will either make the surrogate key the PRIMARY KEY and define
a UNIQUE constraint for the business key, or vice versa. All references
in the database to the table will be implemented through the surrogate
key, but all references from outside the table will continue to use the
business key.

This way, I still can offer the users the continued use of the
identification scheme they are accustomed to, but I don't get the
performance hit that I would get by implementing references with a
frequently changing, composite, or very long business key.

--
Hugo Kornelis, SQL Server MVP
Re: hmmmmmmmmmm Hugo Kornelis
11/2/2007 11:44:36 PM
[quoted text, click to view]

Hi Joe,

If you quote Dr. Codd, quote him in full. Surrogate keys are not exposed
to the database users. He never said that surrogates should not be
exposed to developers or DBAs.

[quoted text, click to view]

An IDENTITY is neither physical, nor a locator. And if you stop using
SELECT * in your view definitions, it's not exposed either.

--
Hugo Kornelis, SQL Server MVP
Re: hmmmmmmmmmm Hugo Kornelis
11/2/2007 11:48:54 PM
[quoted text, click to view]

Hi Joe,

So how exactly does this blahblah relate to the issue at hand, which (if
I understand the messages correctly) is about either using the natural
key as the only key of the table, or _adding_ a surrogate key to solve
most of the problems that are caused by changing a natural key?

[quoted text, click to view]

We also have much larger databases. Currently, the amount of data stored
in databases is growing at a faster rate than the processing power of
our computers. Unless that trend reverse, if will be MUCH worse in 5
years. If not sooner.

If you get called in for a consultancy gig and deliver a product that is
blindingly fast on your 100 MB test data but slows down to a crawl on
the company's multi-terabyte DB, do you tell them that the problem will
solve itself as the hardware evolves over the next years?

--
Hugo Kornelis, SQL Server MVP
Re: hmmmmmmmmmm Geoff Schaller
11/3/2007 7:35:17 AM
Well said.

Often the 'real world'... you know, the one where people pay you money
to implement their ideas... dictates how things will look. Often it is
not pretty, often it is not efficient from the purist's sense. But it
works and it deals with the real world in ways they are familiar.

We can and should advise but in the end we have to deliver. The customer
is always right, unfortunately, and not all of us have the time to write
book about it :-)


Geoff Schaller


[quoted text, click to view]
AddThis Social Bookmark Button