sql - Surrogate key 'preference' explanation -


as understand there war going on between purists of natural key , purists of surrogate key. in likes this post (there more) people 'natural key bad you, use surrogate...

however, either stupid or blind can not see reason have surrogate key always!

say have 3 tables in configuration this: link table

why need surrogate key it?? mean makes perfect sense not have it.

also, can please explain why primary keys should never change according surrogate key purists? mean, if have color_id varchar(30) , key black, , no longer need black because changing charcoal, why bad idea change black key charcoal , referencing columns too?

edit: noticed dont need change it! create new one, change referencing columns (same have surrogate key) , leave old 1 in peace....

in surrogate key mantra need create additional entry with, say, id=232 , name=black. how benefit me really? have spare key in table don't need more. need join colour name while otherwise can stay in 1 table , merry?

please explain 5 year old, , please keep in mind not trying 'surrogate key bad', trying understand why things 'always use surrogate key!'.

surrogate keys useful there suboptimal natural key: no more, no less. suboptimal natural key guid or varchar or otherwise wide/non-ordered.

however, decision use surrogate implementation decision after conceptual , logical modelling process, based on knowledge of how chosen rdbms works.

however, best practice of "have surrogate key" "always have surrogate key" , introduced immediately. object relation mappers add surrogate keys tables whether needed or not doesn't help.

for link (many-many) table, don't need one: sql: need auto-incremental primary key many-many tables?. table 2 int columns, overhead 50% of data surrogate column (assuming ints , ignoring row metadata)


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -