【问题标题】:1064 - You have an error in your SQL syntax?1064 - 您的 SQL 语法有错误?
【发布时间】:2016-05-11 05:10:02
【问题描述】:

1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 ''transactionid' int(11) DEFAULT NULL 附近使用的正确语法, 主键 (sid), KEY pid (pid)' 在第 12 行

-- Table structure for table `products`
CREATE TABLE IF NOT EXISTS 

`products` ( `pid` int(11) NOT NULL AUTO_INCREMENT,
`product` varchar(255) NOT NULL,
`product_img` varchar(100) DEFAULT NULL,
`price` int(11) DEFAULT NULL,
 `currency` varchar(10) DEFAULT 'USD',
  PRIMARY KEY (`pid`)
 ) ENGINE=InnoDB  DEFAULT 
 CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `products`
--

 INSERT INTO `products` (`pid`, `product`, `product_img`, `price`) 
 VALUES (1, 'White T-Shirt', 'white.png', 22), (2, 'Black T-Shirt', 'black.png', 30);

  --------------------------------------------------------

  -- Table structure for table `sales`

  CREATE TABLE IF NOT EXISTS 

 `sales` ( `sid` int(11) NOT NULL AUTO_INCREMENT,
 `pid` int(11) DEFAULT NULL,
 `uid` int(11) DEFAULT NULL,
 `saledate` date DEFAULT NULL,
 'transactionid' int(11) DEFAULT NULL,
  PRIMARY KEY (`sid`),
  KEY `pid` (`pid`),
   KEY `uid` (`uid`)
  ) 

 ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;

--
-- Dumping data for table `sales`
--

 INSERT INTO `sales` (`sid`, 

`pid`, `uid`, `saledate`) VALUES
 (1, 2, 1, '0000-00-00'),
 (2, 2, 1, '0000-00-00'),
 (3, 1, 1, '0000-00-00'),
 (6, 2, 1, '2011-03-13'),
 (7, 2, 1, '2011-03-13'),
 (8, 2, 1, '2011-03-13'),
 (9, 2, 1, '2011-03-13'),
 (10, 2, 1, '2011-03-13'),
 (11, 1, 1, '2011-03-13');

【问题讨论】:

标签: mysql create-table


【解决方案1】:

检查 transactionid 周围的引号。您需要使用` 而不是'。

【讨论】:

    【解决方案2】:

    这一行的语法错误:

    'transactionid' int(11) DEFAULT NULL,
    

    它应该和其他列声明一样,意味着列名周围的字符不应该是'(单引号)而应该是`(反引号 em>) 符号

    `transactionid` int(11) DEFAULT NULL,
    

    【讨论】:

      猜你喜欢
      • 2016-10-30
      • 2017-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-27
      • 1970-01-01
      • 2016-01-24
      • 2021-07-03
      相关资源
      最近更新 更多