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.