IMG-LOGO

How to generate new Guid in TSQL?

andy - 16 Feb, 2021 3247 Views 0 Comment

GUID stands for Globally Unique Identifier. It is a universally unique id using a pseudo-random 128-bit number. GUIDs are mostly used to replace as another alternative or replacement of integer value. It is preferable to compare with numbers because it is unique across tables, databases, and servers. The drawback is it contains 4 times larger than the traditional 4-byte index value.

To generate a GUID value in TSQL. You can use the built-in function called NEWID().

Here is the TSQL query to generate a new GUID in SQL Server.


SELECT NEWID() As GUIDVALUE

Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.

Related Articles

How to restore database using SQL query in TSQL?

If you have a database backup bak file extension and want to restore it using SQL query You can use the built in RESTORE DATABASE function Remember in order to be able to restore a database successfully You need to ...

How to get all table sizes in TSQL?

To get the information about how much space or size used by tables You can retrieve the size information by linking multiple tables in sys tables There are two tables that hold this information The first one is the sys ...