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.