William
William

Reputation: 3

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

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.

Upvotes: 0

Views: 1382

Answers (2)

The Impaler
The Impaler

Reputation: 48810

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.

Upvotes: 0

Pradeep Prabhu
Pradeep Prabhu

Reputation: 145

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.

Upvotes: 4

Related Questions