Step 1: Create two tables tbl_course_detail and tbl_student_detail in the database student as per the following schemas shown below:
tbl_course_detail
Name | Type | Constraint |
---|---|---|
Course_ID | Varchar(10) | Primary Key |
Course_name | Varchar(20) | Not Null |
Credit | Int(1) | Not Null |
Semester_type | Varchar(15) | Not Null |
tbl_student_detail
Name | Type | Constraint |
---|---|---|
Enr_No | Int(12) | Primary Key |
Name | Varchar(30) | Not Null |
City | Varchar(20) | Not Null |
Course_ID | Varchar(10) | Not Null |
Our aim is to import the Primary Key Course_ID of table tbl_course_detail as a Foreign Key in the table tbl_student_detail.
Step 2: Open the "Structure" of tbl_student_detail and click the "Relation view" button.
Step 3: Select 'tbl_course_detail' from the drop-down beside Course_ID. You will automatically get Course_ID in the second field. Click the "Save" button.
You have successfully created the Foreign Key in table tbl_student_detail. You can check by inserting the values. The entire process is shown in the GIF image below: