Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2006
    Posts
    26

    Unanswered: 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.

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    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);

  3. #3
    Join Date
    Jan 2006
    Posts
    26
    Figures I'd do something stupid like that. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •