2016-10-13 73 views
0

我正在使用MySQL Workbench 6.3。我有一個兩列id和成分的表。但是id值沒有正確插入。檢查圖像以供參考。我曾經嘗試都低於查詢mysql表中的數字沒有以正確的順序插入

create table ingredients(id int(6) primary key not null, ingredient varchar(30) not null unique); 

create table ingredients(id int(6) primary key not null auto_increment, ingredient varchar(30) not null unique); 

但輸出是same.id列值犯規進來順序。 id列的截圖:

enter image description here

+2

通過ID子句添加以查詢。 – Shadow

+0

請嘗試使用'VARCHAR(255)',除非您有一個非常有說服力的理由來限制其他情況。 'VARCHAR(30)'不保存任何空間,它只會產生潛在的截斷錯誤。同樣,使用'INT'作爲默認值,而不是像'INT(6)'這樣的古怪變體。 – tadman

回答

0

這些行是任意的,雖然它們通常它可能在插入訂單的訂單。如果你希望他們在一些特定的順序:

SELECT * FROM ingredients ORDER BY id 
0
Select * From ingredients 
Order By id; 

ORDER BY子句將查詢結果進行排序。他們將按照升序默認退還,如果你希望他們按降序排列,把遞減列名後:

Order By id Desc; 
相關問題