Home > Mobile >  questions about ER diagram when I using MySQL
questions about ER diagram when I using MySQL

Time:04-20

I'm trying to establish 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 leaner. Please help me... Thank you!

CodePudding user response:

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")

CodePudding user response:

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")
  • Related