簡體   English   中英

這個MySQL查詢有什么問題-資料庫無法接受?

[英]What's wrong with this MySQL query — db won't accept?

我有以下MySQL查詢:

INSERT INTO 12:12:12:12:12(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_speed,rain_mm_per_hour,nsew,str,ip) VALUES(1361707978,'2013-02-24T12:12:58+00:00',0.0,0,0.0,0.0,0.0,0,'1010101010101010','0')

該表的名稱是“ 12:12:12:12:12”。

這是模式:

"CREATE TABLE IF NOT EXISTS `$mac` (
  `timestamp` int(11) NOT NULL,
  `niceTime` varchar(20) NOT NULL,
  `temperature` float NOT NULL,
  `relative_humidity` int(11) NOT NULL,
  `wind_speed` float NOT NULL,
  `gust_speed` float NOT NULL,
  `rain_mm_per_hour` float NOT NULL,
  `nsew` int(11) NOT NULL,
  `str` varchar(1000) NOT NULL,
  `ip` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;"

無論我做什么,我都無法使查詢被接受;(

Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '12:12:12:12:12(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_' at line 1

提前謝謝了,

您將在表名中使用像這樣的反引號12:12:12:12:12

嘗試這個

   INSERT INTO `12:12:12:12:12`(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_speed,rain_mm_per_hour,nsew,str,ip) VALUES(1361707978,'2013-02-24T12:12:58+00:00',0.0,0,0.0,0.0,0.0,0,'1010101010101010','0'

編輯。

命名對象的規則,包括MySql中的表:

http://dev.mysql.com/doc/refman/5.1/zh-CN/identifiers.html

標識符可以以數字開頭,但除非加引號,否則不能僅由數字組成。

The identifier quote character is the backtick (“`”):

在標識符周圍使用反引號,尤其是在使用此類非常規表名稱時:

INSERT INTO `12:12:12:12:12`(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_speed,rain_mm_per_hour,nsew,str,ip)
VALUES(1361707978,'2013-02-24T12:12:58+00:00',0.0,0,0.0,0.0,0.0,0,'1010101010101010','0')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM