0

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.

Charlieface
  • 52,284
  • 6
  • 19
  • 43
William
  • 3
  • 2
  • 1
    Does this answer your question? [Set start value for column with autoincrement](https://stackoverflow.com/questions/1280705/set-start-value-for-column-with-autoincrement) – Orel Eraki Aug 12 '22 at 09:26
  • And how database is created? Are you using EF Code First? Or any other ORM? – Guru Stron Aug 12 '22 at 09:29
  • 2
    [Why should I "tag my RDBMS"?](https://meta.stackoverflow.com/questions/388759/why-should-i-tag-my-rdbms) - please add a tag to specify whether you're using `mysql`, `postgresql`, `sql-server`, `oracle` or `db2` - or something else entirely. – marc_s Aug 12 '22 at 09:32

2 Answers2

4

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.

Charlieface
  • 52,284
  • 6
  • 19
  • 43
0

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.

The Impaler
  • 45,731
  • 9
  • 39
  • 76
  • What if I want to generate 5-digit invoice number like 00001 , 00002 and ...? how to create secondary auto-generated column? Thanks. – William Aug 12 '22 at 18:09