Neeraj Mehta
Neeraj Mehta

Reputation: 1705

Creating a custom Serial Number in Primary Key in mvc4

I am building a website in mvc4 and i want to ask that as i am registering a new user than the user-profile table automatically updated with user-id as auto increment in the 1,2,3,4,5,...sequence but i want this primary key to auto-increment in some other way such as psk1,psk2,psk3...................can i have this ?? if Yes how it is possible?

I have try using custom membership provider but i am not successful by using that method so can any one have better option other than this?

Upvotes: 0

Views: 720

Answers (1)

Pantelis Natsiavas
Pantelis Natsiavas

Reputation: 5369

I can think of three ways of creating unique primary keys

  • Autoincrement by identity.

This is the method that you are already familiar with, leading to automatic generation of primary keys of type 1,2,3,....

  • Using UUID.

This is a global unique identified which you can create in .NET and pass it as value in your database record.

  • Custom creation of primary key

If there is a special need, you could set your data table column to be primary Key of type varchar and create either in the .NET domain, or in the SQL server using a trigger. There, you could find the last inserted ID, parse it, increment the integer part and form the new unique primary key. .

Hope I helped!

Upvotes: 1

Related Questions