How MySQL lets the self ID set the method starting from 1

Source: Internet
Author: User
Tags numeric value table name

Like what:

The code is as follows Copy Code
TRUNCATE TABLE table1

TRUNCATE table table1 (table name) or this can also be:

The code is as follows Copy Code

ALTER TABLE table_name AUTO

Method Two

Will not empty the existing data, the operation is more flexible, not only can return to zero, but also for the deletion of a large number of consecutive rows, reset the value and insert new data, or starting from the new value, of course, can not and existing conflicts.

The code is as follows Copy Code

$sql = "Delete from $table _vote";
mysql_query ($sql, $link);
$sql = "ALTER TABLE $table _vote auto_increment=1";
mysql_query ($sql, $link);

MySQL Database unique number field (AutoNumber field)
In database applications, we often use a unique number to identify the record. Auto_increment Properties of data columns available in MySQL

From dynamic generation. MySQL supports a variety of data tables, each of which has a different properties of the data table, which will introduce the data in various tables

Column self-increasing property.

ISAM table

If you insert a null into a auto_increment data column, MySQL automatically generates the next sequence number. Number is open from 1

Beginning, and 1 for cardinality increment.

The effect of inserting 0 into a auto_increment data column is the same as inserting a null value. This is not recommended, however, or it is better to insert a null value.

When you insert a record without explicitly specifying a value for Auto_increment, the equivalent is to insert a null value.

When you insert a record, if you explicitly specify a numeric value for the auto_increment data column, there are two situations where, if

The inserted value repeats with the existing number, and an error message occurs because the value of the Auto_increment data column must be unique;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.