In
this article I am going to explain how to set auto incremented, auto generated alphanumeric
unique ID in sql server.
In
the previous article I have explained how to combine 2 or more columns into onecolumn in SQL server, show and hide ondropdown selection using Jquery, how to calculate total number of days betweentwo dates in asp.net and how to show and hide the div on button click using Jquery.
Description:
I
want to generate alphanumeric auto generated unique code for users. As you know
primary key is always unique.
Implementation:
To
generate unique code I have add new column to table. I have create a table Users
create TABLE [dbo].[Users](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Firstname] [varchar](50) NULL,
[Middlename] [varchar](50) NULL,
[Lastname] [varchar](50) NULL,
[Phonenumber] [int] NULL,
[City] [varchar](50) NULL,
[usercode] AS ('user' + right(('00000' + convert(varchar(5),[id])),5)) ,
) ON [PRIMARY]
Usercode column represent
the alphanumeric auto generated column. Now insert some dummy record into the
table to test it.
0 Comments