mysql設置主鍵自增 如何設置mysql主鍵自動增長?
如何設置mysql主鍵自動增長?創(chuàng)建表時,設置主鍵自增長(主鍵必須是整數(shù)才能自增長):create table stu(SID int primary key auto)遞增,sname,tvarch
如何設置mysql主鍵自動增長?
創(chuàng)建表時,設置主鍵自增長(主鍵必須是整數(shù)才能自增長):create table stu(SID int primary key auto)遞增,sname,tvarchar(20),age,t,int,gender,tvarchar(10)xunset修改表時主鍵自增長:alter table stu change Sid int Autouincrement<刪除修改表時主鍵自增長:alter table stu change Sid int
只定義Autouincrement不能處理。
mysql> CREATE TABLE tab(
-> id INT AUTOu1075(42000)錯誤:表定義不正確只能有一個自動列,必須將其定義為鍵!此問題與特定的業(yè)務場景和技術實現(xiàn)有關:
1。業(yè)務場景:如訂單、付款單等敏感字段不能自動添加。它們是具有高安全級別的字段,需要一個唯一的ID作為主鍵。
2. 技術實現(xiàn):在實際開發(fā)過程中,批量導入或處理數(shù)據(jù)時,需要考慮技術實現(xiàn)的性能,因此需要從多方面驗證是使用自增主鍵還是非自增主鍵。