insert - Mysql插入數(shù)據(jù)語法
問題描述
各位大神好,小弟今天在操作mysql插入數(shù)據(jù)時(shí),碰到一個(gè)問題,百思不得其解,所以來SF請教一下各路大神。
表結(jié)構(gòu)如下:
創(chuàng)建該表SQL語句如下:
CREATE TABLE `test_env` ( `id` int(11) NOT NULL AUTO_INCREMENT, `describe` varchar(11) NOT NULL, `detail` varchar(11) NOT NULL, `title` varchar(11) NOT NULL, `type` int(11) NOT NULL, `create_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
下面問題來了
我使用insert語句插入一條記錄,但是一直提示我語法錯(cuò)誤
insert into test_env (describe, detail, title, type) values (’11’, ’22’, ’33’, 0);
提示
如果我使用下面的insert語句則沒有錯(cuò)誤
insert into test_env (`describe`, `detail`, `title`, `type`) values (’11’, ’22’, ’33’, 0);
請問各位大神這是怎么回事,我之前在filed名上不加 ``符號(hào)也沒問題。
問題解答
回答1:因?yàn)閐escribe是mysql保留的關(guān)鍵字,用來描述表結(jié)構(gòu)的
回答2:應(yīng)該是你的列名里有mysql的關(guān)鍵字describe,所以不加引號(hào)會(huì)報(bào)錯(cuò)。
回答3:mysql命令describe
回答4:關(guān)鍵字了為防止這種情況發(fā)生,可以使用方法二
但是一般來講不要使用關(guān)鍵字作為field
相關(guān)文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. win10系統(tǒng) php安裝swoole擴(kuò)展3. extra沒有加載出來4. 關(guān)于Mysql數(shù)據(jù)表行轉(zhuǎn)列5. mysql - 為什么where條件中or加索引不起作用?6. php - 第三方支付平臺(tái)在很短時(shí)間內(nèi)多次異步通知,訂單多次確認(rèn)收款7. django進(jìn)行數(shù)據(jù)庫的查詢8. PHP求助,求幫忙謝謝各位9. Span標(biāo)簽10. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時(shí)間會(huì)消失是什么情況?
