If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Adding a constraint to table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-17-07, 10:03
Eiolon Eiolon is offline
Registered User
 
Join Date: Jan 2006
Posts: 26
Adding a constraint to table

Is it possible to add a constraint to a table once it has already been created?

Here is my table:

Code:
id int not null primary key auto_increment,
first_name varchar(25) not null,
last_name varchar(25) not null,
job_id int,
department_id int,
supervisor_id int
I want to add a recursive constraint that references the supervisor_id to the id column.

I tried:

Code:
alter table employees add constraint super_emp foreign key (supervisor_id) references id;
I get an error 1005 saying that I can't create a table.

Thanks for your help.
Reply With Quote
  #2 (permalink)  
Old 11-17-07, 11:35
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
You forgot to mention the referenced table in your alter table statement:
Code:
alter table employees 
  add constraint super_emp foreign key (supervisor_id) 
  references employees(id);
Reply With Quote
  #3 (permalink)  
Old 11-17-07, 11:41
Eiolon Eiolon is offline
Registered User
 
Join Date: Jan 2006
Posts: 26
Figures I'd do something stupid like that. Thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On