Tuesday, 23 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