insert - Mysql插入数据语法
问题描述
各位大神好,小弟今天在操作mysql插入数据时,碰到一个问题,百思不得其解,所以来SF请教一下各路大神。
表结构如下:
创建该表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语句插入一条记录,但是一直提示我语法错误
insert into test_env (describe, detail, title, type) values (’11’, ’22’, ’33’, 0);
提示
如果我使用下面的insert语句则没有错误
insert into test_env (`describe`, `detail`, `title`, `type`) values (’11’, ’22’, ’33’, 0);
请问各位大神这是怎么回事,我之前在filed名上不加 ``符号也没问题。
问题解答
回答1:因为describe是mysql保留的关键字,用来描述表结构的
回答2:应该是你的列名里有mysql的关键字describe,所以不加引号会报错。
回答3:mysql命令describe
回答4:关键字了为防止这种情况发生,可以使用方法二
但是一般来讲不要使用关键字作为field
相关文章:
1. nignx - docker内nginx 80端口被占用2. javascript - canvas 裁剪空白区域3. docker网络端口映射,没有方便点的操作方法么?4. docker绑定了nginx端口 外部访问不到5. angular.js - angular内容过长展开收起效果6. docker不显示端口映射呢?7. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?8. javascript - nodejs调用qiniu的第三方资源抓取,返回401 bad token,为什么9. debian - docker依赖的aufs-tools源码哪里可以找到啊?10. docker api 开发的端口怎么获取?
