Database Design 27 - Foreign Key

Поділитися
Вставка
  • Опубліковано 4 лют 2025

КОМЕНТАРІ • 42

  • @veedjohnson
    @veedjohnson 3 роки тому +18

    Hi, just here to tell you that it's 2021 and this database playlist is really helpful!

  • @codebreakthrough
    @codebreakthrough  10 років тому +1

    Learn about Foreign Keys by watching this video. Please click "like" on the video!
    buff.ly/1swqZBQ

  • @wejoyskp
    @wejoyskp 8 років тому +6

    Thank you Caleb. Very clear and i understood with your real life example.

  • @asirsakin5562
    @asirsakin5562 8 років тому +5

    i,v noticed you worked late at night sir,
    but you made that morning useful

  • @abdessamadbourhjoul7386
    @abdessamadbourhjoul7386 3 роки тому +1

    Still helpful in 2021!
    thank you for this masterpiece.

  • @dhegana
    @dhegana 8 років тому +1

    Nice one caleb! Please keep on making videos about database

  • @UsefIbba
    @UsefIbba 7 років тому +3

    What's up dude, thanks bro!

  • @FabianBarajas
    @FabianBarajas 9 років тому +1

    really well done. Thanks

  • @titorojas7703
    @titorojas7703 8 років тому

    Hey caleb, I was wondering how to join tables with no common columns?
    Love your videos dude!

  • @ganiyatadebayo8725
    @ganiyatadebayo8725 6 років тому +1

    Hi, I've got an orderDetails table that has orderID and productID as primary keys. However, i'm confused if they are both going to be foreign keys as well.

  • @Serraomomma
    @Serraomomma 9 років тому +1

    Thanks!

  • @arnmazing3156
    @arnmazing3156 6 років тому

    IDK if I'm getting this but as I understand if you want to create a table that needs columns from another table you have to use Foreign Key to access it. Kinda like in java to access another class you need to initialize an object that reference the class that you want to use. Do foreign keys have to be Primary keys?

  • @nayooti298
    @nayooti298 9 років тому

    Hey Caleb, tx for all the work.
    I do have a question though. If a primary key of a entity-type is kombined by two attribute-types, say a student's 'first name' and 'last name'. How does is this student represented in a different table, or generally: how does the foreign key looks like, when it's related primary key consists of two or more keys? Tx!!!!

  • @dis0rder3d
    @dis0rder3d 10 років тому

    way to break it down my brother. thanks

  • @Patignar
    @Patignar 9 років тому

    Great Tutorial!

  • @nikunjkelatkar313
    @nikunjkelatkar313 9 років тому

    nice video dude thanx

  • @rohitmewar9094
    @rohitmewar9094 10 років тому

    thanks Caleb... :)

  • @whereweregoingwedontneedey4374
    @whereweregoingwedontneedey4374 10 років тому

    Here's a question - the reasoning for using lookup tables and using foreign keys is sometimes stated as to avoid mistakes if things change (in this example, you gave if the building name changed from legit to legitt - however, doesn't the DbMS automatically do this for you anyway - for example, change all instances of legit to legitt?

    • @3Nex
      @3Nex 9 років тому

      Paul French Of course not, and it would be horrible if it did. That would also imply that if you have a table with users (where there is a varchar column called `name`), and two of those users were named David; when one of the Davids changes his name to Mark, the other one would have his name changed. That is never supposed to change automatically, in the real world, or a digital one.
      Unless you have specifically designed your table to do so because of your own internal reasons that are familiar to you and make sense for your scenario.

  • @najoudalabeedi8906
    @najoudalabeedi8906 10 років тому

    thank u so much

  • @changeluhia
    @changeluhia 6 років тому

    this video is legitt

  • @arslanali774
    @arslanali774 6 років тому +1

    how can i connect with you ?

  • @hermainesanchez4514
    @hermainesanchez4514 8 років тому

    gwapo tani lain man agi hehehe

  • @GinnHardcore
    @GinnHardcore 7 років тому

    If you take his example and say you have 3 building 16's because you have building 16 recurring does that mean the database is not normalized or are foreign keys an exception to the rule and aloud duplicates in there row

    • @codebreakthrough
      @codebreakthrough  7 років тому +1

      Foreign key columns can allow duplicates if the column is labeled NULL-able. That's because they are purely a reference and the db restrains you from doing dumb stuff.

    • @GinnHardcore
      @GinnHardcore 7 років тому

      CalebTheVideoMaker2 thank you for the reply Caleb much appreciated:) I think I've near enough watched your entire series!

  • @amandaknapton1626
    @amandaknapton1626 10 років тому +1

    A class im taking touches on databases and we are supposed to develop tables based on a case study and then draw relationships, primary and foreign keys. Every time I think I get it, I don't. Help?

    • @codebreakthrough
      @codebreakthrough  10 років тому +1

      Amanda Knapton my advise is to just study your face off on the matter. School will try to tell you there is only 1 definite right way to do things, but this isn't always the case. Often it is though.Learn every concept in this course. They will cover all of the subjects covered in class likely. Any other questions can be left in a comment.

    • @amandaknapton1626
      @amandaknapton1626 10 років тому

      Thanks Caleb, you are very good in your videos! Regarding this primary and foreign key business, Lets say *PtID# is the primary key in a table, in the next table I would have it as the **foreign key so that I will have the direct relationship... but then what would the *primary key of my second table be since the PtID# seems to be the only unique identifier in the table but it is already the foreign key? follow? I'm just trying to get a basic understanding because this a relatively small part of the class content, and maybe 35% of the final grade... theres a group assignment due saturday and then our database individual assignments are due in a month. With other assignments due before that and moving on to different topics. Thanks again!
      p.s. I'm also not so savvy about how youtube comments even work... so ummm hopefully after I leave the library I will be able to find your reply...have so much to learn.

    • @codebreakthrough
      @codebreakthrough  10 років тому +1

      I'd tell you how to find your reply but that would kinda be pointless :P
      The second table...what is it for? What is it storing? Whatever it is storing will have a primary key.
      So I'm guessing PtID# is pateint ID number or something?
      Well if you had a table for diet plans you would have diet plan ID (PK) and PtID (foreign key).
      It might not be the same example but you can apply it the same.

  • @satadhi
    @satadhi 10 років тому

    good job man

  • @minhtao9774
    @minhtao9774 7 років тому

    Thank youuuuuuuuuuuuu!!!!!!!!!!!!!

  • @pbchandra1
    @pbchandra1 8 років тому

    can there be two primary keys in a single table ?
    For example if a table CONTACT contains contact number, contact name, address. Then generally contact number has to be primary key. But what if two different persons use the same contact number ? (like father and son).

    • @codebreakthrough
      @codebreakthrough  8 років тому +1

      +Bharat Chandra there can never be two primary keys. There can be composite keys or surrogate keys, though. If you don't have enough to make each row unique, consider adding a column or two!

    • @mohamed_elhariry
      @mohamed_elhariry 7 років тому

      There can't be more than one primary key in a relation (table). Therefore you might think about choosing another key as primary.
      Although, if you can't choose another one, you might consider creating a composite key or a surrogate key.
      A composite key combines multiple attributes so that you can uniquely identify a row. For example, in a given table where you have attributes like name, surname, address, phone#, neither of these attributes alone can uniquely identify a row. But if you consider all or some of them together, then you will be able to uniquely identify a specific row.
      This is how you create a composite key:
      CREATE TABLE CONTACT(
      Name VARCHAR(20),
      Email VARCHAR(50),
      PRIMARY KEY (Name, Email)
      )
      A surrogate key, instead, is just an incrementing ID that you create every time a new tuple is created. That way you will always be able to uniquely identify a row.
      This is how you create a surrogate key:
      CREATE TABLE CONTACT(
      ID int NOT NULL AUTO_INCREMENT,
      Name VARCHAR(20),
      Email VARCHAR(50),
      PRIMARY KEY (ID)
      );

    • @sreism
      @sreism 7 років тому

      +Mohamed Elhariry can you please explain the difference a bit more?

    • @sreism
      @sreism 7 років тому

      +Mohamed Elhariry can you please explain the difference a bit more?

  • @sierrakilo9695
    @sierrakilo9695 6 років тому

    Hey Caleb, great videos, hope you're still active here. So if you are adding 2 foreign keys to one entity, what does that make it? As in 1:n or m:n at that point?

    • @AnontheGOAT
      @AnontheGOAT 5 років тому

      I think it would be a m:n because you are connecting essentially two data tables/entities to one or more rows in another table.

  • @abrorakhmedov7389
    @abrorakhmedov7389 2 роки тому

    well its 08.2022 still helpfull

  • @albaghdadinoah7196
    @albaghdadinoah7196 3 роки тому

    Why I do feel that you are explaining the same concepts in the last 10 videos

  • @vikasgautam7717
    @vikasgautam7717 7 років тому

    handwriting is pathetic or else good