How to create a foreign key in phpmyadmin

0 votes

In my patient table, I want to add a foreign key for doctorid.

I have all of my tables established, but the main issue is that only the primary key appears when I go to the table > structure > relation view so that I may build a foreign key (and it is already the primary key of 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 (patientid and medicineid) that allow me to alter both in relation view. Should I change the doctor ID index in the patient table to anything else? Given that patient ID is the primary key for the patient table and doctor is the foreign key, neither can be the primary key.

table

Can someone please help me with this?

Aug 1, 2022 in PHP by Kithuzzz
• 38,000 points
2,192 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You can execute it using a traditional SQL statement that appears somewhat like this.

ALTER TABLE table_1_name
    ADD CONSTRAINT fk_foreign_key_name
    FOREIGN KEY (table_1_column_name)
    REFERENCES target_table(target_table_column_name);

For instance, if the field created_by in your books database refers to the column id in your user table:

ALTER TABLE books
    ADD CONSTRAINT books_FK_1
    FOREIGN KEY (created_by)
    REFERENCES users(id);

I hope this helps you.

answered Aug 3, 2022 by narikkadan
• 63,600 points

edited Mar 5

Related Questions In PHP

0 votes
0 answers

How to generate a create table script for an existing table in phpmyadmin?

How can I generate a create table ...READ MORE

Aug 4, 2022 in PHP by Kithuzzz
• 38,000 points
1,108 views
0 votes
1 answer

How to create a database using PDO in PHP?

Hello @Hitesh, Yes, you can create a database using ...READ MORE

answered Nov 9, 2020 in PHP by Niroj
• 82,840 points
6,698 views
0 votes
0 answers

How to sort an array of associative arrays by value of a given key in PHP?

Given this array: $inventory = array( ...READ MORE

Jul 24, 2022 in PHP by Kithuzzz
• 38,000 points
739 views
0 votes
1 answer

What is a Cookie? How to create Cookies With PHP?

A cookie is often used to identify ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,840 points
3,963 views
0 votes
2 answers

How can we create a session in PHP?

Hello, niroj. Here is my idea session_start(); $_SESSION['USERNAME'] ...READ MORE

answered Dec 7, 2020 in PHP by Famous
• 140 points
1,442 views
0 votes
1 answer

How to log in to phpMyAdmin with WAMP?

Hello @kartik,  Try-Username: root Password: (No password set). Sometimes it doesn't ...READ MORE

answered Apr 9, 2020 in PHP by Niroj
• 82,840 points
7,380 views
0 votes
0 answers

Fatal error : execution time of 30 seconds exceeded in phpMyAdmin

My MySQL table has 6.5 million records ...READ MORE

Jul 26, 2022 in PHP by Kithuzzz
• 38,000 points
1,878 views
0 votes
1 answer

Why is not preferable to use mysql_* functions in PHP?

The reasons are as follows: The MySQL extension: Does ...READ MORE

answered Sep 7, 2018 in Database by DataKing99
• 8,250 points
1,401 views
0 votes
2 answers
0 votes
2 answers

How to send data to my database from html and css Contact Us Form?

Hello @Sign, It is simple to create contact ...READ MORE

answered Aug 4, 2020 in Database by Niroj
• 82,840 points
36,288 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP