2013-02-26 82 views
-2

我得到這個錯誤,而試圖在一個數據庫中創建一個表的表..MySQL錯誤試圖創建與現場

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL, `call_code_id` INT(11) UNSIGNED NOT NULL, `result_code` ENUM NOT NULL,' at line 1 

我在做什麼wront這給我一個錯誤? 這是我的mysql代碼。

CREATE TABLE `phone_calls` (

`phone_call_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , 
`account_id` INT(11) UNSIGNED NOT NULL , 
`team_id` INT(11) UNSIGNED NOT NULL , 
`campaign_id` INT(11) UNSIGNED NOT NULL , 
`call_code` ENUM NOT NULL , 
`call_code_id` INT(11) UNSIGNED NOT NULL , 
`result_code` ENUM NOT NULL , 
`result_code_id` INT(11) UNSIGNED NOT NULL , 
`time_zone_id` INT(11) UNSIGNED NOT NULL , 
`trigger_on` DATETIME NOT NULL , 
`created_on` DATETIME NOT NULL , 
`first_attempt_on` DATETIME NOT NULL , 
`first_attempt_by` INT(11) UNSIGNED NOT NULL , 
`first_attempt_by_name` CHAR(30) NOT NULL , 
`call_subject` CHAR(50) NOT NULL , 
`status` TINYINT(2) NOT NULL COMMENT '0= purge, 1=active, 2 = in progress, 3 = completed', 
`last_attempt_on` DATETIME NOT NULL , 
`last_attempt_by` INT(11) UNSIGNED NOT NULL , 
`last_attempt_by_name` CHAR(30) NOT NULL , 
`total_attempts` TINYINT(3) NOT NULL DEFAULT '0', 
`modified_by` INT(11) UNSIGNED NOT NULL , 
`modified_by_name` CHAR(30) NOT NULL , 
`client_id` INT(11) UNSIGNED NOT NULL , 
`last_call_id` INT(11) UNSIGNED NOT NULL , 
`call_direction` ENUM NOT NULL COMMENT 'INBOUND or OUTBOUND', 
`call_notes` TEXT NOT NULL , 
INDEX ( `account_id` , `team_id` , `campaign_id` , `call_code` , `call_code_id` , `result_code` , `result_code_id` , `time_zone_id` , `first_attempt_by` , `last_attempt_by` , `modified_by` , `client_id` , `last_call_id`) 
) ENGINE = MYISAM 

非常感謝您的時間:)

+0

又該空ENUM是什麼意思?您忘記指定枚舉本身,如[本頁]所示(http://dev.mysql.com/doc/refman/5.0/en/enum.html)。 – raina77ow 2013-02-26 18:04:46

回答

0

您需要定義每個enum列的可能值,如下所示:

CREATE TABLE `phone_calls` (
`phone_call_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , 
`account_id` INT(11) UNSIGNED NOT NULL , 
`team_id` INT(11) UNSIGNED NOT NULL , 
`campaign_id` INT(11) UNSIGNED NOT NULL , 
`call_code` ENUM('foo','bar') NOT NULL , 
`call_code_id` INT(11) UNSIGNED NOT NULL , 
`result_code` ENUM('foo','bar') NOT NULL , 
`result_code_id` INT(11) UNSIGNED NOT NULL , 
`time_zone_id` INT(11) UNSIGNED NOT NULL , 
`trigger_on` DATETIME NOT NULL , 
`created_on` DATETIME NOT NULL , 
`first_attempt_on` DATETIME NOT NULL , 
`first_attempt_by` INT(11) UNSIGNED NOT NULL , 
`first_attempt_by_name` CHAR(30) NOT NULL , 
`call_subject` CHAR(50) NOT NULL , 
`status` TINYINT(2) NOT NULL COMMENT '0= purge, 1=active, 2 = in progress, 3 = completed', 
`last_attempt_on` DATETIME NOT NULL , 
`last_attempt_by` INT(11) UNSIGNED NOT NULL , 
`last_attempt_by_name` CHAR(30) NOT NULL , 
`total_attempts` TINYINT(3) NOT NULL DEFAULT '0', 
`modified_by` INT(11) UNSIGNED NOT NULL , 
`modified_by_name` CHAR(30) NOT NULL , 
`client_id` INT(11) UNSIGNED NOT NULL , 
`last_call_id` INT(11) UNSIGNED NOT NULL , 
`call_direction` ENUM('foo','bar') NOT NULL COMMENT 'INBOUND or OUTBOUND', 
`call_notes` TEXT NOT NULL , 
INDEX (`account_id` , `team_id` , `campaign_id` , `call_code` , `call_code_id` , `result_code` , `result_code_id` , `time_zone_id` , `first_attempt_by` , `last_attempt_by` , `modified_by` , `client_id` , `last_call_id`) 
) ENGINE = MYISAM 

參見:http://dev.mysql.com/doc/refman/5.0/en/enum.html

+0

謝謝你的作品 – Jaylen 2013-02-26 19:08:22

1

您的ENUM定義不正確,檢查:

Documention

我敢肯定,你可以在那裏找到答案:)

+0

謝謝。知道了 – Jaylen 2013-02-26 19:07:44