简体   繁体   中英

What's wrong with this MySQL syntax?

Alright so I'm trying to tie a Spigot plugin that I'm making into MySQL, and I did it successfully up until the point where I edited the code that was creating the table. I find that MySQL stack traces are much too ambiguous to be useful, so I have no idea what I'm doing wrong here. Code:

CREATE TABLE IF NOT EXISTS WebsiteLink_keys(id INT NOT NULL KEY AUTO_INCREMENT, key VARCHAR(36), trimmedUUID VARCHAR(36), playerUUID VARCHAR(36), date TIMESTAMP, status TEXT);

key is a reserved word in MySQL. If you absolutely must use it as a column name, you can escape it using backticks:

CREATE TABLE IF NOT EXISTS WebsiteLink_keys (
    id INT NOT NULL KEY AUTO_INCREMENT, 
    `key` VARCHAR(36), -- Here!
    trimmedUUID VARCHAR(36), 
    playerUUID VARCHAR(36), 
    date TIMESTAMP, 
    status TEXT
)

Or, better yet, use a name that isn't a reserved word, such as link_key :

CREATE TABLE IF NOT EXISTS WebsiteLink_keys (
    id INT NOT NULL KEY AUTO_INCREMENT, 
    link_key VARCHAR(36), -- Here!
    trimmedUUID VARCHAR(36), 
    playerUUID VARCHAR(36), 
    date TIMESTAMP,
    status TEXT
)
CREATE TABLE IF NOT EXISTS WebsiteLink_keys(
  id INT NOT NULL AUTO_INCREMENT, 
  `key` VARCHAR(36), 
  trimmedUUID VARCHAR(36), 
  playerUUID VARCHAR(36), 
  `date` TIMESTAMP, 
  status TEXT, 
  PRIMARY KEY (id)
);

PRIMARY KEY (id) is at the end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM