Click here to Skip to main content
15,887,854 members
Articles / Web Development / ASP.NET
Alternative
Tip/Trick

Generate auto row number for a table

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
28 Sep 2011CPOL 11.7K   1   3
If you have the ability to change it, you may want to consider moving away from the 36 digit alphanumeric created by GUID() as a Key. This is often misused in SQL-Server by developers who have not had proper training/education in SQL Server and or RDBMS. The GUID() is not intended to be a...

If you have the ability to change it, you may want to consider moving away from the 36 digit alphanumeric created by GUID() as a Key. This is often misused in SQL-Server by developers who have not had proper training/education in SQL Server and or RDBMS. The GUID() is not intended to be a Primary Key but a way to generate a unique value when working across multiple systems. Most databases are not setup like this, they are self-contained. Even if they are using data from outside sources, they still are self-contained in that all their tables are in a single DB on a single SQL Server instance. While using the GUID() will create a unique value, it carries overhead with it that makes it a non-optimal choice for a Primary Key when you don’t need to create a unique value that is unique across all databases on all your systems.


As for how to generate a unique key, if you are using SQL Server as your tag as your post indicates, you can let SQL Server do this for you by setting the column of the table that is your primary key to auto-increment a unique value.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: 1. I said an identity int field is a great PK, not a guid. 2... Pin
KP Lee3-Oct-11 22:34
KP Lee3-Oct-11 22:34 
GeneralI beg to differ. Uniqueidentifier was originally DESIGNED to... Pin
KP Lee30-Sep-11 17:55
KP Lee30-Sep-11 17:55 
GeneralRe: No offense intended but your wrong about this being a great ... Pin
YSLGuru3-Oct-11 7:58
YSLGuru3-Oct-11 7:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.