0

I land up in an error stating:

Error Code 1064: You have an error in your sqlsyntax; check the manual that corresponds to your MariaDB Server syntax for the right syntax to use

CREATE TABLE 'company'.'employee'(
'fname' VARCHAR (10) NOT NULL,
'mname' VARCHAR(2) NULL, 
'lname' VARCHAR(10) NOT NULL,
'ssn' CHAR(9) NOT NULL, 
'bdate' DATE,
'address' VARCHAR(20) NOT NULL,
'sex' CHAR NULL,
'salary' DECIMAL (10, 2) NULL,
'super_ssn' CHAR(9) NULL,
'd_no' INT NOT NULL,
PRIMARY KEY ('ssn'));
Wei Lin
  • 3,591
  • 2
  • 20
  • 52
SID
  • 17
  • 5
  • Possible duplicate of [When to use single quotes, double quotes, and back ticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-back-ticks-in-mysql) – Madhur Bhaiya Dec 01 '18 at 07:20

1 Answers1

0

Use ` instead of ' (single quote),

You should write it like the following :

    CREATE TABLE `company`.`employee`(
      `fname` VARCHAR (10) NOT NULL,
      `mname` VARCHAR(2) NULL,
      `lname` VARCHAR(10) NOT NULL,
      `ssn` CHAR(9) NOT NULL,
      `bdate` DATE,
      `address` VARCHAR(20) NOT NULL,
      `sex` CHAR NULL,
      `salary` DECIMAL (10, 2) NULL,
      `super_ssn` CHAR(9) NULL,
      `d_no` INT NOT NULL,
      PRIMARY KEY (`ssn`)
    );

Actually, the ` symbol is optional, but it is used if the field names, tables, or databases are the same as keywords or MySQL clauses whose purpose is that MySQL is not confused with what you mean in the query.

For example :

SELECT column FROM `char`

I use ` symbol because the name of the table is the same as keyword on MySQL i.e CHAR() (but naming like that is a bad way), so keep in mind that if you write SQL Query you must decide to use the ` symbol

hope this can help you.

Imam Digmi
  • 452
  • 4
  • 14