Alex Rivera | Logout

Will SQL Server 2005 penalize me for using an nvarchar(50) as a primary key, instead of an integer?

Asked 2008-10-22T05:40:23.157
12

I'm considering altering some tables to use nvarchar(50) as primary key instead of an int primary key. Using an int ID for a key really is irrelevant data, it's the string I'm interested in. What sort of performance hit will occur, or where do you research this? Other than cut and try that is.

Edit
Report

1 Answer

26

You have hit upon one of the major "holy wars" of database design. The debate you're referring to is the "surrogate vs. natural key" argument that's been raging for as long as there have been RDBMSs (as nearly as I can tell).

The debate essentially boils down to whether a representative key (surrogate, for example an IDENTITY column) should be used versus using the actual data that uniquely describes a record (natural key).

I will say that there is no "right" answer. Performance measures are an artifact of the platform, and should be assessed by experimentation, but performance is not likely to be the major concern.

What I consider to be the primary argument for surrogate keys is the immutability of primary keys. If you choose to use a natural key, you give up the option of altering that key after it is established. You also give up the possibility that it may become non-unique at some point in the future. For those reasons, I typically (not always) use surrogate keys for most of my tables.

However, as I mentioned, there is a very long-standing debate filled with discussions of indexing strategies and normal-form adherance to be read if you are so inclined.

I would Google "surrogate vs. natural keys". Here are a few links to get you started:

Systems Engineering and RDBMS

Techrepublic

Tony Rogerson's blog

Hope this helps.

answered 2008-10-22T05:54:42.100

Your Answer