Home > database >  how to set ID start from 10000 or any 5 digit number in SQL and C#?
how to set ID start from 10000 or any 5 digit number in SQL and C#?

Time:08-12

I have table called 'users'.

user_id
user_name
user_password 

The user_id column start from 1. Is there any way to start from 10000 or any 5-digit number?

Note : I user SQL in my C# Program.

CodePudding user response:

When defining the table, you can use

Create Table Users
(
  user_id int IDENTITY(10000,1),
  ...
)

or if the table is already defined with rows in it, then you can use

DBCC CHECKIDENT ('table_name', RESEED, new_value);

where new_value is whatever number you need to start with again.

CodePudding user response:

Don't do it.

The primary key of a table should only ensure row uniqueness, and should not convey any information about the data. Its "form" should be of no consequence.

You probably need to ask yourself why do I want specific values? If you want to expose them in the UI, or send it to an external related application, then you may be better off creating a secondary [auto-]generated column just for this purpose. I would strongly recommend you leave the PK alone and don't touch it.

  • Related