How to get the "best of both worlds" with natural and surrogate keys? And...
I am designing my first database, and I find myself frustrated by the choice between storing an integer or a string for each instance of a categorical variable.My understanding is that if I have a...
View ArticleHow not to "naturalize" surrogate keys?
Don't naturalize surrogate keys. As soon as you display the value of a surrogate key to your end users, or worse yet allow them to work with the value (perhaps to search), you have effectively given...
View ArticleInsert results from query, update old existing row if query doesn't still...
I am trying to refactor a table which contains historical data and therefore isn't ever deleted, but has an 'active' field.Each day we run a query (a few joins, but quite slow) to get some data to...
View ArticleIf all associated attributes of an intended primary key are identical, is it...
I'll start with an example. If I have a person table with intended surrogate primary key Id:+----+------+------------+-------------+| Id | name | DoB | SSN |+----+------+------------+-------------+| 1...
View ArticleShould a inherited table have a new surrogate key, or just use parent table's...
I am modeling some things with an "is a" relationship (aka inheritance), and there were two ways to go about it in regards to the inherited table's primary key and foreign key pointing back to the...
View ArticleNatural Keys vs Surrogate Keys part 2
A while back, I asked if surrogate keys provide better performance than natural keys in SQL Server. @sqlvogel provided an answer to that question yesterday that caused me to revisit it. This question...
View ArticleWhat are the disadvantages of using surrogate keys? [closed]
I am using MS SQL Server but in general database design I want to know what problems can arise when every row in a database has its auto generated surrogate key value.I know some advantages, for...
View ArticleWhat problems are there in not using a primary key column at all?
What purpose would a primary key column serve on a table such as post_versions here? Nothing refers to it, and there are no queries where I will ever want to select a row by post_versions.id. It'll be...
View ArticleComposite primary key plus a separate (surrogate) id column for foreign key...
I am trying to build a database about locations like so:Country → Region → TownCountries will be populated with a list of pre-defined worldwide countries, regions & towns are input by users.Region...
View ArticleDoes adding a surrogate key get rid of an identifying relationship between...
In the following example, we have a Comments table with a composite primary key (PK)CREATE TABLE Comments ( video_id INT NOT NULL, user_id INT NOT NULL, comment_dt DATETIME NOT NULL, PRIMARY KEY...
View ArticleM:M Table Design - Use of PK
I have a many-to-many table that contains id's from 2 related tables.For creating a primary key on this table, is it better to create another integer column and have that as a surrogate PK?Or should I...
View ArticleDo natural keys provide higher or lower performance in SQL Server than...
I'm a fan of surrogate keys. There is a risk my findings are confirmation biased. Many questions I've seen both here and at http://stackoverflow.com use natural keys instead of surrogate keys based on...
View ArticleForeign keys - link using surrogate or natural key?
Is there a best practice for whether a foreign key between tables should link to a natural key or a surrogate key? The only discussion I've really found (unless my google-fu is lacking) is Jack...
View ArticleShould every table have a single-field surrogate/artificial primary key?
I understand one benefit of surrogate/artificial keys in general - they do not change and that can be very convenient. This is true whether they are single or multiple field - as long as they are...
View ArticleWhat normal form does a surrogate key violate?
I have following question:"What normal form does a surrogate key violate?"My thought was the 3rd normal form, but I'm not quite sure it's just an assumption i am making. Could someone explain that to me?
View ArticleSurrogate key vs Natural key
I have a table called devices. Most of the devices that will get stored in this table can be uniquely identified by their serial number and part number. But there are some device types that do not have...
View ArticleIdentity versus Composite values for Primary Keys in Many-To-Many Tables...
I am in the middle of an interesting "Data Architecture" discussion at a place I am contracting & need some input.As a habit, I always create a Surrogate Key as the Primary Key in my tables - be...
View ArticleCommon term for tenant-based keys [closed]
Assume the following schema:ID | TENANT | TENANT_CUSTOM_ID346 | 101 | 1 347 | 102 | 1 348 | 101 | 2 349 | 101 | 3 350 | 101 | 4 351 | 102 | 2 352 | 103 | 1What is another name (or...
View ArticleWhat are the consequences, positive or negative, to having a surrogate...
I recently made a table that looks like the one belowCREATE TABLE example( id SERIAL PRIMARY KEY, subindusty_id INT UNIQUE NOT NULL, name TEXT NOT NULL -- other fields...)I realized that in this table...
View ArticleSurrogate keys as Foreign Keys
I have a question about Surrogate keys, say i have two tables(in sql server): Table A: Student_ID, Name, School, SectionTable B: Book_ID,Student_ID, IssueDate, BookName If Student_ID is a clustered...
View Article