Is it safe to use human readable primary keys in SQL?

I want to know if I can use read-only primary keys for a relatively small number of database objects that will describe large megacities.

For example, using "washington_dc" as pk for the Washington, DC area, or "nyc" for New York.

Tons of objects will be alien keys to these areas of metro objects, and I would like to find out where a person or business is just by looking at their record in the database.

I'm just worried because my gut tells me that this can be a serious crime against good practice.

So, am I allowed to do such things?

Thank!

+5
source share
4 answers

It all depends on the application. Natural primary keys make a lot of sense on the surface because they are human readable and do not require any associations when displaying data to end users.

, INT ( BIGINT) , , - . , , , . , , city , ( " , St. " ).

, :

  • ( )
  • ( )
  • ( )

# 1 # 2 # 3, , .

+5

,

?

, . , , , , , .

( ) :

  • ( )
  • ( )
  • ( )
  • ( )

, , , , , , , . , , , , .

+2

, , .

, , , , ( , PK).

, , ( - , . IDENTITY). PK, int bigint PK. , , , SSMS , JOIN, , PK.

+1

.

.

numeric - Auto increment keys are preferred. they are easily saved and allow you to encode input forms and other interfaces where the user does not need to come up with a new line as a key ...

Imagine: should it be washington, or washington_dc or dc or washtondc .. etc.

+1
source

All Articles