- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to make a primary key start from 1000?
To make a primary key start from 1000, you need to alter your table and set to auto_increment with value 1000. The syntax is as follows −
alter table yourTableName auto_increment=1000;
To understand the above syntax, let us first create a table. The query to create a table is as follows −
mysql> create table PrimaryKey1000Demo -> ( -> ProductId int auto_increment, -> PRIMARY KEY(ProductId) -> ); Query OK, 0 rows affected (0.56 sec)
Now here is the query that will update the primary key to start from 1000 −
mysql> alter table PrimaryKey1000Demo auto_increment=1000; Query OK, 0 rows affected (0.20 sec) Records: 0 Duplicates: 0 Warnings: 0
Now we have updated the start value to begin from 1000. Let us now insert some records to check the starting value of primary key. The query to insert record is as follows −
mysql> insert into PrimaryKey1000Demo values(); Query OK, 1 row affected (0.11 sec) mysql> insert into PrimaryKey1000Demo values(); Query OK, 1 row affected (0.19 sec) mysql> insert into PrimaryKey1000Demo values(); Query OK, 1 row affected (0.23 sec) mysql> insert into PrimaryKey1000Demo values(); Query OK, 1 row affected (0.08 sec)
Display all records from the table using a select statement. The query is as follows −
mysql> select *from PrimaryKey1000Demo;
The following is the output displaying ProductID, our primary key to begin from 1000 −
+-----------+ | ProductId | +-----------+ | 1000 | | 1001 | | 1002 | | 1003 | +-----------+ 4 rows in set (0.00 sec)
- How to make MySQL table primary key auto increment?
- How to remove primary key from MongoDB?
- How to create an INT field (not a primary key) that begins at 1000 with auto_increment in MySQL?
- Primary key Vs Unique key
- Can we remove a primary key from MySQL table?
- Can we use PRIMARY KEY( column1, column2) in MySQL to make pairs?
- How to change a primary key in MySQL to auto_increment?
- How can I define a column of a MySQL table PRIMARY KEY without using the PRIMARY KEY keyword?
- Difference between Primary Key and Candidate key
- Difference between Primary Key and Unique key
- How to get primary key of a table in MySQL?
- How to update DB2 table with a duplicate primary key?
- How do I drop a primary key in MySQL?
- Remove Primary Key in MySQL?
- Reset Primary Key in MySQL