代码之家  ›  专栏  ›  技术社区  ›  Brian Hicks

这个SQL查询有什么问题?

sql
  •  0
  • Brian Hicks  · 技术社区  · 15 年前

    在这个插入查询中,我似乎出错了。有人能告诉我怎么做吗?

    谢谢。

    INSERT INTO tablename ('score', 'coins-earned', 'bonus-used', 'topmultiplier', 'highscore', 'currentposition', 'super', 'star', 'color') 
    VALUES ('1', '2', 'TRUE', '3', 'TRUE', '4', '5', '6', '7') 
    
    5 回复  |  直到 15 年前
        1
  •  7
  •   egrunin    15 年前

    您将列名称放在引号中,连字符在列名称中可能无效。在MS SQL中,这是有效的:

    INSERT INTO tablename (score, [coins-earned], [bonus-used], 
        topmultiplier, highscore, currentposition, super, star, color) 
    VALUES ('1', '2', 'TRUE', '3', 'TRUE', '4', '5', '6', '7') 
    

    这还假定所有列都是char或varchar,而它们可能不是。数字列和布尔列也不需要引号,因此有可能最终得到如下内容:

    INSERT INTO tablename (score, [coins-earned], [bonus-used], 
        topmultiplier, highscore, currentposition, super, star, color) 
    VALUES (1, 2, TRUE, 3, TRUE, 4, '5', '6', '7') 
    
        2
  •  1
  •   codaddict    15 年前

    请提供表格结构。

    我猜“score”是数字,您试图插入一个字符串,其他许多列也是如此。

        3
  •  0
  •   Bjoern    15 年前

    那么语法本身就可以了。

    请添加表说明,必须有一个关于要放入表中的值的错误(可能是数字,您希望插入“true”)。

        4
  •  0
  •   karlis    15 年前

    我猜这些数字是表设计中的数值,所以您不需要''-如果“使用的奖金”列是位/bool列,请使用1/0而不是'true'。

    所以

    值(1,2,1,3,1,4,5,6,7)

        5
  •  0
  •   Peter Lang    15 年前

    尝试替换列名中的单引号:

    INSERT INTO tablename
      (`score`, `coins-earned`, `bonus-used`, `topmultiplier`,
       `highscore`, `currentposition`, `super`, `star`, `color`) 
    VALUES ('1', '2', 'TRUE', '3', 'TRUE', '4', '5', '6', '7')