How to Make Primary Key start from user defined number – MySQL

While your are creating the structure for table just add the AUTO_INCREMENT = YOUR_DEFINED_NUMBER.

Doing this your Primary Key will set and start are from YOUR_DEFINED_NUMBER.

 

CREATE TABLE `user` (
`id` bigint(20) NOT NULL,
`username` varchar(150) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`referer_info` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`url` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`country_code` varchar(50) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`event_data` longtext COLLATE utf8mb4_unicode_520_ci
) ENGINE=MyISAM DEFAULT AUTO_INCREMENT = 2500;

 

If your table has already been created with an auto-increment. so you can use Alter table query.

 

ALTER TABLE your_table_name AUTO_INCREMENT = 2500;

 

Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.
Yes0
No0
Harinder Singh

Harinder Singh

My name is Harinder Singh and I specialize in Software industry. I consider myself as a life learner. I love learning new concepts, embracing new ideas and reading and searching for innovation.