Wednesday, 24 December 2014

How to automatically generate unique id in sql?

In sql there are many options to generate unique number. Here I am explaining about how to generate standard unique number in sql.

Below is sql query :

CREATE TABLE dbo.tblTable1
  (ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED,
   UserID AS UID + RIGHT(00000000 + CAST(ID AS VARCHAR(8)), 8) PERSISTED,
   username varchar(200),city varchar(200)
  )

No comments:

Post a Comment

Dear Readers, Please post your valuable feedback in the comment section if you like this blog or if you have any suggestions. I would love to hear the same from you. Thanks