Search code examples
mysqlmysql-error-1064

SQL Syntax Error 1064 when trying to populate database


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');

Solution

  • 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');