Wednesday, November 25, 2015

What is an uniqueidentifier?

 Unique Identifiers are used in many places, SQL Server's data type; as GUID in ActiveX Controls, and as a 128 bit IP address in IPV6 although it is not called GUID. Using 128 bits for the IP address makes it possible to assign a whole lot more addresses than IPV4.

Uniqueidentifiers are also called GUIDs(Globally Unique Identifier) which are unique and different from any other. It was introduced in SQL Server 7.0. The GUID is obtained by the function call NewID()or as a hexadecimal formatted string. The unique identifier data type is stored in the computer as a 16-byte (128 bits) binary value. The formatted GUID using Hexadecimal is usually a string represented by groups separated by hyphens:
4bytes-2bytes-2bytes-2bytes-6bytes
Here is how the uniqueidentifier obtained by calling the NewID() function.
---
Declare @myid uniqueidentifier
set @myid=NEWID()

---
A uniqueidentifier is obtained every time this function is called as shown here:



While it is great for security, it takes up too much space (think of millions of rows with a uniqueidentifier data type column).

More about uniqueidentifier in SQL Servers here.

No comments: