doulei1965 2016-06-03 05:22
浏览 47
已采纳

如何在phpmyadmin中创建外键

I want to make doctorid a foreign key in my patient table.

So I have all of my tables created - the main problem is that when I go to the table > structure > relation view only the primary key comes up that I can create a foreign key (and it is already the primary key of the certain table that I want to keep - i.e Patient table patient is enabled to be changed but the doctor Id -I have a doctor table also- is not enabled).

I have another table with two composite keys (medicineid and patientid) in relation view it enables me to change both

Do I have to chance the index of doctor ID in patient table to something else? both cannot be primary keys as patient ID is the primary for the patient table - doctor is the foreign.

table

I hope anyone can help

Kind regards

  • 写回答

4条回答

  • dsflxcfuw27742248 2016-06-03 05:27
    关注

    You can do it the old fashioned way... with an SQL statement that looks something like this

    ALTER TABLE table_name
        ADD CONSTRAINT fk_foreign_key_name
        FOREIGN KEY (foreign_key_name)
        REFERENCES target_table(target_key_name);
    

    This assumes the keys already exist in the relevant table

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?