Quantcast
Browsing all 31 articles
Browse latest View live

M: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 Article


Does 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 Article


Image may be NSFW.
Clik here to view.

Composite 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 Article

What 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 Article

What 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 Article


Image may be NSFW.
Clik here to view.

Natural 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 Article

Should 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 Article

If 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 Article


Insert 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 Article


How 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 Article

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 Article
Browsing all 31 articles
Browse latest View live