'Implementing ER Diagram in MySQL, receiving Error 1064 during altering

I'm trying to establish an ER diagram for my database. There are 5 tables in my database.

enter image description here

When I want to make the relationship between industry_number and company_inustry, it always said there is a 1064 error. my code is:

ALTER TABLE company_inustry
ADD FOREIGN KEY (Detailed Industry)
REFERENCES Industry_number(Detailed Industry)

Error is #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Industry) REFERENCES Industry_number(Detailed Industry)' at line 2.

I'm a new learner. Please help me... Thank you!



Solution 1:[1]

You have spaced in the column names so you need quote them.
It would be a better idea to use an underscore Detailed_Industry as you have done in the table names. If you do not you will have the same problem in every query that refers to these columns.

ALTER TABLE company_inustry ADD FOREIGN KEY ("Detailed Industry") REFERENCES Industry_number("Detailed Industry")

Solution 2:[2]

You need to use double quotes (" ") if you have space in name of the tables. use underscore as a good industry practice.

Use this query for correct syntax:

ALTER TABLE company_inustry ADD FOREIGN KEY ("Detailed Industry") REFERENCES Industry_number("Detailed Industry")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Ritik Banger