How to Create Table Auto Increments in MySQL

How to Create Table Auto Increments in MySQL thumbnail
Maintain your database structure with MySQL code.

MySQL is a freely distributed relational database used on various platforms, including UNIX, Windows and Mac. You can create a MySQL application using most popular languages, such as Java, C++ and PHP. The MySQL language enables you to construct and modify tables. Use the MySQL Auto_Increment method to create an auto increment value for your table, such as for a primary key.

Instructions

    • 1

      Open your MySQL table code and locate the table creation portion:

      CREATE TABLE products (

      ID MEDIUMINT NOT NULL,

      UNAME CHAR(20) DEFAULT '' NOT NULL,

      PRIMARY KEY(ID)

      );

    • 2

      Type "AUTO_INCREMENT" in the primary key (ID) definition. Modify this code as needed to fit your data:

      CREATE TABLE products (

      ID MEDIUMINT NOT NULL AUTO_INCREMENT,

      UNAME CHAR(20) DEFAULT '' NOT NULL,

      PRIMARY KEY(ID)

      );

    • 3

      Save the table modifications. The table "ID" field automatically increments.

Related Searches:

References

Resources

  • Photo Credit Pixland/Pixland/Getty Images

Comments

Related Ads

Featured