filmov
tv
UniqueIdentifier, Guid, Newid, NewSequentialid in SQL Server
Показать описание
Uniqueidentifiers are also referred to as GUIDs. (Globally Unique IDentifier). That is, the API call that returns a GUID is guaranteed to always return a unique value across space and time. Its related to MAC address based On network card and the system time.
The uniqueidentifier data type in SQL Server is stored natively as a 16-byte binary value. We can get a Guid from NewID() or NewSequentialID()
NEWID() - randomly generates a guaranteed unique value based on the identification number of the server's network card plus a unique number from the CPU clock. We can use this in Insert, Select Statement.
NEWSEQUENTIALID() - generates these values in sequential order as opposed to randomly. We can use this in Create Statement default value and We can’t use in Insert, Select Statement
The major advantage of using GUIDs is that they are unique across all space and time. This comes in handy if you're consolidating records from multiple SQL Servers into one table, as in a data warehousing situation. GUIDs are also used heavily by SQL Server replication to keep track of rows when they're spread out among multiple SQL Servers
The main disadvantage to using GUIDs as key values is that they are BIG. At 16 bytes a pop, they are one of the largest datatypes in SQL Server. Indexes built on GUIDs are going to be larger and slower than indexes built on IDENTITY columns, which are usually ints (4 bytes)
Комментарии