What is GUID and how to generate it in SQL Server?

GUID:

GUID (Globally Unique Identifier) is a 128 bit unique number which is generated by Operating system automatically. This number is globally unique and can not be generated the same number in any other computer in the entire world. Identity key in a table generates unique number in that particular table. There is chance that we can find the same number in other tables. But GUID never be repeated in any other table or database or computer in the entire world.

               For example, If we consider a motor cycle, it will have a unique number registered to it. But this number might be repeated for some other product in some other country. But GUIDs are not like that. We can use GUIDs for anything in the world since no one can generate the same number which we have generated.

Ex: 

3C23D051-8FEA-4E40-BFCE-DB1C20FE8B78

63D03E22-A0E9-4269-859C-76CEBB017EE9

73E0D38C-D7CC-4C62-8E1B-D1CDE21FCB09

Real time usage of GUIDs:

  • Unique IDs for products in a shopping mall
  • Primary keys in databases
  • For generating Unique customer IDs of an organization
  • For generating files with unique names etc…

GUIDs in SQL Server are generated by using NEWID() function.

————————
SELECT NEWID()
————————

GUID

For more info: Click here

Happy Reading :)

Tags:,

Leave a Reply

Your email address will not be published. Required fields are marked *