HomeОбразованиеRelated VideosMore From: Manish Sharma

SQL tutorials 18: SQL Foreign Key Constraint

364 ratings | 100279 views
SQL Tutorial 18: SQL foreign key constraint. Topic covered in this tutorial 1. Defining SQL foreign key using create table at column level 2. Defining SQL foreign key using create table at table level 1. Defining SQL foreign key using Alter Table statement Links Website article: http://www.rebellionrider.com/sql-foreign-key.htm Primary key tutorial: http://www.rebellionrider.com/sql-foreign-key.htm Create Table Tutorial: http://www.rebellionrider.com/sql-create-table.html Tool used in this tutorial is SQL Developer. This tutorial series is part of SQL expert exam certification training. if you are preparing for SQL certification you can use my tutorials. This SQL Tutorial is a part of free training. Copy Cloud referral link || Use this link to join copy cloud and get 20GB of free storage https://copy.com?r=j7eYO7 Contacts E-Mail [email protected] Twitter https://twitter.com/rebellionrider Instagram http://instagram.com/rebellionrider Facebook. https://www.facebook.com/imthebhardwaj Linkedin. http://in.linkedin.com/in/mannbhardwaj/ Thanks for linking, commenting, sharing and watching more of our videos This is Manish from RebellionRider.com Foreign key is an Input/output data constraint which is also known as referential integrity constraint. Foreign key represent a link or say a relationship between columns of tables. Similar to primary key constraint Foreign Key constraint is also of two types. Simple Foreign key constraint and Composite Foreign key constraint. Constraint which involves only one column in foreign key in child table and one column in reference key in parent table is called Simple Foreign Key. While the constraint which involves more than one column in foreign key in child table and more than one column in reference key in the parent table is called Composite Foreign Key.
Html code for embedding videos on your blog
Text Comments (56)
sumit chawla (2 months ago)
Dekhna sai pehla Manish sir ka video like kardo kyu aisa apko kisi training institute mai Paisa leke bhi nahi padha jayega
Rupam Chakraborty (3 months ago)
Reference author(author_id) or Reference Parents(author_id)
lokesh paruchuri (4 months ago)
How to identify the table does have foreign key or not .By sql cmd prompt.
CHETIPATTU C (6 months ago)
is it possible to drop foreign-key table directly???
George Cristian Iordan (7 months ago)
God I try to make a reference between 2 tables 2 columns for 2 days and I couldn't do it.... I hate your accent but sir.... you are a GREAT TEACHER, thank you in my country they say > Hope you reach 100 y old! or more ... have a great day
Mohammad Shakil (10 months ago)
what is constraint ...need a tutorial define constraint
Naumi Zafar (10 months ago)
hi bro good evening i want to know how to insert more than one foreign keys in table? is there any limit for foreign keys?
Sharanya Boddula (10 months ago)
Awesome explaination and nice ppt..
Jumping Clasher (10 months ago)
bhai harkuch harkuch batat ra hai tu yaar
ruchi jain (1 year ago)
Hi Manish, your videos r the best,really i feel so comfortable with oracle sql now Can u plz make video on new features of 12c, i have my interviews in coming weeks ,it would be of great hlp .
Rahul choudhary (1 year ago)
Watching your all vidoes it is enough to crack ocp xam???
Robert Bhandari (1 year ago)
Thank you #legend
monideep gupta (1 year ago)
Thanks a lot for such great videos !!!!! Please plan to do some Data Analytics videos also, it would be of great help !!!!
Kaz Tee (1 year ago)
can someone please help with this sql i want the user to update his profile. i create a profile page now i cant get the sql correct for the upadte button. i tried update user (table) set firstname,lastname,address,email,telephone (fields in my table) where 'email' (email it uses to update that particular user account details
news knowledge (1 year ago)
hi sir, your lectures very informative for me meny 2 table create kiye hain or aik new 3rd table create kr k just usme un dono tables ki primary keys as a foreign keys lgani hai kya ap mjhe 3rd tables ka syntax send kr de gy yahan please
Sathish Kumar (1 year ago)
Dear Manish, If I have to create more than one primary key, I have to use composite Primary key. Fine. When I try to keep one of this Primary key to my foreign key error is raised . can you give your reply please
shweta singh (1 year ago)
thank you sir for clear my doubts about foreign key
Blizzard Kompressor (2 years ago)
You are an awesome Teacher! A lot of things that I never understood, it took me only 10 Min. with you and now I have understand everything! Thanks a lot Bro! Do not stop teaching the World how to do this! =) Saludos!
sanseora sandy (2 years ago)
sir how can i save sql database to notepad .txt format plz explain
jubin joy (2 years ago)
Is there a reason for using the code (CONSTRAINT bok_ai_fk). Does it affect in any way?
irshad (2 years ago)
sir which software are you using for this type of queries plz tell
Manish Sharma (2 years ago)
In almost all the videos I have used Oracle SQL Developer a free GUI by Oracle Itself. I have done an installation video of the same, here is the link https://youtu.be/zliF8kXVmeE
Sabit Mubarik (2 years ago)
You got an amazing talent of teaching others , keep on doing this sacred work Dear.... The thing is that I followed your tutorial for installing the oracle 11g complete setup all was well but in the end whenever I login into my Enterprise Manager account it says something like this(INTERNAL ERROR HAS OCCOURED AND DO SOMETHING WITH YOUR LOG FILES)... please tell me I am desperate to see the dashboard of EM opening on my screen.... With Love from PAKISTAN <3
amrita mehara (2 years ago)
Sir your tutorial data is not showing clear.. It's too small
sai prasad (2 years ago)
difference between column level and table level in oracle ? please tell
Loux (2 years ago)
there's no difference, its just depending on how you want to write it and he showed both ways
Koann (2 years ago)
7:18 - Take a glass of water jajajaj
Jyotimoi das (2 years ago)
Thanks Manish for the oracle SQL tutorials. It's been grate help !!!!
long tran (2 years ago)
Mr Sharma, I like your videos. I'm using ORACLE SQL 11G express and I have one request? would you continue on with your (this) video and make a video with real database tables to show how FOREIGN KEY work with real data??? thank you in advance!
rishabh rastogi (2 years ago)
its vry helpfull... thanks
Manish Sharma (2 years ago)
+rishabh rastogi You are most welcome. I am glad your find my videos helpful. Do make sure to Like & Share them.
Sean Dougan (2 years ago)
this was really well done
Mladen Skywalker (3 years ago)
I have a question. What if I have table A, table B and table C. Let's say table C is linked with both table A and B. How would I define foreign keys in table C? Could I add two constrains for each reference? Thanks. :)
Blizzard Kompressor (2 years ago)
Yes, you can have more then one constraint for each references... ;)
Matt Robertson (2 years ago)
I would also like to know the answer to this question Manish!
Anatolii Stepaniuk (3 years ago)
I know how to define a foreign key - there's a lot of information about this on the Internet. But I do not quite understand the details of how the foreign key is used. THAT would be a very valuable information in your tutorial
Andrej D (2 years ago)
+Anatolii Stepaniuk. Imagine you are an IT guy in a company. IT department has ID 5. This means that in "Employees" table there would be "Anatolii" with department_ID=5. Now I go to the separate "Departments" Table and try to delete the department with ID 5. If there is NO Foreign Key, I will successfully delete the department, and "Anatolii" will end up with NO department assinged. And that's bad :). Hope this helped.
Upekshe Ruwanpathirana (3 years ago)
Holy shit man!!! U have no idea how much u helped me for my Bsc... I never went to the classes for the subject DBE :)
arpan saini (2 years ago)
to define key in-front of column i.e sir refers to Column level To define key at the end of all columns i.e sir refers to Table level. That's it
sai prasad (2 years ago)
can u tell the difference between column level and table level
Manish Sharma (3 years ago)
Although I never encourage bunking classes yet I'm just thrilled that my videos helped you. Have fun 😊👍
Gayatri miriyala (3 years ago)
Hi..Iam Gayatri.Just now i have watched ur video on primary key,foreign key.Your explanation is so good.. nice and perfect lecture.I think it will help me alot .Thank u so much...
Manish Sharma (3 years ago)
+Gayatri miriyala Thanks, glad you enjoyed my videos. Please like and share the videos on your social networks and help other in learning the concepts oracle database in free.
Md Arafat Wasiullah (3 years ago)
Explanation throughout the video is outstanding ..Keep it up ..!! Looking for more playlists on various CS topics :)
Susy Chappa López (3 years ago)
THANK ME help much, have an SUBSCRITORA MORE IN PERU My English is not very good SORRY
Avi Levin (3 years ago)
Great video, Thanks!
John Richardson II (3 years ago)
Great tutorials, Manish! Thanks
Sia Lee (4 years ago)
your video is very small i don't see it please zoom
Gul Shahzad Sarwar (4 years ago)
Thanks Manish for such a wonderful lecture.
Deepak Srighakolapu (4 years ago)
thanks  for explaining
3231cool (4 years ago)
Nice and very informative!! Explained in simple language. Good work !
Faranak So (4 years ago)
perfect
Manish Sharma (4 years ago)
+Faranak So Thank you so much.
Abadhesh Panda (4 years ago)
Hi Manish.. What is the use of  Constraint? With link to Primary key or Foreign Key ?
Manish Sharma (4 years ago)
Foreign key is a referential integrity constraint which helps in several manners like establishing a relationship (link) between parent and child table which you can then use in several ways for example, Joins is one of them. Uses of FK constraint include: ·         1.  It forestalls those actions that can lead to destruction of links between various tables.          2.  It ensures that the data that is being inserted in the foreign key column is essentially coming from the table it points to. This guarantees the validity of the data. Incidentally Primary key has the job of identifying each row uniquely in a table. You can go through these links for more knowledge on Primary and Foreign key. http://bit.ly/primary-key http://bit.ly/foreign-key thanks
Manish Sharma (4 years ago)
Before jumping over my next tutorial I'll suggest you all to watch my Foreign key tutorial. It will help you to understand the concepts more clearly.#SQL #SQLDeveloper #OracleDatabase

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.