Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Generate auto row number for a table

, 28 Sep 2011
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)

About the Author

YSLGuru

United States United States
No Biography provided

Comments and Discussions

 
GeneralRe: 1. I said an identity int field is a great PK, not a guid. 2... PinmemberKP Lee3-Oct-11 22:34 
GeneralI beg to differ. Uniqueidentifier was originally DESIGNED to... PinmemberKP Lee30-Sep-11 17:55 
GeneralRe: No offense intended but your wrong about this being a great ... PinmemberYSLGuru3-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 | Mobile
Web01 | 2.8.140709.1 | Last Updated 28 Sep 2011
Article Copyright 2011 by YSLGuru
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid