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 *

How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site
%d bloggers like this: