How to Set Auto Increment Value In MySQL

How to Set Auto Increment Value In MySQL thumbnail
MySQL helps you maintain your customer data.

MySQL is a free and widely-used database that runs on a variety of platforms, including Windows, Unix and Mac. Popular languages are supported, allowing you to create an application that utilizes MySQL whether you desire to use C++, Java or PHP. MySQL provides the language for you to create and modify a table, which includes the syntax to set an automatic increment value. This is useful for generating table primary keys.

Instructions

    • 1

      Access your MySQL table and go to the portion where you created your table. It should resemble this:

      CREATE TABLE customers (

      ident MEDIUMINT NOT NULL,

      NAME CHAR(20) DEFAULT '' NOT NULL,

      PRIMARY KEY(ident)

      );

    • 2

      Insert the text "AUTO_INCREMENT" on the primary key "ident" line. Change the code for your specific table accordingly.

      CREATE TABLE customers (

      ident MEDIUMINT NOT NULL AUTO_INCREMENT,

      NAME CHAR(20) DEFAULT '' NOT NULL,

      PRIMARY KEY(ident)

      );

    • 3

      Save your database changes. The table will increment the "ident" field automatically.

Related Searches:

References

Resources

  • Photo Credit Jupiterimages/Creatas/Getty Images

Comments

You May Also Like

Related Ads

Featured