在列名称中使用保留字 [英] Using reserved words in column names

查看:152
本文介绍了在列名称中使用保留字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一些简单的代码,但我只是不知道为什么我不能使用这个词作为表的实体

this is some simple code but I just don't know why I can't use this word as the entity of the table

CREATE TABLE IF NOT EXISTS users(
key INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
username VARCHAR(50) NOT NULL,
);

我意识到如果我使用键,我不能使用keymysql会要求我检查语法,但如果我使用id或任何其他的表将被创建。

I realized I can't use "key" if I use key the mysql will ask me to check the syntax but if I use "id" or any others the table will be created.

任何人都知道如何创建实体名称键?没有什么重要的,因为我可以只使用id而不是键,但因为我发现这个错误我wonna看看有没有办法让它工作。

Anyone know how I can create the entity name into key? Not something important since I can just use id instead of key but since I found this error I wonna see if there's a way to get it work.

推荐答案

您仍然可以使用

CREATE TABLE IF NOT EXISTS users
(
    `key` INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
    username VARCHAR(50) NOT NULL,
);

但建议不要使用任何保留的关键字以避免未来的问题。 :)

but as an advise, refrain from using any reserved keyword to avoid future problems. :)

  • MySQL Reserved Keywords List

这篇关于在列名称中使用保留字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆