This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
howdy ya'll,
newbie here and I'm working my way through The Complete SQL Bootcamp: Zero to Hero by Jose Portilla on Udemy.
I'm confused as to how to go about adding or dropping a foreign key constraint on an already existing table for a single column. In the lecture he uses SET and DROP, with ALTER TABLE but then also briefly mentions ADD CONSTRAINT but doesn't differentiate when to use which one.
For example, I have 3 tables. One called teachers, one called students, and I tried making a third called stu_tea that just combines Teacher_id from teachers, and student_id from students. Obviously I could have done the foreign key stuff initially when creating stu_tea, but I wanted to see how it could be done after the fact.
I can't for the life of me figure out how to DROP the foreign key part.
To add one I got the following to work:
ALTER TABLE stu_tea
ADD FOREIGN KEY (teacher_id)
REFERENCES teachers(teacher_id);
but how would I drop that same constraint?
I've tried googling it, and only ended up more confused after trying every possible syntax I could find.
Any help and explanation is MUCH appreciated!
Happy Holidays Ya'll
Subreddit
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnSQL/co...