A GUID, (which may be pronounced goo-id or gwid), is a globally unique identifier.
The guid is a sequence of hexademical digits and looks something like this:
I’ve heard developers say that it is unique world-wide, yep, globally. But is it? I decided to do some research and find out based on other’s experience. Wikipedia
says “While each generated GUID is not guaranteed to be unique, the total number of unique keys (2128 or 3.4×1038) is so large that the probability of the same number being generated twice is very small.”
Hmm. Okay. But how about real-world experience? I am still skeptical. I find this sentence about GUIDs in an article by Scott Mitchell
. A reader of Scott’s, Rusty Alderson, shares:
"In creating very large databases, GUIDs (as generated by MS's NEWID() function) WILL have collisions, or duplicates. In a previous project where I was building a large Customer ODS (Operational Data Store), I typically found about 4 collisions per million rows. Code has to be developed to handle this. This was in SQL Server 2000. Perhaps SQL Server 2005 has remedied this."
So there you have it. GUIDs are not globally unique. So now that we are in SQL Server 2008, what’s the verdict? Anyone working with millions of rows having collisions?
Here is a great example of working with stored procedures in your asp.net code.
In this article by Scott Mitchell, you will find an example of how to create a stored procedure using SQLServer. This stored procedure, sproc_UpdateUsersCurrentActivity, also checks if a row exists, and if so updates, otherwise inserts. It also handles rollback for errors.
Scott also demonstrates how to use the CommandType.StoredProcedure and how to add parameters.
Following the first example, there is yet another stored procedure example that performs a select statement: sproc_GetUsersCurrentActivity. This demonstrates how to pass in 3 input parameters. Scott then demonstrates how to attach the results of the stored procedure to a Gridview.
The article is titled Examining ASP.NET's Membership, Roles, and Profile - Part 10, but provides examples for working with stored procedures that are invaluable for the new developer.