Primary Key and Foreign Key in MySQL Explained with Examples | MySQL Tutorial

Поділитися
Вставка
  • Опубліковано 5 жов 2024
  • In this video, learn Primary Key and Foreign Key in MySQL Explained with Examples | MySQL Tutorial. Find all the videos of the MySQL Full Course in this playlist: • MySQL Full Free Course...
    💎 Get Access to Premium Videos and Live Streams: / @wscubetech
    WsCube Tech is a leading Web, Mobile App & Digital Marketing company, and institute in India.
    We help businesses of all sizes to build their online presence, grow their business, and reach new heights.
    👉For Digital Marketing services (Brand Building, SEO, SMO, PPC, SEM, Content Writing), Web Development and App Development solutions, visit our website: www.wscubetech...
    👉Want to learn new skills and improve existing ones with in-depth and practical sessions? Enroll in our advanced online courses now and make yourself job-ready: courses.wscube...
    All the courses are job-oriented, up-to-date with the latest algorithms and modules, fully practical, and provide you hands-on projects.
    👉 Want to learn and acquire skills in English? Visit WsCube Tech English channel: bit.ly/2M3oYOs
    📞 For more info about the courses, call us: +91-7878985501, +91-9269698122
    ✅ CONNECT WITH THE FOUNDER (Mr. Kushagra Bhatia) -
    👉 Instagram - / kushagrabhatiaofficial
    👉 LinkedIn - / kushagra-bhatia
    Connect with WsCube Tech on social media for the latest offers, promos, job vacancies, and much more:
    ► Subscribe: bit.ly/wscubech...
    ► Facebook: / wscubetech.india
    ► Twitter: / wscubetechindia
    ► Instagram: / wscubetechindia
    ► LinkedIn : / wscubetechindia
    ► UA-cam: / wscubetechjodhpur
    ► Website: wscubetech.com
    -------------------------------------| Thanks |--------------------------
    #MySQLTutorial #MySQLCourse #MySQL

КОМЕНТАРІ • 47

  • @gauravpathak4479
    @gauravpathak4479 Рік тому +5

    01:27 Primary key and foreign key constraints in relational databases
    02:54 Creating a primary key in a database for unique identification
    04:21 Foreign key creates linking between two tables
    05:48 Foreign keys link the primary keys of two tables, enabling joint operations.
    07:15 Creating a students table with primary and foreign keys
    08:42 Creating a city table with id as primary key and city_id as foreign key
    10:09 City ID 522 is located in city ID 609
    11:29 Enforcing primary key and foreign key constraints is crucial in large-scale relational databases.

  • @vinaymishra8533
    @vinaymishra8533 2 роки тому +2

    sir great work I had search more then 10 tutorials to find this concept but now it is clear

  • @strangerealm796
    @strangerealm796 Рік тому +4

    Sir table banai hai lekin bol rha hai referencing column city_id and referenced column cities (id)is incompatible.😢

  • @theAdam586
    @theAdam586 7 місяців тому

    5. What is a foreign key? Write a query to implement the same in MySQL.
    This is one of the prevalent MySQL queries interview questions for both beginner and experienced candidates. A foreign key is used to connect two tables. A FOREIGN KEY is a field (or assortment of it) in one table that alludes to the PRIMARY KEY in another table. The FOREIGN KEY requirement is utilised to forestall activities that would crush joins between tables.
    To assign a foreign key, it is important to mention it while creating the table. It can be assigned by invoking the FOREIGN KEY query. Something like this:
    FOREIGN KEY (Any_ID) REFERENCES Table_to_reference(Any_ID)

  • @MuhammadAyaz_786
    @MuhammadAyaz_786 Рік тому +3

    what a great work sir

  • @abdul_moiz_7
    @abdul_moiz_7 Місяць тому

    Great explanation of this topic.

  • @rksvlog2529
    @rksvlog2529 Рік тому +1

    Great....amazing technique

  • @vedsharma1933
    @vedsharma1933 Рік тому +1

    thanks

  • @samiahirfanghouri1136
    @samiahirfanghouri1136 5 місяців тому

    Good explanation

  • @manyadewangan6765
    @manyadewangan6765 Рік тому +1

    I have a good doubt sir if we use primary key while creating columns then unique constraint ka koi use nhi hoga?

    • @Bhumi_rai
      @Bhumi_rai Рік тому

      unique key mysql accept hi nhi karaga because 1 column pa 2 constraint nhi hote

    • @hamzaarif6000
      @hamzaarif6000 Рік тому +2

      Jab ap kisi column ko primary key set krtay ho to unique constraint lganay ka faida hi nahi q k primary key k column ki hr value unique e hoti hai. Primary key or Unique constraint mein difference ye hai k Primary key hum table k kisi aik column pr lga sktay hain jabkay unique constraint hum table k multiple columns pr lga sktay hain

    • @hamzaarif6000
      @hamzaarif6000 Рік тому +1

      ​@@Bhumi_rai2 constraint ho sktay hain. Mainy try kiya tha or mere accept hogaye thy

  • @coolanujkumar5
    @coolanujkumar5 Рік тому +2

    missing index for constraint .... in the referenced table

  • @nikhilmore3771
    @nikhilmore3771 Рік тому +1

    PRIMARY KEY is parent
    (confirm on other sources)

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

    kodular ya thunkable per ek video upload kijiye sir please

  • @technicalrider6196
    @technicalrider6196 Рік тому +2

    Wrong teaching u have add primary key to city_id if ur refering city_id primary key to foreign key (cid)

  • @strangerealm796
    @strangerealm796 Рік тому +3

    Jinka error aa rha ho vo cities ki table me primary key (Id) rakhe phrr chal jayega.

  • @RajeshKumar-jx9ql
    @RajeshKumar-jx9ql Рік тому

    city_id kisi or table ki primary key hone wali h.....esa kyu hoga???? jbki kisi or table me to already primary ki hmne de rakhi h

  • @bhaveshmorankar8579
    @bhaveshmorankar8579 Рік тому

    failed to add the foreign key dikha raha hai isko kaise solve kre?

  • @prasantaroutray2506
    @prasantaroutray2506 11 місяців тому

    bro are you from odisha?

  • @lion7366
    @lion7366 Рік тому

    Error Code: 1822. Failed to add the foreign key constraint. Missing index for constraint

    • @khushiv2003
      @khushiv2003 Рік тому

      Same problem

    • @ruturajkadam5164
      @ruturajkadam5164 Рік тому

      ​@@khushiv2003add constraint while adding foreign, you can give it any namr

    • @ayushpratap8301
      @ayushpratap8301 Рік тому +1

      In the 1st table that is "cities",
      at last write
      primary key (cid)

  • @Ukmmtj1
    @Ukmmtj1 9 місяців тому +1

    2:06 email bhi unique hi hota h🤔

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

    sir pura syllabous nahi hua hai abhi

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

    failed to add misssing constraints error aa rha hai sir g??

    • @Tadapatiatma
      @Tadapatiatma Рік тому

      Mila answe nhi mila to main bata sakta hun

    • @divyanshsingh8807
      @divyanshsingh8807 Рік тому

      Koi batayega iska solution kya h

    • @pulkitjadoun8596
      @pulkitjadoun8596 Рік тому

      @@Tadapatiatma bata de bhai kese theek hoga

    • @Tadapatiatma
      @Tadapatiatma Рік тому +1

      ​@@pulkitjadoun8596 pehle apko 1st table Banna hai jismein apko primary key rakhna hai jo apka 2nd table ka foreign key hoaga means apko pehle 1st table ka primary key create karna ho ga tabhi to ap usko 2nd table mein foreign key aur reference de payenge

    • @pulkitjadoun8596
      @pulkitjadoun8596 Рік тому

      @@Tadapatiatma ok bro thanks

  • @Roller_Roaster
    @Roller_Roaster Рік тому

    id mai 3 kyu show kr raha last mai?

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

    Sir 3 br try Kara laekin failed to add missing constraints error araha hai

    • @Tadapatiatma
      @Tadapatiatma Рік тому

      Mila answer nhi mila to main bata sakta hun

    • @gopalbarnwal7459
      @gopalbarnwal7459 Рік тому

      @@Tadapatiatma bolo

    • @rahuldatta1382
      @rahuldatta1382 Рік тому +1

      @@gopalbarnwal7459 in the settings of cities, you have to select cid as a primary key

    • @pulkitjadoun8596
      @pulkitjadoun8596 Рік тому

      @@rahuldatta1382 kar liys fir bhi nahi ho raha

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

    important

  • @_.innovative_pixel
    @_.innovative_pixel 5 місяців тому

    8:00

  • @harshadaborade5712
    @harshadaborade5712 4 місяці тому +2

    Worst explanation

  • @shubhamnimbalkar8659
    @shubhamnimbalkar8659 Рік тому +1

    yedee chale mat kar aaise .....important portion tu bad mai sikha raha hai student ko ...primary key foreign key pahile sikhana tha....time wast

  • @CodingMan-f1v
    @CodingMan-f1v 2 роки тому +1

    Good explanation