2016-01-21 166 views
0

我已經通過互聯網瞭解不太好的結果。更改主鍵和自動增量

這裏是我的表:

+------------------+---------+------+-----+---------+----------------+ 
| Field   | Type | Null | Key | Default | Extra   | 
+------------------+---------+------+-----+---------+----------------+ 
| jobid   | int(11) | NO | PRI | NULL | auto_increment | 
| locid   | int(11) | YES |  | 0  |    | 
| userid   | int(11) | YES |  | 0  |    | 
| createdate  | int(11) | YES |  | 0  |    | 
| jobapplicationid | int(11) | YES |  | NULL |    | 
+------------------+---------+------+-----+---------+----------------+ 
5 rows in set (0.00 sec) 

我想改變自動增量的主鍵從原來的作業ID

我已經試過alter table jobs_applications drop primary key jobid沒有成功jobapplicationid。

任何幫助將不勝感激。

+0

您是否嘗試過使用像HeidiSQL這樣的軟件? – Dave

+0

@Dave我正在尋找一個基本的sql命令解決方案 – jkushner

+0

你的意思是沒有成功嗎?發佈錯誤消息有很大幫助 –

回答

0
-- remove pk 
ALTER TABLE `jobs_applications` DROP PRIMARY KEY; 
-- remove auto inc 
ALTER TABLE `jobs_applications` CHANGE `jobid` `jobid` INT(11) UNSIGNED NOT NULL; 
-- set pk and auto inc to the other column 
ALTER TABLE `jobs_applications` CHANGE `jobapplicationid` `jobapplicationid` INT(11)AUTO_INCREMENT PRIMARY KEY;