简体   繁体   中英

MySQL ALTER TABLE AUTO_INCREMENT and ORDER BY

I would like alter my table so that the table is sorted alphabetically as well as then reset my AUTO_INCREMENT Field (prof_id).

Attached is the database structure. The Foreign Key in 'my_contacts' is still NULL.

I have run an "ALTER TABLE profession ORDER BY profession"

在此处输入图片说明

I would like alter my table so that the table is sorted alphabetically

That's strange and doesn't happen that way. You should rather get the sorted/ordered data while doing a SELECT statement using an ORDER BY clause like below

select * from profession order by profession;

Again I would suggest, change you column name different than the table name. In your case, table name and column name both the profession .

then reset my AUTO_INCREMENT Field (prof_id).

Not sure why you would want to reset the PK field; anyways you can do the same using an ALTER statement like

ALTER TABLE profession AUTO_INCREMENT = 1;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM