SQL中的语法错误?

时间:2015-05-06 12:59:07

标签: mysql sql

可能是一个简单的解决方法,但从我从示例中可以看到,这应该有效!

ALTER TABLE "relevant_topics" 
ADD `linktitle_11` varchar(500);
ADD `linktitle_11_url` varchar(500);
ADD `linktitle_11_desc` varchar(500);
ADD `linktitle_12` varchar(500);
ADD `linktitle_12_url` varchar(500);
ADD `linktitle_12_desc` varchar(500);
ADD `linktitle_13` varchar(500);
ADD `linktitle_13_url` varchar(500);
ADD `linktitle_13_desc` varchar(500);

谁能说出我做错了什么?

4 个答案:

答案 0 :(得分:1)

表格名称不需要引号,每个,应与ALTER TABLE relevant_topics ADD `linktitle_11` varchar(500), ADD `linktitle_11_url` varchar(500), ADD `linktitle_11_desc` varchar(500), ADD `linktitle_12` varchar(500), ADD `linktitle_12_url` varchar(500), ADD `linktitle_12_desc` varchar(500), ADD `linktitle_13` varchar(500), ADD `linktitle_13_url` varchar(500), ADD `linktitle_13_desc` varchar(500);

分开
Objective-C

答案 1 :(得分:1)

因为现在你只是创建了linktitle_11列吗?分号结束你的sql语句,并且没有简单地称为add的sql语句,只要添加第一列,你的alter table语句就会结束 你需要这样做:

ALTER TABLE "relevant_topics" 
ADD (`linktitle_11` varchar(500),
 `linktitle_11_url` varchar(500),
 `linktitle_11_desc` varchar(500),
 `linktitle_12` varchar(500),
 `linktitle_12_url` varchar(500),
 `linktitle_12_desc` varchar(500),
 `linktitle_13` varchar(500),
 `linktitle_13_url` varchar(500));

OR

ALTER TABLE "relevant_topics" 
ADD `linktitle_11` varchar(500);
ALTER TABLE "relevant_topics" 
ADD `linktitle_11_url` varchar(500);
ALTER TABLE "relevant_topics" 
ADD `linktitle_11_desc` varchar(500);
ALTER TABLE "relevant_topics" 
ADD `linktitle_12` varchar(500);
ALTER TABLE "relevant_topics" 
ADD `linktitle_12_url` varchar(500);
ALTER TABLE "relevant_topics" 
ADD `linktitle_12_desc` varchar(500);
ALTER TABLE "relevant_topics" 
ADD `linktitle_13` varchar(500);
ALTER TABLE "relevant_topics" 
ADD `linktitle_13_url` varchar(500);
ALTER TABLE "relevant_topics" 
ADD `linktitle_13_desc` varchar(500);

虽然我不知道哪种方式最安全

答案 2 :(得分:1)

如果需要,您可以使用代字号作为引号

ALTER TABLE `relevant_topics`
ADD `linktitle_11` varchar(500),
ADD `linktitle_11_url` varchar(500),
ADD `linktitle_11_desc` varchar(500),
ADD `linktitle_12` varchar(500),
ADD `linktitle_12_url` varchar(500),
ADD `linktitle_12_desc` varchar(500),
ADD `linktitle_13` varchar(500),
ADD `linktitle_13_url` varchar(500),
ADD `linktitle_13_desc` varchar(500);

答案 3 :(得分:1)

尝试

ALTER TABLE relevant_topics
ADD `linktitle_11` varchar(500),
ADD `linktitle_11_url` varchar(500),
ADD `linktitle_11_desc` varchar(500),
ADD `linktitle_12` varchar(500),
ADD `linktitle_12_url` varchar(500),
ADD `linktitle_12_desc` varchar(500),
ADD `linktitle_13` varchar(500),
ADD `linktitle_13_url` varchar(500),
ADD `linktitle_13_desc` varchar(500);