Mysql -- Automatic growth, mysql -- Growth

Source: Internet
Author: User

Mysql -- Automatic growth, mysql -- Growth

Create table teacher (
T_id int primary key auto_increment,
# Auto_increment automatic growth requires an integer type and an index
T_name varchar (20 ),
T_class varchar (20 ),
Days tinyint unsigned
);

 

# Set the starting value of automatic growth, and the inserted data will automatically grow from 10
Alter table tab_name auto_increment 10;


# Manually insert a large id. If the id data in the current table does not exceed 21, you can insert a data with the id of 21.
Insert into t1 values (21, 'lily', '20140901', 23 );
# After inserting a data entry with id 21, manually insert a data entry. If t_id is not inserted manually, t_id will be inserted from 22.
 

# If you delete data with t_id 21 and 22 again, and then manually insert a data record (t_id is not manually inserted), The t_id is inserted starting from 23.

 

# If you manually delete data with t_id 21 and 22, use alter table t1 auto_increment 10;
# In this way, manual data insertion will automatically increase from 10
 
If you do not delete data with t_id = 10 and directly set the auto-increment value t_id to 5, the auto-increment will not start from 5 and will start from the maximum value of t_id in the current data table.
 

 


How to set the initial value for fields automatically added by mysql?

Alter table table_name AUTO_INCREMENT = n references ej38.com/showinfo/mysql-202971.html
 
In mySQL, how does one change the column to auto-increment? Urgent !!!

Alter table questionlib modify id int (11) auto_increment;
This should be fine. After modification, it will automatically grow from the next record.
If you want to make the original Automatic growth, You have to copy the structure of the existing table (without id), add the id and add AUTO_INCREMENT, and then add n null records through the loop, then insert data in sequence based on the id of the previous table.
It is troublesome to associate with other tables.

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.