skip to Main Content

I am trying to create a table in a database in phpMyAdmin and I keep getting the "a symbol name was expected" error and I cannot figure out what is going on. Is my syntax wrong? I am new to this and I’m at a loss.

Create Table Query

3

Answers


  1. You used ' ' sign in your column properties. But mySQL allow you to use `` sign.

    CREATE TABLE IF NOT EXISTS `sales` (
            `id` int(11) NOT NULL AUTO_INCREMENT,
            `name` varchar(50) NOT NULL,
            `item` varchar(50) NOT NULL,
            `date` varchar(50) NOT NULL,
            `amount` int(11) NOT NULL,
            PRIMARY KEY (`id`)
        );
    
    Login or Signup to reply.
  2. Column names, table names should be surrounded by backticks(``)

    CREATE TABLE IF NOT EXISTS `sales` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `name` varchar(50) NOT NULL,
        `item` varchar(50) NOT NULL,
        `date` varchar(50) NOT NULL,
        `amount` int(11) NOT NULL,
        PRIMARY KEY (`id`)
    )
    

    Or you can go without backticks as well:

    CREATE TABLE IF NOT EXISTS sales (
        id int(11) NOT NULL AUTO_INCREMENT,
        name varchar(50) NOT NULL,
        item varchar(50) NOT NULL,
       date varchar(50) NOT NULL,
       amount int(11) NOT NULL,
       PRIMARY KEY (id)
    )
    
    Login or Signup to reply.
  3. Your code is wrong , So here is the correct Code :

    CREATE TABLE IF NOT EXISTS `sales` (
        `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
        `name` VARCHAR(50) CHARACTER SET utf8 NOT NULL,
        `item` VARCHAR(50) CHARACTER SET utf8 NOT NULL,
        `date` VARCHAR(50) NOT NULL,
        `amount` int(11) NOT NULL
    ) 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search