Domanda

I have two different entity types that are identified by a string. I want to write an SQL database to store the relationship between two elements, one of each type.

I don't need to store any information about the elements itself, only its identifier, so I want to write an SQL table that have two string (the related elements' identifiers) as primary keys.

I have read Strings as Primary Keys in SQL Database and I'm not sure if it's a good idea to have two strings as primary keys of a table.

The other option is to store in one table the identifiers of one type of entity and in another table, the identifiers of the other type, and then my "relationship" table will have two integers as primary keys... but it will made me to re-write the persistence part of my program...

All the advices are welcome

È stato utile?

Soluzione

There is no problem with using two strings as keys in your database. There is no need to go through all that trouble just to get integers keys, because it technically could be faster. This is basically also what Kevin says in the selected answer on the question you link.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top