How to auto-generate unique-identifier column in Sql?

How to auto-generate unique-identifier column in Sql?

SQL SERVER
SQL SERVER

Hello everyone, In this article lets see the sample code that can help you auto-generate the unique-identifier in sql server.

create table Table
(
	Id uniqueidentifier primary key not null default newid(),
	Name nvarchar(50) not null, 
	Email nvarchar(50) null
)

The above sql query creates the table named dbo.Table with 3 columns Id, Name and Email where the Id is unique-identifier and has auto-generated guid values in them.

Id uniqueidentifier primary key not null default newid()

In this case, the Id can have some user input values, however, if not passed, it creates the new guid value by the help of newid() function in sql.

Leave a Reply

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

Please disable your adblocker or whitelist this site!

%d bloggers like this: