Click here to Skip to main content
11,647,828 members (60,096 online)
Click here to Skip to main content

Tagged as

Generate auto row number for a table

, 28 Sep 2011 CPOL 3.8K 1
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

YSLGuru
United States United States
No Biography provided

You may also be interested in...

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
memberKP Lee3-Oct-11 22:34 
GeneralI beg to differ. Uniqueidentifier was originally DESIGNED to... Pin
KP Lee30-Sep-11 17:55
memberKP Lee30-Sep-11 17:55 
GeneralRe: No offense intended but your wrong about this being a great ... Pin
YSLGuru3-Oct-11 7:58
memberYSLGuru3-Oct-11 7:58 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150804.4 | Last Updated 28 Sep 2011
Article Copyright 2011 by YSLGuru
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid