doulei1965 2016-06-03 13: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 13: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条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大