Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to alter table

 
pankaj patil
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to alter table in mysql

this is what i have written

it gives error

alter table test add(centerid int) foreignkey (test,centerid) reference(result,centerid);

can any sort out this problem
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the MySQL docs:

ALTER TABLE tbl_name
...
ADD [CONSTRAINT [symbol]]
FOREIGN KEY [index_name] (index_col_name,...)
[reference_definition]


As you will see you are missing the CONSTRAINT keyword, you need to reinstate the space between "foreign" and "key", you need to give the foreign key a name and correctly define the column it is on.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic