MySQL表字段名包含減號的問題
往MySQL數據中插入數據時,一直提示SQL語法有錯誤(syntax error),
檢查了半天,原來是因為表名包含了減號。
原來的表結構:
Sql代碼
CREATE TABLE IF NOT EXISTS `amazon-sellertransactions` (
`record-insert-time` timestamp NOT NULL DEFAULT CURRENT-TIMESTAMP ON UPDATE CURRENT-TIMESTAMP,
`record-id` int(10) unsigned NOT NULL AUTO-INCREMENT,
`amazon-order-id` varchar(30) DEFAULT NULL,
`merchant-id` varchar(30) DEFAULT NULL,
`purchase-date` datetime DEFAULT NULL,
`last-update-date` datetime DEFAULT NULL,
`order-status` varchar(50) DEFAULT NULL,
`fulfillment-channel` varchar(20) DEFAULT NULL,
`sales-channel` varchar(50) DEFAULT NULL,
`shipments-service-level` varchar(50) DEFAULT NULL,
`order-total` varchar(30) DEFAULT NULL,
`buyer-name` varchar(50) DEFAULT NULL, www.2cto.com
`buyer-email` varchar(60) DEFAULT NULL,
`number-items-shipped` varchar(10) DEFAULT NULL,
`number-items-unshipped` varchar(10) DEFAULT NULL,
`ship-city` varchar(50) DEFAULT NULL,
`ship-state` varchar(50) DEFAULT NULL,
`ship-postal-code` varchar(50) DEFAULT NULL,
`ship-country` varchar(50) DEFAULT NULL,
`ship-name` varchar(50) DEFAULT NULL,
`ship-phone` varchar(30) DEFAULT NULL,
`ship-address-line1` varchar(120) DEFAULT NULL,
`payment-method` varchar(30) DEFAULT NULL,
PRIMARY KEY (`Record`),
UNIQUE KEY `amazon-order-id` (`amazon-order-id`)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
這段SQL代碼創建表是沒有問題,但是在相關操作中卻報語法錯誤,加上引號也不行,所以,只能修改表字段名,修改後的SQL代碼如下:
Sql代碼
CREATE TABLE IF NOT EXISTS `amazon_sellertransactions` (
`record_insert_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`record_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`amazon_order_id` varchar(30) DEFAULT NULL,
`merchant_id` varchar(30) DEFAULT NULL,
`purchase_date` datetime DEFAULT NULL,
`last_update_date` datetime DEFAULT NULL,
`order_status` varchar(50) DEFAULT NULL,
`fulfillment_channel` varchar(20) DEFAULT NULL,
`sales_channel` varchar(50) DEFAULT NULL,
`shipments_service_level` varchar(50) DEFAULT NULL,
`order_total` varchar(30) DEFAULT NULL,
`buyer_name` varchar(50) DEFAULT NULL, www.2cto.com
`buyer_email` varchar(60) DEFAULT NULL,
`number_items_shipped` varchar(10) DEFAULT NULL,
`number_items_unshipped` varchar(10) DEFAULT NULL,
`ship_city` varchar(50) DEFAULT NULL,
`ship_state` varchar(50) DEFAULT NULL,
`ship_postal_code` varchar(50) DEFAULT NULL,
`ship_country` varchar(50) DEFAULT NULL,
`ship_name` varchar(50) DEFAULT NULL,
`ship_phone` varchar(30) DEFAULT NULL,
`ship_address_line1` varchar(120) DEFAULT NULL,
`payment_method` varchar(30) DEFAULT NULL,
PRIMARY KEY (`Record`),
UNIQUE KEY `amazon_order_id` (`amazon_order_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;