Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 我的sql有什么问题?_Mysql_Phpmyadmin - Fatal编程技术网

Mysql 我的sql有什么问题?

Mysql 我的sql有什么问题?,mysql,phpmyadmin,Mysql,Phpmyadmin,您必须从表名中删除”字符,如下所示 CREATE TABLE IF NOT EXISTS 'test'( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , `campaincode` VARCHAR( 100 ) NOT NULL , `description` VARCHAR( 100 ) NOT NULL , `paymentplantype` VARCHAR( 100 ) NOT NULL , `cont

您必须从表名中删除
字符,如下所示

  CREATE TABLE IF NOT EXISTS 'test'(
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  `campaincode` VARCHAR( 100 ) NOT NULL ,
  `description` VARCHAR( 100 ) NOT NULL ,
  `paymentplantype` VARCHAR( 100 ) NOT NULL ,
  `contractlength` INT NOT NULL ,
  `monthlyannuityfactor` DOUBLE NOT NULL ,
  `initialfee` DOUBLE NOT NULL ,
  `notificationfee` DOUBLE NOT NULL ,
  `interestratepercentage` INT NOT NULL ,
  `interestfreemonths` INT NOT NULL ,
  `paymentfreemonths` INT NOT NULL ,
  `fromamount` DOUBLE NOT NULL ,
  `toamount` DOUBLE NOT NULL ,
  `timestamp` INT UNSIGNED NOT NULL ,
  `storeid` INT NOT NULL
  )

您的SQL存在一些问题

  • 是检查表是否存在的方式
  • 您没有正确分配十进制数据类型
  • 这件衣服不需要包装 所有的字在'
  • 下面是检查表是否存在的代码,如果我不存在,请创建它

     CREATE TABLE IF NOT EXISTS test(
    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `campaincode` VARCHAR( 100 ) NOT NULL ,
    `description` VARCHAR( 100 ) NOT NULL ,
    `paymentplantype` VARCHAR( 100 ) NOT NULL ,
    `contractlength` INT NOT NULL ,
    `monthlyannuityfactor` DOUBLE NOT NULL ,
    `initialfee` DOUBLE NOT NULL ,
    `notificationfee` DOUBLE NOT NULL ,
    `interestratepercentage` INT NOT NULL ,
    `interestfreemonths` INT NOT NULL ,
    `paymentfreemonths` INT NOT NULL ,
    `fromamount` DOUBLE NOT NULL ,
    `toamount` DOUBLE NOT NULL ,
    `timestamp` INT UNSIGNED NOT NULL ,
    `storeid` INT NOT NULL
    )
    

    如果您需要更多帮助信息,请告诉我,如果答案回答了您的问题,请不要忘记将答案标记为已完成

    表名中有引号,而表名中应有背景。试试这个:

    /* CHECK IF THE TABLE EXISTS IN sys.objects*/
    IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = object_id(N'[dbo].[Table]') AND type in (N'U'))
    
    
    BEGIN  -- If it dont create the table 
        CREATE TABLE [VI].[dbo].[Table] 
            (
                 id INT NOT NULL identity(1,1) PRIMARY KEY 
                 , campaincode VARCHAR( 100 ) NOT NULL 
                 , [description] VARCHAR( 100 ) NOT NULL --if you want to use keywords that SQL uses like description it is best practise to wrap them in []
                 , paymentplantype VARCHAR( 100 ) NOT NULL 
                 , contractlength INT NOT NULL 
                 , monthlyannuityfactor decimal(18, 0) NOT NULL -- when using decimal you must also type in the amount of numbers you want before the .(decimal place) and the amount you want after the decimal place 
                                                                -- i have set this to 18 before the . and 0 after this is the deafult when creating tables
                 , initialfee decimal(18, 0) NOT NULL 
                 , notificationfee decimal(18, 0) NOT NULL 
                 , interestratepercentage INT NOT NULL 
                 , interestfreemonths INT NOT NULL 
                 , paymentfreemonths INT NOT NULL 
                 , fromamount decimal(18, 0) NOT NULL 
                 , toamount decimal(18, 0) NOT NULL 
                 , [timestamp] INT NOT NULL 
                 , storeid INT NOT NULL 
             )
    END
    
    对于一些有用的信息,应始终使用反勾号。但是有一些原因可以解释为什么一个团队不愿意使用它们

    优点:

    • 使用它们,没有保留字或禁止字符
    • 在某些情况下,您会收到更多描述性错误消息
    • 如果你避免不良行为,你不在乎,但是。。。说实话, 有时,它们是避免SQL注入的一种不错的方法
    缺点:

    • 它们不是标准的,通常不便于携带。但是只要 您不使用反勾号作为标识符的一部分(这是最糟糕的) 实践我可以想象),你可以通过 自动删除背景标记
    • 如果您的一些查询来自Access,它们可能会引用表名 (也许你不能盲目地删除所有的)。然而 允许混合使用反勾号和双引号
    • 一些愚蠢的软件或函数会过滤你的查询,并且 反勾号的问题。但是,它们是ASCII的一部分,因此 表示您的软件/功能非常差

    请参阅:

    有很多大写字母!。。。jks请提供错误信息,看看你是如何使用反勾号的?嗯,有一个地方你用了别的东西!而且,你不太可能想要双精度而不是十进制。“但我知道什么?”实际上他不知道。有人编辑了答案并把它们放在那里。。。我试图还原编辑,但我们的编辑重叠了,所以引号仍保留在那里。@joe776但是,在PHPmyadmin的上下文中,此查询没有其他问题。
    如果不存在,则创建表有什么问题
    ?标签引用了phpmyadmin,在这个上下文中,这个答案是不合适的!是的-而且你也可以删除所有的背景标记!
     CREATE TABLE IF NOT EXISTS `test`(
      `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
      `campaincode` VARCHAR( 100 ) NOT NULL ,
      `description` VARCHAR( 100 ) NOT NULL ,
      `paymentplantype` VARCHAR( 100 ) NOT NULL ,
      `contractlength` INT NOT NULL ,
      `monthlyannuityfactor` DOUBLE NOT NULL ,
      `initialfee` DOUBLE NOT NULL ,
      `notificationfee` DOUBLE NOT NULL ,
      `interestratepercentage` INT NOT NULL ,
      `interestfreemonths` INT NOT NULL ,
      `paymentfreemonths` INT NOT NULL ,
      `fromamount` DOUBLE NOT NULL ,
      `toamount` DOUBLE NOT NULL ,
      `timestamp` INT UNSIGNED NOT NULL ,
      `storeid` INT NOT NULL
      )