MySql 语法错误

发布于 2024-12-28 22:41:25 字数 992 浏览 0 评论 0原文

我正在尝试为我下载的简单脚本创建这两个表,但在运行 sql 命令时它返回语法错误。

我得到的错误是:

CREATE TABLE `usrsig` (
  `id` int(9) NOT NULL auto_increment,
  `url` varchar(255) default NULL,
  `user` int(9) NOT NULL default '0',
  PRIMARY KEY  (`id`)
  KEY `user_own` (`user`) 
);

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'KEY `user_own` (`user`) )' at line 6

第二个表的内容如下:

CREATE TABLE `usruser` (
  `id` int(9) NOT NULL auto_increment,
  `name` varchar(30) NOT NULL default '',
  `pass` varchar(30) default NULL,
  `last` datetime default NULL,
  `hits` int(9) NOT NULL default '0',
  PRIMARY KEY  (`id`)
  KEY `name_index` (`name`) 
);

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'KEY `name_index` (`name`) )' at line 8

如果有人能好心地帮助我,我将非常感激。

谢谢

I am trying to create these two tables for a simple script I downloaded but when running the sql command it returns a syntax error.

The error I get is:

CREATE TABLE `usrsig` (
  `id` int(9) NOT NULL auto_increment,
  `url` varchar(255) default NULL,
  `user` int(9) NOT NULL default '0',
  PRIMARY KEY  (`id`)
  KEY `user_own` (`user`) 
);

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'KEY `user_own` (`user`) )' at line 6

And the following for the 2nd tabel:

CREATE TABLE `usruser` (
  `id` int(9) NOT NULL auto_increment,
  `name` varchar(30) NOT NULL default '',
  `pass` varchar(30) default NULL,
  `last` datetime default NULL,
  `hits` int(9) NOT NULL default '0',
  PRIMARY KEY  (`id`)
  KEY `name_index` (`name`) 
);

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'KEY `name_index` (`name`) )' at line 8

If anyone could be so kind as to help me out I would be greatly appreciative.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

勿挽旧人 2025-01-04 22:41:25

您只是在 PRIMARY KEY (id) 之后缺少一个逗号。

CREATE TABLE `usrsig` (
  `id` int(9) NOT NULL auto_increment,
  `url` varchar(255) default NULL,
  `user` int(9) NOT NULL default '0',
  /* Comma needed... */
  PRIMARY KEY  (`id`),
  KEY `user_own` (`user`) 
);


CREATE TABLE `usruser` (
  `id` int(9) NOT NULL auto_increment,
  `name` varchar(30) NOT NULL default '',
  `pass` varchar(30) default NULL,
  `last` datetime default NULL,
  `hits` int(9) NOT NULL default '0',
  /* Comma needed... */
  PRIMARY KEY  (`id`),
  KEY `name_index` (`name`) 
);

提示一下,大约 99% 的情况下,MySQL 报告的错误恰好出现在所标识位置之前的一个字符。因此,请在 KEY name_index 之前查找一个字符或符号:

检查与您的 MySQL 服务器版本相对应的手册,了解在“KEY name_index”附近使用的正确语法

You're just missing a comma after PRIMARY KEY (id)

CREATE TABLE `usrsig` (
  `id` int(9) NOT NULL auto_increment,
  `url` varchar(255) default NULL,
  `user` int(9) NOT NULL default '0',
  /* Comma needed... */
  PRIMARY KEY  (`id`),
  KEY `user_own` (`user`) 
);


CREATE TABLE `usruser` (
  `id` int(9) NOT NULL auto_increment,
  `name` varchar(30) NOT NULL default '',
  `pass` varchar(30) default NULL,
  `last` datetime default NULL,
  `hits` int(9) NOT NULL default '0',
  /* Comma needed... */
  PRIMARY KEY  (`id`),
  KEY `name_index` (`name`) 
);

As a tip, about 99% of the time, the error as reported by MySQL occurs exactly one character before the place identified. So look one character or symbol before KEY name_index:

check the manual that corresponds to your MySQL server version for the right syntax to use near 'KEY name_index

晌融 2025-01-04 22:41:25

我认为您只是在 PRIMARY KEY ('id') 行后面缺少一个逗号。

I think you are just missing a comma after the PRIMARY KEY ('id') line.

本宫微胖 2025-01-04 22:41:25

您放置主键和其他键的方式是语法问题。

主键 (id),

在其后面放置一个逗号。

The way you are putting Primary key and other key is the syntax problem.

Primary Key (id),

Put a comma after this.

ぽ尐不点ル 2025-01-04 22:41:25
CREATE TABLE usrsig (
  id int(9) NOT NULL  AUTO_INCREMENT,
  url varchar(255) DEFAULT NULL,
  user int(9) NOT NULL DEFAULT 0,
  PRIMARY KEY  (id),
  KEY user_own (user) 
);

CREATE TABLE usruser (
  id int(9) NOT NULL  AUTO_INCREMENT,
  name varchar(30) NOT NULL DEFAULT '',
  pass varchar(30) DEFAULT NULL,
  last datetime DEFAULT NULL,
  hits int(9) NOT NULL DEFAULT 0,
  PRIMARY KEY  (id),
  KEY name_index (name) 
);
CREATE TABLE usrsig (
  id int(9) NOT NULL  AUTO_INCREMENT,
  url varchar(255) DEFAULT NULL,
  user int(9) NOT NULL DEFAULT 0,
  PRIMARY KEY  (id),
  KEY user_own (user) 
);

CREATE TABLE usruser (
  id int(9) NOT NULL  AUTO_INCREMENT,
  name varchar(30) NOT NULL DEFAULT '',
  pass varchar(30) DEFAULT NULL,
  last datetime DEFAULT NULL,
  hits int(9) NOT NULL DEFAULT 0,
  PRIMARY KEY  (id),
  KEY name_index (name) 
);
两个我 2025-01-04 22:41:25

任何主键错误 - 修复

//删除所有

  1. Drop-Database

  2. 删除迁移

  3. 删除迁移

  4. 删除迁移
    直到清除所有迁移

  5. Add-Migration

  6. 更新数据库

成功

Any primary key error - fix

//delete all

  1. Drop-Database

  2. Remove-Migration

  3. Remove-Migration

  4. Remove-Migration
    until you clear all migration

  5. Add-Migration

  6. Update-Database

success

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文