{"id":593,"date":"2019-06-04T17:57:26","date_gmt":"2019-06-05T01:57:26","guid":{"rendered":"https:\/\/db2tutorial.com\/?page_id=593"},"modified":"2020-04-11T06:58:52","modified_gmt":"2020-04-11T14:58:52","slug":"db2-foreign-key","status":"publish","type":"page","link":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/","title":{"rendered":"Db2 Foreign Key"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the Db2 foreign key constraint to enforce the referential integrity between the data across tables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to the Db2 foreign key<\/h2>\n\n\n\n<p>Let&#8217;s take a look at the <code>contacts<\/code> and <code>phones<\/code> tables:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> contacts(\n\tcontact_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span> <span class=\"hljs-keyword\">GENERATED<\/span> <span class=\"hljs-keyword\">ALWAYS<\/span> <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span>,\n\tfirst_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tlast_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tPRIMARY <span class=\"hljs-keyword\">KEY<\/span>(contact_id)\n);\n\n<span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> phones(\n\tphone_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span> <span class=\"hljs-keyword\">GENERATED<\/span> <span class=\"hljs-keyword\">ALWAYS<\/span> <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span>,\n\tphone_no <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">20<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tphone_type <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">10<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tcontact_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tPRIMARY <span class=\"hljs-keyword\">KEY<\/span>(phone_id)\n);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this diagram, each contact may have zero or many <code>phones<\/code> such as home phone, work phone, and emergency phone. However, each phone must belong to one and only one contact. The relationship between the contacts and phones is one-to-many.<\/p>\n\n\n\n<p>For each row in the <code>phones<\/code> table, you can always find a corresponding row in the <code>contacts<\/code> table. But the current setup does not ensure this relationship. It means you can insert a new row into the <code>phones<\/code> table with the contact identification (<code>contact_id<\/code>) that does not exist in the <code>contacts<\/code> table.<\/p>\n\n\n\n<p>Furthermore, if you delete a contact, all the <code>phones<\/code> of the deleted contact will remain in the <code>phones<\/code> table. The rows in the <code>phones<\/code> table that does not have corresponding rows in the <code>contacts<\/code> table are called orphaned rows.<\/p>\n\n\n\n<p>In order to enforce the relationship between <code>contacts<\/code> and <code>phones<\/code> tables, you need to use a foreign key constraint.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is a foreign key?<\/h3>\n\n\n\n<p>A foreign key is a column or group of columns in a table that uniquely identifies a row in another table. The foreign key constraints define foreign keys.<\/p>\n\n\n\n<p>Back to our example, the <code>contact_id<\/code> in the <code>phones<\/code> table should be the foreign key of the <code>phones<\/code> table. Because for each phone in the <code>phones<\/code> table, you can find a corresponding contact in the <code>contacts<\/code> table.<\/p>\n\n\n\n<p>To add a foreign key constraint to the <code>phones<\/code> table, you use the following <code>ALTER TABLE<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> phones\n<span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (contact_id)\n\t<span class=\"hljs-keyword\">REFERENCES<\/span> contacts(contact_id)\n\t\t<span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">NO<\/span> <span class=\"hljs-keyword\">ACTION<\/span>\n\t\t<span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>contacts<\/code> table is called the parent table to which the foreign key references. The <code>phones<\/code> table is called the child table (or dependent table) to which the foreign key constraint is applied.<\/p>\n\n\n\n<p>The <code>contact_id<\/code> column in the <code>contacts<\/code> table is called the parent key and the <code>contact_id<\/code> column in the <code>phones<\/code> table is called the foreign key or foreign key column.<\/p>\n\n\n\n<p>In the database world, referential integrity is a mechanism to ensure that the relationship of data between tables remains consistent. And to enforce the referential integrity, you use foreign key constraints. Therefore, foreign key constraints are also known as referential integrity constraints or referential constraints.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Db2 FOREIGN KEY constraint syntax<\/h2>\n\n\n\n<p>The following illustrates the syntax of defining a foreign key constraint:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">&#91;CONSTRAINT constraint_name]\nFOREIGN KEY (fk1, fk2,...)\nREFERENCES parent_table(c1,2,..) \n\tON <span class=\"hljs-keyword\">UPDATE<\/span> &#91; <span class=\"hljs-keyword\">NO<\/span> <span class=\"hljs-keyword\">ACTION<\/span> | RESTRICT]\n\t<span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> &#91; <span class=\"hljs-keyword\">NO<\/span> <span class=\"hljs-keyword\">ACTION<\/span> | RESTRICT | <span class=\"hljs-keyword\">CASCADE<\/span> | <span class=\"hljs-keyword\">SET<\/span> <span class=\"hljs-literal\">NULL<\/span>];\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax:<\/p>\n\n\n\n<p>First, specify a constraint name in the <code>CONSTRAINT<\/code> clause. The <code>CONSTRAINT<\/code> clause is optional. If you omit it, Db2 will generate a name for the foreign key constraint.<\/p>\n\n\n\n<p>Second, specify a list of comma-separated foreign key columns enclosed by parentheses in the <code>FOREIGN KEY<\/code> clause.<\/p>\n\n\n\n<p>Third, specify the name of the parent table and a list of comma-separated columns to which the foreign key columns reference.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&nbsp;ON UPDATE rules<\/h3>\n\n\n\n<p>Db2 triggers the <code>ON UPDATE<\/code> rule when you update a row in either parent or child table. The update rule has two options <code>NO ACTION<\/code> and <code>RESTRICT<\/code>.<\/p>\n\n\n\n<p>When you update the row in the parent key column of the parent table, Db2 rejects the update if there is the corresponding row exists in the child table for both <code>RESTRICT<\/code> and <code>NO ACTION<\/code> option.<\/p>\n\n\n\n<p>When you update the row in the foreign key column of the child table, Db2 rejects the update for <code>RESTRICT<\/code> option and allows the update for the <code>NO ACTION<\/code>, with the condition that the new value of the foreign key column exists in the parent table.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&nbsp;ON DELETE rules<\/h3>\n\n\n\n<p>Db2 triggers the <code>ON DELETE<\/code> rule when you delete a row in the parent table. Db2 determines whether or not to delete the rows in the child table based on the following options:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>NO ACTION<\/code> or <code>RESTRICT<\/code> does not delete any row in both tables and issues an error.<\/li><li><code>CASCADE<\/code> deletes the row in the parent table and all related rows in the child table.<\/li><li><code>SET NULL<\/code> deletes the row in the parent table and updates values in the foreign key columns in the child table to NULL only if these columns are not nullable columns.<\/li><\/ul>\n\n\n\n<p>You can use the foreign key constraint to define foreign keys in the <code>CREATE TABLE<\/code> or <code>ALTER TABLE<\/code> statement.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Db2 FOREIGN KEY constraint examples<\/h2>\n\n\n\n<p>Let&#8217;s take some example of using the foreign key constraint to understand it better.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1) Creating a table which has a single foreign key example<\/h3>\n\n\n\n<p>First, <a href=\"https:\/\/db2tutorial.com\/db2-basics\/db2-insert\/\">insert<\/a> a new contact into the <code>contacts<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> contacts(first_name, last_name) \n<span class=\"hljs-keyword\">VALUES<\/span>(<span class=\"hljs-string\">'John'<\/span>,<span class=\"hljs-string\">'Doe'<\/span>);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The contact <code>John Doe<\/code> has the contact id 1:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> * <span class=\"hljs-keyword\">FROM<\/span> contacts;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Next, add two <code>phones<\/code> for the contact <code>John Doe<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> \n\tphones(phone_no, phone_type, contact_id)\n<span class=\"hljs-keyword\">VALUES<\/span>\n\t(<span class=\"hljs-string\">'(408)-987-1234'<\/span>,<span class=\"hljs-string\">'HOME'<\/span>,<span class=\"hljs-number\">1<\/span>),\n\t(<span class=\"hljs-string\">'(408)-672-3424'<\/span>,<span class=\"hljs-string\">'WORK'<\/span>,<span class=\"hljs-number\">1<\/span>);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Then, <a href=\"https:\/\/db2tutorial.com\/db2-basics\/db2-delete\/\">delete<\/a> the contact id 1 from the <code>contacts<\/code> table. Because we declare the <code>ON DELETE<\/code> rule with the <code>CASCADE<\/code> action, Db2 will delete all phones of <code>John Doe<\/code> from the <code>phones<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">FROM<\/span> contacts\n<span class=\"hljs-keyword\">WHERE<\/span> contact_id = <span class=\"hljs-number\">1<\/span>;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>After, verify the deletion by querying data from the <code>contacts<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> * <span class=\"hljs-keyword\">FROM<\/span> contacts;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>It returned no row.<\/p>\n\n\n\n<p>Finally, view data in the <code>contacts<\/code> table by using the following <code><a href=\"https:\/\/db2tutorial.com\/db2-basics\/db2-select\/\">SELECT<\/a><\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> * <span class=\"hljs-keyword\">FROM<\/span> phones;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>It also returns an empty set.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2) Creating a table with multiple foreign keys example<\/h3>\n\n\n\n<p>The following statement <a href=\"https:\/\/db2tutorial.com\/db2-basics\/db2-create-table\/\">creates a new table<\/a> called <code>members<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> members (\n\tmember_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span> <span class=\"hljs-keyword\">GENERATED<\/span> <span class=\"hljs-keyword\">ALWAYS<\/span> <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span>,\n\tfirst_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tlast_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tjoined_date <span class=\"hljs-built_in\">DATE<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tPRIMARY <span class=\"hljs-keyword\">KEY<\/span>(member_id)\n);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Suppose each member can have one or many favorite books and each book may belong to favorite lists of many users. The relationship between members and books are many-to-many.<\/p>\n\n\n\n<p>The following <code>favorite_books<\/code> table stores the favorite books of members:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> favorite_books(\n\tmember_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tbook_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\t<span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (book_id)\n\t\t<span class=\"hljs-keyword\">REFERENCES<\/span> books(book_id) \n\t\t<span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> RESTRICT \n\t\t<span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>,\n\t<span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (member_id)\n\t\t<span class=\"hljs-keyword\">REFERENCES<\/span> members(member_id) \n\t\t<span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> RESTRICT \n\t\t<span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>\n);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>favorite_books<\/code> table has two foreign keys. The first one refers to the <code>book_id<\/code> column of the <code>books<\/code> table and the second one references to the <code>member_id<\/code> of the <code>members<\/code> table.<\/p>\n\n\n\n<p>The <code>favorite_books<\/code> table is known as an associative table, pivot table, or mapping table. We often use these kinds of tables to manage the many-to-many relationship.<\/p>\n\n\n\n<p>In this tutorial, you have learned about Db2 foreign key and how to use the foreign key constraint to enforce referential integrity.<\/p>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"593\"\n\t\t\t\tdata-post-url=\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/\"\n\t\t\t\tdata-post-title=\"Db2 Foreign Key\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"593\"\n\t\t\t\tdata-post-url=\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/\"\n\t\t\t\tdata-post-title=\"Db2 Foreign Key\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to use the Db2 foreign key constraint to enforce the referential integrity between the data across tables.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":141,"menu_order":47,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-593","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The Ultimate Guide to Db2 Foreign Key By Practical Examples<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn how to use the Db2 foreign key constraint to enforce the referential integrity between the data across tables.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Ultimate Guide to Db2 Foreign Key By Practical Examples\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn how to use the Db2 foreign key constraint to enforce the referential integrity between the data across tables.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/\" \/>\n<meta property=\"og:site_name\" content=\"DB2 Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-11T14:58:52+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/\",\"url\":\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/\",\"name\":\"The Ultimate Guide to Db2 Foreign Key By Practical Examples\",\"isPartOf\":{\"@id\":\"https:\/\/www.db2tutorial.com\/#website\"},\"datePublished\":\"2019-06-05T01:57:26+00:00\",\"dateModified\":\"2020-04-11T14:58:52+00:00\",\"description\":\"In this tutorial, you will learn how to use the Db2 foreign key constraint to enforce the referential integrity between the data across tables.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.db2tutorial.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Db2 Basics\",\"item\":\"https:\/\/www.db2tutorial.com\/db2-basics\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Db2 Foreign Key\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.db2tutorial.com\/#website\",\"url\":\"https:\/\/www.db2tutorial.com\/\",\"name\":\"DB2 Tutorial\",\"description\":\"A Comprehensive DB2 Tutorial\",\"publisher\":{\"@id\":\"https:\/\/www.db2tutorial.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.db2tutorial.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.db2tutorial.com\/#organization\",\"name\":\"Db2 Tutorial\",\"url\":\"https:\/\/www.db2tutorial.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.db2tutorial.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/03\/favicon.png\",\"contentUrl\":\"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/03\/favicon.png\",\"width\":500,\"height\":500,\"caption\":\"Db2 Tutorial\"},\"image\":{\"@id\":\"https:\/\/www.db2tutorial.com\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The Ultimate Guide to Db2 Foreign Key By Practical Examples","description":"In this tutorial, you will learn how to use the Db2 foreign key constraint to enforce the referential integrity between the data across tables.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/","og_locale":"en_US","og_type":"article","og_title":"The Ultimate Guide to Db2 Foreign Key By Practical Examples","og_description":"In this tutorial, you will learn how to use the Db2 foreign key constraint to enforce the referential integrity between the data across tables.","og_url":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/","og_site_name":"DB2 Tutorial","article_modified_time":"2020-04-11T14:58:52+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/","url":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/","name":"The Ultimate Guide to Db2 Foreign Key By Practical Examples","isPartOf":{"@id":"https:\/\/www.db2tutorial.com\/#website"},"datePublished":"2019-06-05T01:57:26+00:00","dateModified":"2020-04-11T14:58:52+00:00","description":"In this tutorial, you will learn how to use the Db2 foreign key constraint to enforce the referential integrity between the data across tables.","breadcrumb":{"@id":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.db2tutorial.com\/db2-basics\/db2-foreign-key\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.db2tutorial.com\/"},{"@type":"ListItem","position":2,"name":"Db2 Basics","item":"https:\/\/www.db2tutorial.com\/db2-basics\/"},{"@type":"ListItem","position":3,"name":"Db2 Foreign Key"}]},{"@type":"WebSite","@id":"https:\/\/www.db2tutorial.com\/#website","url":"https:\/\/www.db2tutorial.com\/","name":"DB2 Tutorial","description":"A Comprehensive DB2 Tutorial","publisher":{"@id":"https:\/\/www.db2tutorial.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.db2tutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.db2tutorial.com\/#organization","name":"Db2 Tutorial","url":"https:\/\/www.db2tutorial.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.db2tutorial.com\/#\/schema\/logo\/image\/","url":"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/03\/favicon.png","contentUrl":"https:\/\/db2tutorial.com\/wp-content\/uploads\/2019\/03\/favicon.png","width":500,"height":500,"caption":"Db2 Tutorial"},"image":{"@id":"https:\/\/www.db2tutorial.com\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/pages\/593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/comments?post=593"}],"version-history":[{"count":1,"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/pages\/593\/revisions"}],"predecessor-version":[{"id":1058,"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/pages\/593\/revisions\/1058"}],"up":[{"embeddable":true,"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/pages\/141"}],"wp:attachment":[{"href":"https:\/\/www.db2tutorial.com\/wp-json\/wp\/v2\/media?parent=593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}