mysql將id重新排列的方法:1、使用column計(jì)數(shù)【alter table tablename drop column id】;2、使用increment排列【alter table tablenam auto_increment】。
mysql將id重新排列的方法:
使用mysql時(shí),通常表中會有一個自增的id字段,但當(dāng)我們想將表中的數(shù)據(jù)清空重新添加數(shù)據(jù)時(shí),希望id重新從1開始計(jì)數(shù),用以下兩種方法均可:
方法一:
alter table tablename drop column id; alter table tablename add id mediumint(8) not null primary key auto_increment first;
方法二:
alter table tablename auto_increment=0
方法二不會清空已有數(shù)據(jù),操作比較靈活,不僅可以將自增值歸零,也適用于刪除大量連續(xù)行后,重新設(shè)置自增值并插入新的數(shù)據(jù);或從新的值開始,當(dāng)然不能和已有的沖突。
$sql="delete from $table_vote"; mysql_query($sql, $link); $sql="alter table $table_vote auto_increment=1"; mysql_query($sql, $link);