尝试填充数据库时出现 SQL 语法错误 1064

发布于 2024-08-29 08:17:04 字数 1540 浏览 7 评论 0 原文

我不断收到以下错误消息

错误 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行 ''isbn10','isbn13','title','edition','author_f_name','author_m_name','author_l_na' 附近使用的正确语法

。使用以下命令从 MySQL 命令行填充我的 MySQL 数据库:

source C:\myFilePath\myFileName.sql

这是我的 mysqldump 的摘录(显示本书的表结构)。

我哪里出错了?:

--
-- Table structure for table `book`
--

DROP TABLE IF EXISTS `book`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `book` (
  `book_id` int(11) NOT NULL AUTO_INCREMENT,
  `isbn10` char(20) DEFAULT NULL,
  `isbn13` char(20) DEFAULT NULL,
  `title` char(20) DEFAULT NULL,
  `edition` char(20) DEFAULT NULL,
  `author_f_name` char(20) DEFAULT NULL,
  `author_m_name` char(20) DEFAULT NULL,
  `author_l_name` char(20) DEFAULT NULL,
  `cond` enum('as new','very good','good','fair','poor') DEFAULT NULL,
  `price` decimal(8,2) DEFAULT NULL,
  `genre` char(20) DEFAULT NULL,
  PRIMARY KEY (`book_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `book`
--
USE books;

INSERT INTO book ('isbn10','isbn13','title','edition','author_f_name','author_m_name','author_l_name','cond','price','genre') 
VALUES ('0136061699','978-0136061694','Software Engineering: Theory and Practice','4th Edition','Shari','Lawrence','Pfleeger','very good','50','Computing');

I keep getting the following error message

ERROR 1064 (42000): 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 ''isbn10','isbn13','title','edition','author_f_name','author_m_name','author_l_na' at line 1

when trying to populate my MySQL database from the MySQL command line with the following command:

source C:\myFilePath\myFileName.sql

Here is an excerpt from my mysqldump (showing the table structure for book).

Where did I go wrong?:

--
-- Table structure for table `book`
--

DROP TABLE IF EXISTS `book`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `book` (
  `book_id` int(11) NOT NULL AUTO_INCREMENT,
  `isbn10` char(20) DEFAULT NULL,
  `isbn13` char(20) DEFAULT NULL,
  `title` char(20) DEFAULT NULL,
  `edition` char(20) DEFAULT NULL,
  `author_f_name` char(20) DEFAULT NULL,
  `author_m_name` char(20) DEFAULT NULL,
  `author_l_name` char(20) DEFAULT NULL,
  `cond` enum('as new','very good','good','fair','poor') DEFAULT NULL,
  `price` decimal(8,2) DEFAULT NULL,
  `genre` char(20) DEFAULT NULL,
  PRIMARY KEY (`book_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `book`
--
USE books;

INSERT INTO book ('isbn10','isbn13','title','edition','author_f_name','author_m_name','author_l_name','cond','price','genre') 
VALUES ('0136061699','978-0136061694','Software Engineering: Theory and Practice','4th Edition','Shari','Lawrence','Pfleeger','very good','50','Computing');

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

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

发布评论

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

评论(1

风月客 2024-09-05 08:17:04

不要在列名称周围使用单引号。单引号表示字符串,您不使用字符串作为列名。

尝试将您的脚本更改为:

USE books;

INSERT INTO book (isbn10, isbn13, title, edition, author_f_name,
    author_m_name, author_l_name, cond, price, genre)
VALUES ('0136061699', '978-0136061694',
    'Software Engineering: Theory and Practice','4th Edition',
    'Shari','Lawrence','Pfleeger','very good','50','Computing');

Don't use single quotes around the column names. Single quotes means strings, you don't use strings for column names.

Try changing your script to this:

USE books;

INSERT INTO book (isbn10, isbn13, title, edition, author_f_name,
    author_m_name, author_l_name, cond, price, genre)
VALUES ('0136061699', '978-0136061694',
    'Software Engineering: Theory and Practice','4th Edition',
    'Shari','Lawrence','Pfleeger','very good','50','Computing');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文