Search code examples
sqlsyntaxsyntax-error

error: You have an error in your SQL syntax when creating table in mysql


I know what a syntax error is but cannot find any error when creating this table: my code

CREATE TABLE branch supplier (
     branch_id INT,
     supplier_name VARCHAR(40),
     supply_type VARCHAR(40),
     PRIMARY KEY (branch_id, supplier_name),
     FOREIGN KEY (branch_id) REFERENCES branch(branch_id) ON DELETE CASCADE
 );

and the error I'm getting

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 'supplier ( branch_id INT, supplier_name VARCHAR(40), supply_type ' at line 1


Solution

  • It is not allowed to use table names with space(s) unless you use `. This means you need to change this to...

    CREATE TABLE `branch supplier`...
    

    or to something without space, as example

    CREATE TABLE branch_supplier...