使用查询在表中插入多个列错误

时间:2014-12-02 03:34:38

标签: mysql

这是我的疑问:

ALTER TABLE  `mytable` ADD  
`telephone` VARCHAR( 50 ) NOT NULL,
`date_of_annual_health_care_plan` DATE NOT NULL,
`first_language` VARCHAR ( 50 ) NOT NULL,
`interp_req` INT NOT NULL,
`religion` VARCHAR ( 50 ) NOT NULL,
`religious_considerations` VARCHAR ( 350 ) NOT NULL,
`diagnosis_and_associated_health_conditions` VARCHAR ( 500 ) NOT NULL,
`communcation` VARCHAR ( 350 ) NOT NULL,
`challenging_behaviours` VARCHAR ( 350 ) NOT NULL,
`medicare_number` VARCHAR ( 50 ) NOT NULL,
`pension_number` VARCHAR ( 50 ) NOT NULL,
`private_health_insurance` VARCHAR ( 50 ) NOT NULL,
`person_responsible` INT NOT NULL,
`person_res_name` VARCHAR ( 50 ) NOT NULL,
`person_res_address` VARCHAR ( 50 ) NOT NULL,
`person_res_telephone_h` VARCHAR ( 50 ) NOT NULL,
`person_res_telephone_w` VARCHAR ( 50 ) NOT NULL,
`person_res_telephone_m` VARCHAR ( 50 ) NOT NULL,
`person_res_email` VARCHAR ( 50 ) NOT NULL,
`decision_making_function` VARCHAR ( 250 ) NOT NULL,
`relative` VARCHAR ( 50 ) NOT NULL,
`guardian_name` VARCHAR ( 50 ) NOT NULL,
`guardian_address` VARCHAR ( 50 ) NOT NULL,
`guardian_telephone_h` VARCHAR ( 50 ) NOT NULL,
`guardian_telephone_w` VARCHAR ( 50 ) NOT NULL,
`guardian_telephone_m` VARCHAR ( 50 ) NOT NULL,
`guardian_email` VARCHAR ( 50 ) NOT NULL
;

我收到以下错误:

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   在'date_of_annual_health_care_plan DATE NOT NULL附近,   first_language VARCHAR(第3行50'

为什么我收到此错误?

2 个答案:

答案 0 :(得分:0)

您需要在每列前加ADD COLUMN前缀,以便在一个语句中添加多个列,如下所示:

ALTER TABLE  `mytable`
ADD COLUMN `telephone` VARCHAR( 50 ) NOT NULL,
ADD COLUMN `date_of_annual_health_care_plan` DATE NOT NULL,
...

此外,我认为你不需要在任何地方使用反引号,因为没有一个名字与保留字冲突。

SQLFiddle

答案 1 :(得分:0)

请参阅以下查询。 你的语法错了。

ALTER TABLE  mytable 
ADD column telephone VARCHAR( 50 ) NOT NULL,
ADD column date_of_annual_health_care_plan DATE NOT NULL,
ADD column first_language VARCHAR ( 50 ) NOT NULL,
ADD column interp_req INT NOT NULL,
ADD column religion VARCHAR ( 50 ) NOT NULL,
ADD column religious_considerations VARCHAR ( 350 ) NOT NULL,
ADD column diagnosis_and_associated_health_conditions VARCHAR ( 500 ) NOT NULL,
ADD column communcation VARCHAR ( 350 ) NOT NULL,
ADD column challenging_behaviours VARCHAR ( 350 ) NOT NULL,
ADD column medicare_number VARCHAR ( 50 ) NOT NULL,
ADD column pension_number VARCHAR ( 50 ) NOT NULL,
ADD column private_health_insurance VARCHAR ( 50 ) NOT NULL,
ADD column person_responsible INT NOT NULL,
ADD column person_res_name VARCHAR ( 50 ) NOT NULL,
ADD column person_res_address VARCHAR ( 50 ) NOT NULL,
ADD column person_res_telephone_h VARCHAR ( 50 ) NOT NULL,
ADD column person_res_telephone_w VARCHAR ( 50 ) NOT NULL,
ADD column person_res_telephone_m VARCHAR ( 50 ) NOT NULL,
ADD column person_res_email VARCHAR ( 50 ) NOT NULL,
ADD column decision_making_function VARCHAR ( 250 ) NOT NULL,
ADD column relative VARCHAR ( 50 ) NOT NULL,
ADD column guardian_name VARCHAR ( 50 ) NOT NULL,
ADD column guardian_address VARCHAR ( 50 ) NOT NULL,
ADD column guardian_telephone_h VARCHAR ( 50 ) NOT NULL,
ADD column guardian_telephone_w VARCHAR ( 50 ) NOT NULL,
ADD column guardian_telephone_m VARCHAR ( 50 ) NOT NULL,
ADD column guardian_email VARCHAR ( 50 ) NOT NULL;