You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MySQL语法错误求助:CREATE TABLE users语句故障排查

Fixing Your MySQL CREATE TABLE Syntax Error

Let’s walk through the issues in your statement and get it working smoothly:

1. Wrong Quote Type for Column Identifiers

The biggest syntax mistake here is using single quotes (') around column names (like 'id' or 'first_name'). In MySQL, single quotes are reserved for string literal values (think the 'Active' in your ENUM definition). For identifiers like column or table names, you need to use backticks (`)—or skip quotes entirely if your names don’t clash with MySQL’s reserved words (none of your column names do here, so quotes are optional either way).

2. Incomplete Statement & Redundant Constraint

Your code cuts off at P..., so I’ll assume you intended to wrap up the table definition. Also, for an AUTO_INCREMENT column, it’s standard practice to set it as the PRIMARY KEY—since primary keys inherently enforce uniqueness, you don’t need to add a separate UNIQUE constraint here.

Corrected Full SQL Statement

CREATE TABLE users (
    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `first_name` VARCHAR(250) NOT NULL,
    `last_name` VARCHAR(250) NOT NULL,
    `user_name` VARCHAR(50) NOT NULL UNIQUE,
    `email` VARCHAR(250) NOT NULL UNIQUE,
    `password` VARCHAR(250) NOT NULL,
    `last_access` DATETIME DEFAULT NULL,
    `phone` VARCHAR(250) DEFAULT NULL,
    `cellphone` VARCHAR(250) DEFAULT NULL,
    `status` ENUM('Active', 'Inactive', 'Blocked', 'Deleted', 'Newreg') DEFAULT 'Active'
);

Quick Additional Notes

  • If you prefer, you can drop the backticks entirely (e.g., id instead of `id`) since none of your column names are MySQL reserved words.
  • The PRIMARY KEY on id handles the uniqueness requirement, so removing the redundant UNIQUE constraint cleans up the code.
  • I filled in the truncated end of your statement to make it valid—tweak it if you had additional columns or constraints planned.

内容的提问来源于stack exchange,提问作者Alfre Cano

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:37:08