SQL REFERENCES关键字语法错误求助(MySQL/PostgreSQL均复现)
references Personne(id_personne)) Hey there! Let's work through this syntax error you're hitting in both MySQL and PostgreSQL—since it's popping up across two databases, the issue is almost certainly a universal syntax mistake rather than a DB-specific quirk.
Common Causes to Check
Extra closing parenthesis
The error points directly to))at the end of that line, which means you’ve probably added an extra)where it doesn’t belong. For example, when defining a foreign key in aCREATE TABLEstatement, the correct syntax only needs one closing parenthesis after the referenced column:-- Correct CREATE TABLE YourTable ( id INT PRIMARY KEY, personne_id INT, FOREIGN KEY (personne_id) REFERENCES Personne(id_personne) );A super common slip-up is tacking on an extra
)like this:-- Incorrect (extra closing parenthesis) CREATE TABLE YourTable ( id INT PRIMARY KEY, personne_id INT, FOREIGN KEY (personne_id) REFERENCES Personne(id_personne)) -- Extra ) here );Misplaced foreign key definition
Double-check that your foreign key clause is properly nested inside the main table definition parentheses. If you accidentally close the table definition before adding the foreign key, or mix up the order of clauses, it’ll trigger a syntax error.Typos in table/column names (less likely here)
While this usually throws a "table/column not found" error instead of a syntax issue, it’s worth verifying thatPersonneandid_personneexactly match the actual names in your database (note PostgreSQL is case-sensitive if you used quoted identifiers when creating the table).
Next Step
If you can share the full SQL code you’re running, it’ll be even easier to pinpoint the exact issue—but based on the error message, that extra closing parenthesis is the most probable culprit.
内容的提问来源于stack exchange,提问作者user7732640

