Possible duplicates:Surrogate Vs. Natural / Business KeysWhen not to use surrogate primary keys?
So, I would prefer to have INT as a primary key with AI. But, here is the reason why I am considering making a unique string as a primary key :. I should not query related tables to retrieve the primary key, since I already know it
For example:I have a lot of relationships:
Customer - Order - Product
Let's say I want to add a new customer and a new order, and I already know what they bought. I have to query the product table to get an INT, but if I have a string (unique) that is the primary key I shouldn't make a query (this seems cleaner than me, I'm not talking about optimization / runtime, not at all )
If you do not care about optimization, the main 2 criteria for the primary key are:
Uniqueness
Constant (never changes)
. - , 2 , (, Norton Antivirus → Symantec Antivirus ), .
100% , .
, - , , , , ID .
, VARCHAR ( ), - .
VARCHAR
(, : SQL Server), . , . , , VARCHAR .
Er...
Source: https://habr.com/ru/post/1732685/More articles:Как создать динамический SQL-запрос? - sqlXpath selects the next (number) neighbor inside the anchor - xpathjquery insert div right inside the form - jqueryReactive Extension Interrupt First Step - c #Is there a drawback to using ASP.NET dynamic data for a data driven website? - asp.netPHP Overload like sprintf ()? - phpAnimation of a selected wpf list item - c #Inability to free memory - cSearch the Java collection. Why is it so hard? - javaLearning Web Programming for a C ++ Programmer - language-agnosticAll Articles