How to insert value into column of existing table?
I have a table which have 5 column
id | firstname | lastname | address | email | course_id
1 | Waleed | Khan | Karachi | something@gmail.com | null
This table has 1000 rows but I added course_id column and want to insert value from another table named Courses.
You'll first need to specify what relationship the two tables are sharing. As mentioned in your question you want to create a column_id column in Students table. You'll create this column and then add foreign key constraint to the column. Add the constraint using ALTER TABLE Students ADD CONSTRAINT constraint_name FOREIGN KEY (column_id) REFERENCES Courses(id) ON DELETE CASCADE ON UPDATE CASCADE;
CASCADE on deleteion and updation will take care of record updation and deletion in Students table.