当前位置:Gxlcms > mysql > MySQL表字段名包含减号的问题_MySQL

MySQL表字段名包含减号的问题_MySQL

时间:2021-07-01 10:21:17 帮助过:57人阅读

bitsCN.com
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, `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, `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; bitsCN.com

人气教程排行