natural-key

Retrofit surrogate key in table with natural key in MySql?

Assume a table that uses a natural key and has a number of existing rows. What would be the easiest way to retrofit a surrogate key column and populate it with unique values using MySql? I.e. transform table employees ( social_security_no varchar(20), ... constraint emp_pk primary key (social_security_no) ); to table emp...

Entity Framework and associations between string keys

Hi, I am new to Entity Framework, and ORM's for that mather. In the project that I'm involed in we have a legacy database, with all its keys as strings, case-insensitive. We are converting to MSSQL and want to use EF as ORM, but have run in to a problem. Here is an example that illustrates our problem: TableA has a primary string k...

Must Django ManyToManyField association tables have a surrogate key?

I'm mapping an existing database structure into Django models. I have a many-to-many structure where the association table is natural-keyed: CREATE TABLE foo (id INTEGER PRIMARY KEY); CREATE TABLE bar (id INTEGER PRIMARY KEY); CREATE TABLE foo2bar (foo_id INTEGER REFERENCES foo(id), bar_id INTEGER REFERENCES bar(id...

What is a natural identifier?

When reading through the Hibernate documentation I keep seeing references to the concept of a "natural identifier". Does this just mean the id an entity has due to the nature of the data it holds? IE: A user's name+password+age+something are its identity? ...

Unique identifiers for users

If I have a table of a hundred users normally I would just set up an auto-increment userID column as the primary key. But if suddenly we have a million users or 5 million users then that becomes really difficult because I would want to start becoming more distributed in which case an auto-increment primary key would be useless as each no...

Can I use an assigned, natural-key identifier while still allowing NHibernate to identify transient instances?

Object A has a one-to-many association: many object B. When I look in the database -- TableB -- I'd like to see the unique, readable string A.Name instead of having always to join or subselect on a surrogate integer identifier to see the name. I can map Name as the identifier for A, but this causes lots of extra SELECT queries because ...

Relational database design question - Surrogate-key or Natural-key?

Which one is the best practice and Why? a) Type Table, Surrogate/Artificial Key Foreign key is from user.type to type.id: b) Type Table, Natural Key Foreign key is from user.type to type.typeName: ...