
This MySQL AUTO_INCREMENT example would change the next value in the AUTO_INCREMENT field (ie: next value in the sequence) to 50 for the contact_id field in the contacts table. Run the following CREATE statement to create a table named students where id field will be created with auto-increment.
#Mysql create table with autoincrement how to
Let's look at an example of how to change the starting value for the AUTO_INCREMENT column in a table in MySQL.įor example: ALTER TABLE contacts AUTO_INCREMENT = 50 start_value The next value in the sequence to assign in the AUTO_INCREMENT column. You do not need to specify the name of the column that contains the AUTO_INCREMENT value. Since a table in MySQL can only contain one AUTO_INCREMENT column, you are only required to specify the table name that contains the sequence. In MySQL, the syntax to change the starting value for an AUTO_INCREMENT column using the ALTER TABLE statement is: ALTER TABLE table_name AUTO_INCREMENT = start_value table_name The name of the table whose AUTO_INCREMENT value you wish to change. You can use the ALTER TABLE statement to change or set the next value assigned by the AUTO_INCREMENT. Now that you've created a table using the AUTO_INCREMENT attribute, how can you change the starting value for the AUTO_INCREMENT field if you don't want to start at 1?



Let's look at an example of how to use a sequence or the AUTO_INCREMENT attribute in MySQL.
