Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Adding COMMENT to a Foreign Key

I'm translating an old database SyBase to MySQL and I have this DDL Query:

ALTER TABLE "DBA"."tab_prodotto"
  ADD FOREIGN KEY "fkey_idlinea" ("tpr_idlin") 
  REFERENCES "DBA"."linea" ("lin_id")
go
COMMENT ON FOREIGN KEY "DBA"."tab_prodotto"."fkey_idlinea" IS
'Riferimento linea'
go

The Alter part of query works well, but I have troubles on COMMENT. I already know that I can alter a column for adding a COMMENT, but is that possible for foreign keys too? If yes, how? I haven't find nothing special on documentation. Thank you in advance.

like image 481
IssamTP Avatar asked Jan 16 '23 10:01

IssamTP


1 Answers

The MySQL reference manual shows the allowed syntax for the FOREIGN KEY command to be:

  [CONSTRAINT [symbol]] FOREIGN KEY
  [index_name] (index_col_name, ...)
  REFERENCES tbl_name (index_col_name,...)
  [ON DELETE reference_option]
  [ON UPDATE reference_option]

reference_option:
   RESTRICT | CASCADE | SET NULL | NO ACTION

There is no allowable COMMENT section. It looks like this is not allowed.

The manual I referenced above is from version 5.6. I checked versions 5.1 and 5.5 and the syntax is the same.

like image 50
Kevin Bedell Avatar answered Jan 20 '23 16:01

Kevin Bedell