{"id":2052,"date":"2021-07-30T18:57:46","date_gmt":"2021-07-30T13:27:46","guid":{"rendered":"https:\/\/selfimagination.in\/tips\/?p=2052"},"modified":"2021-10-21T22:30:35","modified_gmt":"2021-10-21T17:00:35","slug":"mysql-foreign-key-constraint","status":"publish","type":"post","link":"https:\/\/selfimagination.in\/tips\/mysql-foreign-key-constraint\/","title":{"rendered":"MySQL Foreign Key Constraint"},"content":{"rendered":"\n<p class=\"wp-block-zozuk-wphindi\"><strong>MySQL Foreign Key Constraint :<\/strong> \u091c\u092c \u092d\u0940 \u0939\u092e \u0915\u094b\u0908 \u092d\u0940 \u0926\u094b \u091f\u0947\u092c\u0932 \u0915\u094b Connect \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0926\u094b\u0928\u094b\u0902 \u091f\u0947\u092c\u0932 \u0915\u0947 \u090f\u0915 \u090f\u0915 Column \u0915\u0940 \u092c\u0947\u0938 \u092a\u0930 \u0909\u0928\u094d\u0939\u0947\u0902 Connect \u0915\u093f\u092f\u093e \u091c\u093e\u0924\u093e \u0939\u0948\u0902, \u091c\u093f\u0928 Columns \u0915\u0940 base \u092a\u0930 Connect \u0915\u093f\u092f\u093e \u091c\u093e\u0924\u093e \u0939\u0948\u0902 \u0935\u0939 Master table \u092e\u0947\u0902 Primary Key \u0915\u0939\u0932\u093e\u0924\u0947 \u0939\u0948\u0902 \u0914\u0930 Transaction \u091f\u0947\u092c\u0932 \u092e\u0947\u0902 Foreign Key \u0915\u0939\u0932\u093e\u0924\u0947 \u0939\u0948\u0902, \u0907\u0938 Article \u092e\u0947\u0902 \u0939\u092e \u0938\u092e\u091d\u0947\u0902\u0917\u0947 \u0915\u0940 \u092f\u0926\u093f \u0939\u092e Transaction \u092e\u0947\u0902 Entry \u0915\u0930\u0928\u0947 \u0915\u0947 \u092c\u093e\u0926 Master \u0938\u0947 \u0921\u093e\u091f\u093e Delete \u0928\u0939\u0940\u0902 \u0939\u094b\u0928\u0947 \u0926\u0947\u0928\u093e \u091a\u093e\u0939\u0924\u0947 \u0939\u0948\u0902 \u0924\u094b \u0939\u092e\u0947\u0902 Foreign Key Constraint \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0928\u093e \u0939\u094b\u0924\u093e \u0939\u0948\u0902 \u0964<\/p>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\"> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL Foreign Key Constraint Example Using SQL<\/h2>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\">\u0939\u092e\u093e\u0930\u0947 \u092a\u093e\u0938 Do Table \u0939\u0948\u0902 \u090f\u0915 Master \u0914\u0930 \u0926\u0942\u0938\u0930\u0940 Transaction , \u092f\u0939 \u0909\u0928\u0915\u0947 Structure \u0939\u0948\u0902 \u0964<\/p>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\"><a href=\"https:\/\/selfimagination.in\/tips\/update-stock-balance-using-trigger\/\">\u092f\u0926\u093f \u0906\u092a Table \u0914\u0930 Trigger \u092c\u0928\u093e\u0928\u093e \u091a\u093e\u0939\u0924\u0947 \u0939\u0948\u0902 \u0924\u094b \u0907\u0938 \u0932\u093f\u0902\u0915 \u092a\u0930 \u0915\u094d\u0932\u093f\u0915 \u0915\u0930\u0947 <\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">ALTER TABLE `trn_item` ADD  CONSTRAINT `trn_item_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `mst_item`(`item_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\">\u092f\u0926\u093f Transaction Table \u092e\u0947\u0902 \u092a\u0939\u0932\u0947 \u0938\u0947 \u0921\u093e\u091f\u093e \u0939\u094b \u0914\u0930 \u0909\u0938\u0947 \u0915\u094b\u0908 Data \u0907\u0938 Validation \u0915\u093e pass \u0928\u0939\u0940\u0902 \u0915\u0930\u0924\u093e \u0939\u094b\u0917\u093e \u0924\u094b \u092f\u0939 SQL Execute \u0928\u0939\u0940\u0902 \u0939\u094b\u0917\u0940 \u0964<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Foreign Key Constraint Steps<\/h2>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\"><strong>Set InnoDB : <\/strong>\u0938\u092c\u0938\u0947 \u092a\u0939\u0932\u0947 \u0939\u092e\u0947\u0902 \u091c\u093f\u0928 \u0926\u094b Table \u0915\u094b Connect \u0915\u0930\u0928\u093e \u0939\u0948\u0902 \u0909\u0928 Table \u092a\u0930 \u0915\u094d\u0932\u093f\u0915 \u0915\u0930 \u0939\u092e\u0947\u0902 Operation Menu \u092e\u0947\u0902 \u091c\u093e \u0915\u0930 Table Option \u092e\u0947\u0902 \u091c\u093e \u0915\u0930 Engine \u0915\u094b InnoDB \u0938\u0947\u091f \u0915\u0930\u0928\u093e \u0939\u094b\u0924\u093e \u0939\u0948\u0902 \u0964 \u0910\u0938\u093e \u0915\u0930\u0928\u093e \u0938\u0947 Table Structure \u0935\u093e\u0932\u0947 Tab Me Relative View \u0915\u093e Button \u0926\u093f\u0916\u093e\u0908 \u0926\u0947\u0928\u0947 \u0932\u0917\u0924\u093e \u0939\u0948\u0902 \u0964<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"282\" src=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/InnoDB.jpg?resize=640%2C282&#038;ssl=1\" alt=\"Foreign Key Constraint Setup\" class=\"wp-image-2068\" srcset=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/InnoDB.jpg?resize=1024%2C451&amp;ssl=1 1024w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/InnoDB.jpg?resize=300%2C132&amp;ssl=1 300w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/InnoDB.jpg?resize=768%2C339&amp;ssl=1 768w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/InnoDB.jpg?resize=465%2C205&amp;ssl=1 465w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/InnoDB.jpg?resize=695%2C306&amp;ssl=1 695w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/InnoDB.jpg?w=1116&amp;ssl=1 1116w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\"><strong>Relation View :<\/strong> \u091c\u094b Transaction \u091f\u0947\u092c\u0932 \u0939\u0948\u0902 \u0909\u0938 \u092a\u0930 Relative View Button \u092a\u0930 \u0915\u094d\u0932\u093f\u0915 \u0915\u0930 \u0939\u092e\u0947\u0902 Transaction Table \u0915\u0940 Key ( \u091c\u093f\u0938\u0947 \u0939\u092e Foreign Key) \u0915\u0939\u0924\u0947 \u0939\u0948\u0902 \u0909\u0938\u0947 \u0938\u0947\u0932\u0947\u0915\u094d\u091f \u0915\u0930\u0928\u093e \u0939\u094b\u0924\u0940 \u0939\u0948\u0902 , \u0909\u0938\u0915\u0947 \u092c\u093e\u0926 Database \u0914\u0930 \u0935\u0939 Master Table select \u0915\u0930\u0928\u093e \u0939\u094b\u0924\u0940 \u0939\u0948\u0902 \u0914\u0930 Master Table \u0915\u0940 Primary Key Select \u0915\u0930\u0928\u093e \u0939\u094b\u0924\u0940 \u0939\u0948\u0902 \u0909\u0938\u0947 \u092c\u093e\u0926 \u0939\u092e Save \u0915\u0930 \u0926\u0947\u0924\u0947 \u0939\u0948\u0902 \u0964<\/p>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\"><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"308\" src=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Relation-View.jpg?resize=640%2C308&#038;ssl=1\" alt=\"Relational View\" class=\"wp-image-2070\" srcset=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Relation-View.jpg?resize=1024%2C493&amp;ssl=1 1024w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Relation-View.jpg?resize=300%2C145&amp;ssl=1 300w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Relation-View.jpg?resize=768%2C370&amp;ssl=1 768w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Relation-View.jpg?resize=465%2C224&amp;ssl=1 465w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Relation-View.jpg?resize=695%2C335&amp;ssl=1 695w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Relation-View.jpg?w=1366&amp;ssl=1 1366w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Relation-View.jpg?w=1280&amp;ssl=1 1280w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\"><strong>Transaction Table : <\/strong>\u0905\u092c \u091c\u092c \u092d\u0940 \u0906\u092a Transaction Table \u092e\u0947\u0902 Record Insert \u0915\u0930\u0947\u0902\u0917\u0947 \u0924\u094b \u0909\u0938\u092e\u0947 Foreign Key \u092a\u0930 Lookup \u0906\u0928\u0947 \u0932\u0917\u0947\u0917\u0940\u0964 \u0924\u093e\u0915\u093f \u0906\u092a \u0909\u0938\u0915\u0947 Record \u0915\u0947 \u0905\u0932\u093e\u0935\u093e \u0915\u094b\u0908 \u0914\u0930 Record Select \u0928 \u0915\u0930 \u092a\u093e\u090f, \u0914\u0930 \u092f\u0926\u093f \u0906\u092a\u0928\u0947 Insert SQL \u0932\u093f\u0916 \u0915\u0930 \u092d\u0940 \u0915\u094b\u0908 \u0905\u0928\u094d\u092f Code Enter \u0915\u0930\u0928\u093e \u091a\u093e\u0939\u0947\u0902\u0917\u0947 \u0924\u094b \u092d\u0940 Data Insert \u0928\u0939\u0940\u0902 \u0939\u094b\u0917\u093e \u0964<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"252\" src=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Show-Lookup.jpg?resize=640%2C252&#038;ssl=1\" alt=\"Foreign key Link\" class=\"wp-image-2075\" srcset=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Show-Lookup.jpg?w=864&amp;ssl=1 864w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Show-Lookup.jpg?resize=300%2C118&amp;ssl=1 300w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Show-Lookup.jpg?resize=768%2C302&amp;ssl=1 768w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Show-Lookup.jpg?resize=465%2C183&amp;ssl=1 465w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Show-Lookup.jpg?resize=695%2C273&amp;ssl=1 695w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\"><strong>Master Table : <\/strong>\u092f\u0926\u093f \u0907\u0938 \u091f\u0947\u092c\u0932 \u0938\u0947 \u0906\u092a \u0915\u094b\u0908 \u092d\u0940 \u0910\u0938\u093e Record Delete \u0915\u0930\u0928\u093e \u091a\u093e\u0939\u0947\u0902\u0917\u0947 \u091c\u093f\u0938\u0915\u093e Reference \u0906\u092a\u0928\u0947 Transaction \u092e\u0947\u0902 select \u0915\u093f\u092f\u093e \u0939\u0941\u0906 \u0939\u0948\u0902 \u0924\u094b \u0935\u0939 Delete \u0928\u0939\u0940\u0902 \u0939\u094b\u0928\u0947 \u0926\u0947\u0917\u093e, \u092f\u0926\u093f \u0906\u092a\u0928\u0947 Transaction \u0938\u0947 Data Delete \u0915\u0930 \u0926\u093f\u092f\u093e \u0909\u0938\u0915\u0947 \u092c\u093e\u0926 Master \u0938\u0947 delete \u0915\u0930\u0947\u0902\u0917\u0947 \u0924\u094b \u092b\u093f\u0930 \u092f\u0939 Data \u0915\u094b Delete \u0915\u0930\u0928\u0947 \u0926\u0947\u0917\u093e \u0964<\/p>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\">  <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"250\" src=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Delete-Constraint.jpg?resize=640%2C250&#038;ssl=1\" alt=\"Foreign Key Constraint Error\" class=\"wp-image-2077\" srcset=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Delete-Constraint.jpg?resize=1024%2C400&amp;ssl=1 1024w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Delete-Constraint.jpg?resize=300%2C117&amp;ssl=1 300w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Delete-Constraint.jpg?resize=768%2C300&amp;ssl=1 768w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Delete-Constraint.jpg?resize=465%2C182&amp;ssl=1 465w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Delete-Constraint.jpg?resize=695%2C271&amp;ssl=1 695w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/Delete-Constraint.jpg?w=1175&amp;ssl=1 1175w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\"><a href=\"https:\/\/youtu.be\/Ob3WJnvfPx4\" target=\"_blank\" rel=\"noopener\">\u092f\u0926\u093f \u0906\u092a \u0935\u0940\u0921\u093f\u092f\u094b \u0915\u0947 \u092e\u093e\u0927\u094d\u092f\u092e \u0938\u0947 \u0938\u092e\u091d\u0928\u093e \u091a\u093e\u0939\u0924\u0947 \u0939\u0948\u0902 \u0924\u094b \u092f\u0939 \u0935\u0940\u0921\u093f\u092f\u094b \u0926\u0947\u0916 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL Foreign Key Constraint Example Using SQL Foreign Key Constraint Steps<\/p>\n","protected":false},"author":1,"featured_media":2062,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-2052","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/07\/MySQL-Foreign-Key-Constraint.jpg?fit=1200%2C628&ssl=1","_links":{"self":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/2052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/comments?post=2052"}],"version-history":[{"count":17,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/2052\/revisions"}],"predecessor-version":[{"id":4527,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/2052\/revisions\/4527"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/media\/2062"}],"wp:attachment":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/media?parent=2052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/categories?post=2052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/tags?post=2052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}