{"id":538,"date":"2024-12-27T12:01:39","date_gmt":"2024-12-27T12:01:39","guid":{"rendered":"https:\/\/datadandies.nl\/?p=538"},"modified":"2025-01-11T06:53:46","modified_gmt":"2025-01-11T06:53:46","slug":"why-many-to-many-relationships-are-evil","status":"publish","type":"post","link":"https:\/\/datadandies.nl\/index.php\/2024\/12\/27\/why-many-to-many-relationships-are-evil\/","title":{"rendered":"Why many-to-many relationships are evil &#8211; Junction tables \/ Bridge tables"},"content":{"rendered":"\n<p>Why does Power BI hate many-to-many relationships? <\/p>\n\n\n\n<p>Despite the title (that did its job in getting your attention) many-to-many relationships *-* are not necessarily evil. However, modeling your data in a manner that avoids many-to-many relationships helps in a lot of scenarios with data consistency, among other things.<\/p>\n\n\n\n<p>Let&#8217;s dive into this using the ancient author-book example. <\/p>\n\n\n\n<p>I have added the T-SQL scripts so you can follow along if you want. Strap on folks, it will be a long and a bumpy ride. <\/p>\n\n\n\n<p>Let&#8217;s start with creating a table for the authors, inserting two authors and check the table out. <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.3rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"--Data modeling example about handling many-to-many relationships with a junction table. \n--Creating table for authors of books.\nCREATE TABLE TEST.DataModeling.Authors \n\t(\n\t\tAuthorName VARCHAR(400) PRIMARY KEY,\n\t\tNationality VARCHAR(400)\n\t)\n\t\n\t--Inserting 2 authors into the Authors table.\nINSERT INTO TEST.DataModeling.Authors VALUES \n\t('David', 'NL'), ('Harry', 'EN')\n\t\n--Checking out the table.\nSELECT * FROM TEST.DataModeling.Authors\" style=\"color:#D4D4D4;display:none\" aria-label=\"Kopieer\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">--Data modeling example about handling many-to-many relationships with a junction table. <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Creating table for authors of books.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">CREATE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">TABLE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">TEST<\/span><span style=\"color: #D4D4D4\">.DataModeling.Authors <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tAuthorName <\/span><span style=\"color: #569CD6\">VARCHAR<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">400<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #569CD6\">PRIMARY KEY<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tNationality <\/span><span style=\"color: #569CD6\">VARCHAR<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">400<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">--Inserting 2 authors into the Authors table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">INSERT INTO<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Authors <\/span><span style=\"color: #569CD6\">VALUES<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;NL&#39;<\/span><span style=\"color: #D4D4D4\">), (<\/span><span style=\"color: #CE9178\">&#39;Harry&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;EN&#39;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Checking out the table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> * <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Authors<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"265\" height=\"88\" src=\"https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-2.png\" alt=\"\" class=\"wp-image-541\"\/><\/figure>\n\n\n\n<p> Now let&#8217;s create the table for books, insert three books and check the table out. <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.3rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"--Creating table for books.\nCREATE TABLE TEST.DataModeling.Books \n\t(\n\t\tBookTitle VARCHAR(400) PRIMARY KEY,\t\n\t\tPages INT,\n\t\tAuthorName VARCHAR(400)\n\t)\n\t\n\t--Inserting 3 books into the Books table.\nINSERT INTO TEST.DataModeling.Books VALUES \n\t('David book 1', 10, 'David'), ('David book 2', 20, 'David'), ('Harry book', 30, 'Harry')\n\n--Checking out the table.\nSELECT * FROM TEST.DataModeling.Books\" style=\"color:#D4D4D4;display:none\" aria-label=\"Kopieer\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">--Creating table for books.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">CREATE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">TABLE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">TEST<\/span><span style=\"color: #D4D4D4\">.DataModeling.Books <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tBookTitle <\/span><span style=\"color: #569CD6\">VARCHAR<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">400<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #569CD6\">PRIMARY KEY<\/span><span style=\"color: #D4D4D4\">,\t<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tPages <\/span><span style=\"color: #569CD6\">INT<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tAuthorName <\/span><span style=\"color: #569CD6\">VARCHAR<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">400<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><span style=\"color: #6A9955\">--Inserting 3 books into the Books table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">INSERT INTO<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books <\/span><span style=\"color: #569CD6\">VALUES<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David book 1&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">10<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;David&#39;<\/span><span style=\"color: #D4D4D4\">), (<\/span><span style=\"color: #CE9178\">&#39;David book 2&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">20<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;David&#39;<\/span><span style=\"color: #D4D4D4\">), (<\/span><span style=\"color: #CE9178\">&#39;Harry book&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">30<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;Harry&#39;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Checking out the table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> * <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"346\" height=\"109\" src=\"https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-3.png\" alt=\"\" class=\"wp-image-542\" srcset=\"https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-3.png 346w, https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-3-300x95.png 300w\" sizes=\"auto, (max-width: 346px) 100vw, 346px\" \/><\/figure>\n\n\n\n<p>Looking good so far. However, what if we have a book with two authors? <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.3rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"--So far so good. However, what if authors David and Harry are BOTH author of a book? Now things will get tricky.\nINSERT INTO TEST.DataModeling.Books VALUES \n\t('David &amp; Harry book', 40, 'David &amp; Harry')\n\t\n--Checking out the table: we have a problem. Value &quot;David &amp; Harry&quot; in column &quot;AuthorName&quot; from table &quot;Books&quot; does not exist in table &quot;Authors&quot;.\n--Inserting value &quot;David &amp; Harry&quot; in table &quot;Authors&quot; would introduce a host of problems: do we add extra columns for Nationality since David and Harry have different nationalities? Not really a scalable solution.\n--Now imagine you have a third book that is written by good ol' Harry and a new author. Do we add two rows in the &quot;Authors&quot; table? One for the new author and one for the combination of Harry and the new author?\n--How do we use these tables to answer questions from the business like: how many authors are there? A simple COUNT(*) of the &quot;Authors&quot; table returns wrong results. \n--COUNT(DISTINCT AuthorName) returns wrong results as well! Also queries to identify the contribution of individual authors become complex without manual parsing. \nSELECT * FROM TEST.DataModeling.Books\" style=\"color:#D4D4D4;display:none\" aria-label=\"Kopieer\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">--So far so good. However, what if authors David and Harry are BOTH author of a book? Now things will get tricky.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">INSERT INTO<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books <\/span><span style=\"color: #569CD6\">VALUES<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David &amp; Harry book&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">40<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;David &amp; Harry&#39;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Checking out the table: we have a problem. Value &quot;David &amp; Harry&quot; in column &quot;AuthorName&quot; from table &quot;Books&quot; does not exist in table &quot;Authors&quot;.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Inserting value &quot;David &amp; Harry&quot; in table &quot;Authors&quot; would introduce a host of problems: do we add extra columns for Nationality since David and Harry have different nationalities? Not really a scalable solution.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Now imagine you have a third book that is written by good ol&#39; Harry and a new author. Do we add two rows in the &quot;Authors&quot; table? One for the new author and one for the combination of Harry and the new author?<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--How do we use these tables to answer questions from the business like: how many authors are there? A simple COUNT(*) of the &quot;Authors&quot; table returns wrong results. <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--COUNT(DISTINCT AuthorName) returns wrong results as well! Also queries to identify the contribution of individual authors become complex without manual parsing. <\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> * <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"389\" height=\"143\" src=\"https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-4.png\" alt=\"\" class=\"wp-image-543\" srcset=\"https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-4.png 389w, https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-4-300x110.png 300w\" sizes=\"auto, (max-width: 389px) 100vw, 389px\" \/><\/figure>\n\n\n\n<p>As described in the comments in the block of code above, we have a problem. Things got a whole lot more complicated. We can however solve this and create a more flexible data model by creating a junction table (also called a bridge table). In this case, a junction table is a combination of all existing combinations between books and authors. Let&#8217;s try and make this happen. <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.3rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"--Starting with a clean slate, let's empty the &quot;Books&quot; table. \nTRUNCATE TABLE TEST.DataModeling.Books\n\n--The next step is to remove the &quot;AuthorName&quot; column from the &quot;Books&quot; table. We now have an empty &quot;Books&quot; table with only the columns &quot;BookTitle&quot; and &quot;Pages&quot;.\nALTER TABLE TEST.DataModeling.Books DROP COLUMN AuthorName\n\n--Authors table remains the same.\n\n--Insert the existing books into the &quot;Books&quot; table.\nINSERT INTO TEST.DataModeling.Books (BookTitle, Pages) VALUES \n\t('David book 1', 10),\n\t('David book 2', 20),\n\t('Harry book', 30),\n\t('David &amp; Harry book', 40)\n\n--Checking out the new &quot;Books&quot; table.\nSELECT * FROM TEST.DataModeling.Books\" style=\"color:#D4D4D4;display:none\" aria-label=\"Kopieer\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">--Starting with a clean slate, let&#39;s empty the &quot;Books&quot; table. <\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">TRUNCATE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">TABLE<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--The next step is to remove the &quot;AuthorName&quot; column from the &quot;Books&quot; table. We now have an empty &quot;Books&quot; table with only the columns &quot;BookTitle&quot; and &quot;Pages&quot;.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">ALTER<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">TABLE<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books <\/span><span style=\"color: #569CD6\">DROP<\/span><span style=\"color: #D4D4D4\"> COLUMN AuthorName<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Authors table remains the same.<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Insert the existing books into the &quot;Books&quot; table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">INSERT INTO<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books (BookTitle, Pages) <\/span><span style=\"color: #569CD6\">VALUES<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David book 1&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">10<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David book 2&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">20<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;Harry book&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">30<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David &amp; Harry book&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">40<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Checking out the new &quot;Books&quot; table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> * <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"275\" height=\"140\" src=\"https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-5.png\" alt=\"\" class=\"wp-image-544\"\/><\/figure>\n\n\n\n<p>As you can see above, in order for us to be able to create a junction table, we first need to alter the &#8220;Books&#8221; table. We truncated the &#8220;Books&#8221; table and dropped the column &#8220;AuthorName&#8221;. Let&#8217;s also take a peek at what the unchanged &#8220;Authors&#8221; table looks like. <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.3rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"--Checking out the unchanged &quot;Authors&quot; table.\nSELECT * FROM TEST.DataModeling.Authors\" style=\"color:#D4D4D4;display:none\" aria-label=\"Kopieer\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">--Checking out the unchanged &quot;Authors&quot; table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> * <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Authors<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"259\" height=\"81\" src=\"https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-6.png\" alt=\"\" class=\"wp-image-545\"\/><\/figure>\n\n\n\n<p>Looking good. Next step is to create the junction table: the table where the existing combinations of books and authors will live.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.3rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"--Now let's create the junction table called &quot;BookAuthors&quot;.\nCREATE TABLE TEST.DataModeling.BookAuthors\n(\n    BookTitle VARCHAR(400),\n    AuthorName VARCHAR(400),\n    CONSTRAINT PK_BookAuthors PRIMARY KEY (BookTitle, AuthorName),\n    CONSTRAINT FK_BookAuthors_Books FOREIGN KEY (BookTitle) REFERENCES TEST.DataModeling.Books(BookTitle),\n    CONSTRAINT FK_BookAuthors_Authors FOREIGN KEY (AuthorName) REFERENCES TEST.DataModeling.Authors(AuthorName)\n)\n\n-- Insert the relationships between books and authors into the junction table.\nINSERT INTO TEST.DataModeling.BookAuthors (BookTitle, AuthorName) VALUES\n\t('David book 1', 'David'),\n\t('David book 2', 'David'),\n\t('Harry book', 'Harry'),\n\t('David &amp; Harry book', 'David'),\n\t('David &amp; Harry book', 'Harry')\n\n--Checking out the junction table &quot;BookAuthors.\nSELECT * FROM TEST.DataModeling.BookAuthors\" style=\"color:#D4D4D4;display:none\" aria-label=\"Kopieer\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">--Now let&#39;s create the junction table called &quot;BookAuthors&quot;.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">CREATE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">TABLE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">TEST<\/span><span style=\"color: #D4D4D4\">.DataModeling.BookAuthors<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    BookTitle <\/span><span style=\"color: #569CD6\">VARCHAR<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">400<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    AuthorName <\/span><span style=\"color: #569CD6\">VARCHAR<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">400<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">CONSTRAINT<\/span><span style=\"color: #D4D4D4\"> PK_BookAuthors <\/span><span style=\"color: #569CD6\">PRIMARY KEY<\/span><span style=\"color: #D4D4D4\"> (BookTitle, AuthorName),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">CONSTRAINT<\/span><span style=\"color: #D4D4D4\"> FK_BookAuthors_Books <\/span><span style=\"color: #569CD6\">FOREIGN KEY<\/span><span style=\"color: #D4D4D4\"> (BookTitle) <\/span><span style=\"color: #569CD6\">REFERENCES<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books(BookTitle),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">CONSTRAINT<\/span><span style=\"color: #D4D4D4\"> FK_BookAuthors_Authors <\/span><span style=\"color: #569CD6\">FOREIGN KEY<\/span><span style=\"color: #D4D4D4\"> (AuthorName) <\/span><span style=\"color: #569CD6\">REFERENCES<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Authors(AuthorName)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">-- Insert the relationships between books and authors into the junction table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">INSERT INTO<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.BookAuthors (BookTitle, AuthorName) <\/span><span style=\"color: #569CD6\">VALUES<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David book 1&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;David&#39;<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David book 2&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;David&#39;<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;Harry book&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;Harry&#39;<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David &amp; Harry book&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;David&#39;<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David &amp; Harry book&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;Harry&#39;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Checking out the junction table &quot;BookAuthors.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> * <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.BookAuthors<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"310\" height=\"151\" src=\"https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-7.png\" alt=\"\" class=\"wp-image-546\" srcset=\"https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-7.png 310w, https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-7-300x146.png 300w\" sizes=\"auto, (max-width: 310px) 100vw, 310px\" \/><\/figure>\n\n\n\n<p>That is more like it. Now most questions from the business can be answered in an easy manner. For example, would you like to know how many authors there are? <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.3rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"--How many authors are there? A simple COUNT(*) will answer this question.\nSELECT COUNT(*) AS COUNT_AUTHORS FROM TEST.DataModeling.Authors\" style=\"color:#D4D4D4;display:none\" aria-label=\"Kopieer\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">--How many authors are there? A simple COUNT(*) will answer this question.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">COUNT<\/span><span style=\"color: #D4D4D4\">(*) <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> COUNT_AUTHORS <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Authors<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"216\" height=\"53\" src=\"https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-8.png\" alt=\"\" class=\"wp-image-547\"\/><\/figure>\n\n\n\n<p>What about how many books there are?<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.3rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"--How many books are there? A simple COUNT(*) will answer this question.\nSELECT COUNT(*) AS COUNT_BOOKS FROM TEST.DataModeling.Books\" style=\"color:#D4D4D4;display:none\" aria-label=\"Kopieer\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">--How many books are there? A simple COUNT(*) will answer this question.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">COUNT<\/span><span style=\"color: #D4D4D4\">(*) <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> COUNT_BOOKS <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"199\" height=\"53\" src=\"https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-9.png\" alt=\"\" class=\"wp-image-548\"\/><\/figure>\n\n\n\n<p>Let&#8217;s see how many books were written bij author David. <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.3rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"--Show me all books by a certain author.\nSELECT \n\tBookAuthors.AuthorName, \n\tBooks.BookTitle \nFROM TEST.DataModeling.BookAuthors\nJOIN TEST.DataModeling.Books ON BookAuthors.BookTitle = Books.BookTitle\nWHERE BookAuthors.AuthorName = 'David'\" style=\"color:#D4D4D4;display:none\" aria-label=\"Kopieer\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">--Show me all books by a certain author.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tBookAuthors.AuthorName, <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tBooks.BookTitle <\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.BookAuthors<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">JOIN<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books <\/span><span style=\"color: #569CD6\">ON<\/span><span style=\"color: #D4D4D4\"> BookAuthors.BookTitle = Books.BookTitle<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">WHERE<\/span><span style=\"color: #D4D4D4\"> BookAuthors.AuthorName = <\/span><span style=\"color: #CE9178\">&#39;David&#39;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"102\" src=\"https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-10.png\" alt=\"\" class=\"wp-image-549\" srcset=\"https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-10.png 320w, https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-10-300x96.png 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/figure>\n\n\n\n<p>Let&#8217;s turn it around! Which author(s) wrote the book &#8220;David &amp; Harry book&#8221;?<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.3rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"--Show me all authors that have written a certain book.\nSELECT \n\tAuthors.AuthorName, \n\tAuthors.Nationality\nFROM TEST.DataModeling.Authors\nJOIN TEST.DataModeling.BookAuthors ON Authors.AuthorName = BookAuthors.AuthorName\nWHERE BookAuthors.BookTitle = 'David &amp; Harry book'\" style=\"color:#D4D4D4;display:none\" aria-label=\"Kopieer\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">--Show me all authors that have written a certain book.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tAuthors.AuthorName, <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tAuthors.Nationality<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Authors<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">JOIN<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.BookAuthors <\/span><span style=\"color: #569CD6\">ON<\/span><span style=\"color: #D4D4D4\"> Authors.AuthorName = BookAuthors.AuthorName<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">WHERE<\/span><span style=\"color: #D4D4D4\"> BookAuthors.BookTitle = <\/span><span style=\"color: #CE9178\">&#39;David &amp; Harry book&#39;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"251\" height=\"90\" src=\"https:\/\/datadandies.nl\/wp-content\/uploads\/2024\/12\/image-11.png\" alt=\"\" class=\"wp-image-550\"\/><\/figure>\n\n\n\n<p>Pretty nifty, indeed!<\/p>\n\n\n\n<p>For your convenience, I have gathered all the T-SQL statements from above into a single script which can be found below. <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.3rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"--Data modeling example about handling many-to-many relationships with a junction table. \n\n--Drop junction table in order to be able to create the &quot;Authors&quot; and &quot;Books&quot; tables anew (avoiding the error: &quot;cannot drop table because it is references by a FOREIGN KEY constraint&quot;)\nDROP TABLE IF EXISTS TEST.DataModeling.BookAuthors\n\n--Creating table for authors of books.\nDROP TABLE TEST.DataModeling.Authors \n\nCREATE TABLE TEST.DataModeling.Authors \n\t(\n\t\tAuthorName VARCHAR(400) PRIMARY KEY,\n\t\tNationality VARCHAR(400)\n\t)\n\n--Inserting 2 authors into the Authors table.\nINSERT INTO TEST.DataModeling.Authors VALUES \n\t('David', 'NL'), ('Harry', 'EN')\n\n--Checking out the table.\nSELECT * FROM TEST.DataModeling.Authors\n\n--Creating table for books.\nDROP TABLE TEST.DataModeling.Books \n\nCREATE TABLE TEST.DataModeling.Books \n\t(\n\t\tBookTitle VARCHAR(400) PRIMARY KEY,\t\n\t\tPages INT,\n\t\tAuthorName VARCHAR(400)\n\t)\n\n--Inserting 3 books into the Books table.\nINSERT INTO TEST.DataModeling.Books VALUES \n\t('David book 1', 10, 'David'), ('David book 2', 20, 'David'), ('Harry book', 30, 'Harry')\n\n--Checking out the table.\nSELECT * FROM TEST.DataModeling.Books\n\n--So far so good. However, what if authors David and Harry are BOTH author of a book? Now things will get tricky.\nINSERT INTO TEST.DataModeling.Books VALUES \n\t('David &amp; Harry book', 40, 'David &amp; Harry')\n\n--Checking out the table: we have a problem. Value &quot;David &amp; Harry&quot; in column &quot;AuthorName&quot; from table &quot;Books&quot; does not exist in table &quot;Authors&quot;.\n--Inserting value &quot;David &amp; Harry&quot; in table &quot;Authors&quot; would introduce a host of problems: do we add extra columns for Nationality since David and Harry have different nationalities? Not really a scalable solution.\n--Now imagine you have a third book that is written by good ol' Harry and a new author. Do we add two rows in the &quot;Authors&quot; table? One for the new author and one for the combination of Harry and the new author?\n--How do we use these tables to answer questions from the business like: how many authors are there? A simple COUNT(*) of the &quot;Authors&quot; table returns wrong results. \n--COUNT(DISTINCT AuthorName) returns wrong results as well! Also queries to identify the contribution of individual authors become complex without manual parsing. \nSELECT * FROM TEST.DataModeling.Books\n\n--An elegant way of solving this, is by creating a junction table.\n\n--Starting with a clean slate, let's empty the &quot;Books&quot; table. \nTRUNCATE TABLE TEST.DataModeling.Books\n\n--The next step is to remove the &quot;AuthorName&quot; column from the &quot;Books&quot; table. We now have an empty &quot;Books&quot; table with only the columns &quot;BookTitle&quot; and &quot;Pages&quot;.\nALTER TABLE TEST.DataModeling.Books DROP COLUMN AuthorName\n\n--Authors table remains the same.\n\n--Insert the existing books into the &quot;Books&quot; table.\nINSERT INTO TEST.DataModeling.Books (BookTitle, Pages) VALUES \n\t('David book 1', 10),\n\t('David book 2', 20),\n\t('Harry book', 30),\n\t('David &amp; Harry book', 40)\n\n--Checking out the new &quot;Books&quot; table.\nSELECT * FROM TEST.DataModeling.Books\n\n--Checking out the unchanged &quot;Authors&quot; table.\nSELECT * FROM TEST.DataModeling.Authors\n\n--Now let's create the junction table called &quot;BookAuthors&quot;.\nCREATE TABLE TEST.DataModeling.BookAuthors\n(\n    BookTitle VARCHAR(400),\n    AuthorName VARCHAR(400),\n    CONSTRAINT PK_BookAuthors PRIMARY KEY (BookTitle, AuthorName),\n    CONSTRAINT FK_BookAuthors_Books FOREIGN KEY (BookTitle) REFERENCES TEST.DataModeling.Books(BookTitle),\n    CONSTRAINT FK_BookAuthors_Authors FOREIGN KEY (AuthorName) REFERENCES TEST.DataModeling.Authors(AuthorName)\n)\n\n-- Insert the relationships between books and authors into the junction table.\nINSERT INTO TEST.DataModeling.BookAuthors (BookTitle, AuthorName) VALUES\n\t('David book 1', 'David'),\n\t('David book 2', 'David'),\n\t('Harry book', 'Harry'),\n\t('David &amp; Harry book', 'David'),\n\t('David &amp; Harry book', 'Harry')\n\n--Checking out the junction table &quot;BookAuthors.\nSELECT * FROM TEST.DataModeling.BookAuthors\n\n--Now we have a data model that allows for easy answers to most business questions.\n--How many authors are there? A simple COUNT(*) will answer this question.\nSELECT COUNT(*) AS COUNT_AUTHORS FROM TEST.DataModeling.Authors\n\n--How many books are there? A simple COUNT(*) will answer this question.\nSELECT COUNT(*) AS COUNT_BOOKS FROM TEST.DataModeling.Books\n\n--Show me all books by a certain author.\nSELECT \n\tBookAuthors.AuthorName, \n\tBooks.BookTitle \nFROM TEST.DataModeling.BookAuthors\nJOIN TEST.DataModeling.Books ON BookAuthors.BookTitle = Books.BookTitle\nWHERE BookAuthors.AuthorName = 'David'\n\n--Show me all authors that have written a certain book.\nSELECT \n\tAuthors.AuthorName, \n\tAuthors.Nationality\nFROM TEST.DataModeling.Authors\nJOIN TEST.DataModeling.BookAuthors ON Authors.AuthorName = BookAuthors.AuthorName\nWHERE BookAuthors.BookTitle = 'David &amp; Harry book'\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Kopieer\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">--Data modeling example about handling many-to-many relationships with a junction table. <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Drop junction table in order to be able to create the &quot;Authors&quot; and &quot;Books&quot; tables anew (avoiding the error: &quot;cannot drop table because it is references by a FOREIGN KEY constraint&quot;)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">DROP<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">TABLE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">IF<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">EXISTS<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.BookAuthors<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Creating table for authors of books.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">DROP<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">TABLE<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Authors <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">CREATE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">TABLE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">TEST<\/span><span style=\"color: #D4D4D4\">.DataModeling.Authors <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tAuthorName <\/span><span style=\"color: #569CD6\">VARCHAR<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">400<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #569CD6\">PRIMARY KEY<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tNationality <\/span><span style=\"color: #569CD6\">VARCHAR<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">400<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Inserting 2 authors into the Authors table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">INSERT INTO<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Authors <\/span><span style=\"color: #569CD6\">VALUES<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;NL&#39;<\/span><span style=\"color: #D4D4D4\">), (<\/span><span style=\"color: #CE9178\">&#39;Harry&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;EN&#39;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Checking out the table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> * <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Authors<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Creating table for books.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">DROP<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">TABLE<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">CREATE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">TABLE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">TEST<\/span><span style=\"color: #D4D4D4\">.DataModeling.Books <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tBookTitle <\/span><span style=\"color: #569CD6\">VARCHAR<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">400<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #569CD6\">PRIMARY KEY<\/span><span style=\"color: #D4D4D4\">,\t<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tPages <\/span><span style=\"color: #569CD6\">INT<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t\tAuthorName <\/span><span style=\"color: #569CD6\">VARCHAR<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">400<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Inserting 3 books into the Books table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">INSERT INTO<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books <\/span><span style=\"color: #569CD6\">VALUES<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David book 1&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">10<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;David&#39;<\/span><span style=\"color: #D4D4D4\">), (<\/span><span style=\"color: #CE9178\">&#39;David book 2&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">20<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;David&#39;<\/span><span style=\"color: #D4D4D4\">), (<\/span><span style=\"color: #CE9178\">&#39;Harry book&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">30<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;Harry&#39;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Checking out the table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> * <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--So far so good. However, what if authors David and Harry are BOTH author of a book? Now things will get tricky.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">INSERT INTO<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books <\/span><span style=\"color: #569CD6\">VALUES<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David &amp; Harry book&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">40<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;David &amp; Harry&#39;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Checking out the table: we have a problem. Value &quot;David &amp; Harry&quot; in column &quot;AuthorName&quot; from table &quot;Books&quot; does not exist in table &quot;Authors&quot;.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Inserting value &quot;David &amp; Harry&quot; in table &quot;Authors&quot; would introduce a host of problems: do we add extra columns for Nationality since David and Harry have different nationalities? Not really a scalable solution.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Now imagine you have a third book that is written by good ol&#39; Harry and a new author. Do we add two rows in the &quot;Authors&quot; table? One for the new author and one for the combination of Harry and the new author?<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--How do we use these tables to answer questions from the business like: how many authors are there? A simple COUNT(*) of the &quot;Authors&quot; table returns wrong results. <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--COUNT(DISTINCT AuthorName) returns wrong results as well! Also queries to identify the contribution of individual authors become complex without manual parsing. <\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> * <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--An elegant way of solving this, is by creating a junction table.<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Starting with a clean slate, let&#39;s empty the &quot;Books&quot; table. <\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">TRUNCATE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">TABLE<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--The next step is to remove the &quot;AuthorName&quot; column from the &quot;Books&quot; table. We now have an empty &quot;Books&quot; table with only the columns &quot;BookTitle&quot; and &quot;Pages&quot;.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">ALTER<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">TABLE<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books <\/span><span style=\"color: #569CD6\">DROP<\/span><span style=\"color: #D4D4D4\"> COLUMN AuthorName<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Authors table remains the same.<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Insert the existing books into the &quot;Books&quot; table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">INSERT INTO<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books (BookTitle, Pages) <\/span><span style=\"color: #569CD6\">VALUES<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David book 1&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">10<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David book 2&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">20<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;Harry book&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">30<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David &amp; Harry book&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">40<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Checking out the new &quot;Books&quot; table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> * <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Checking out the unchanged &quot;Authors&quot; table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> * <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Authors<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Now let&#39;s create the junction table called &quot;BookAuthors&quot;.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">CREATE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">TABLE<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">TEST<\/span><span style=\"color: #D4D4D4\">.DataModeling.BookAuthors<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    BookTitle <\/span><span style=\"color: #569CD6\">VARCHAR<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">400<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    AuthorName <\/span><span style=\"color: #569CD6\">VARCHAR<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">400<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">CONSTRAINT<\/span><span style=\"color: #D4D4D4\"> PK_BookAuthors <\/span><span style=\"color: #569CD6\">PRIMARY KEY<\/span><span style=\"color: #D4D4D4\"> (BookTitle, AuthorName),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">CONSTRAINT<\/span><span style=\"color: #D4D4D4\"> FK_BookAuthors_Books <\/span><span style=\"color: #569CD6\">FOREIGN KEY<\/span><span style=\"color: #D4D4D4\"> (BookTitle) <\/span><span style=\"color: #569CD6\">REFERENCES<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books(BookTitle),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">CONSTRAINT<\/span><span style=\"color: #D4D4D4\"> FK_BookAuthors_Authors <\/span><span style=\"color: #569CD6\">FOREIGN KEY<\/span><span style=\"color: #D4D4D4\"> (AuthorName) <\/span><span style=\"color: #569CD6\">REFERENCES<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Authors(AuthorName)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">-- Insert the relationships between books and authors into the junction table.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">INSERT INTO<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.BookAuthors (BookTitle, AuthorName) <\/span><span style=\"color: #569CD6\">VALUES<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David book 1&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;David&#39;<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David book 2&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;David&#39;<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;Harry book&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;Harry&#39;<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David &amp; Harry book&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;David&#39;<\/span><span style=\"color: #D4D4D4\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\t(<\/span><span style=\"color: #CE9178\">&#39;David &amp; Harry book&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;Harry&#39;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Checking out the junction table &quot;BookAuthors.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> * <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.BookAuthors<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Now we have a data model that allows for easy answers to most business questions.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--How many authors are there? A simple COUNT(*) will answer this question.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">COUNT<\/span><span style=\"color: #D4D4D4\">(*) <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> COUNT_AUTHORS <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Authors<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--How many books are there? A simple COUNT(*) will answer this question.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">COUNT<\/span><span style=\"color: #D4D4D4\">(*) <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> COUNT_BOOKS <\/span><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Show me all books by a certain author.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tBookAuthors.AuthorName, <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tBooks.BookTitle <\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.BookAuthors<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">JOIN<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Books <\/span><span style=\"color: #569CD6\">ON<\/span><span style=\"color: #D4D4D4\"> BookAuthors.BookTitle = Books.BookTitle<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">WHERE<\/span><span style=\"color: #D4D4D4\"> BookAuthors.AuthorName = <\/span><span style=\"color: #CE9178\">&#39;David&#39;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">--Show me all authors that have written a certain book.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tAuthors.AuthorName, <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\tAuthors.Nationality<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.Authors<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">JOIN<\/span><span style=\"color: #D4D4D4\"> TEST.DataModeling.BookAuthors <\/span><span style=\"color: #569CD6\">ON<\/span><span style=\"color: #D4D4D4\"> Authors.AuthorName = BookAuthors.AuthorName<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">WHERE<\/span><span style=\"color: #D4D4D4\"> BookAuthors.BookTitle = <\/span><span style=\"color: #CE9178\">&#39;David &amp; Harry book&#39;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Why does Power BI hate many-to-many relationships? Despite the title (that did its job in getting your attention) many-to-many relationships *-* are not necessarily evil. However, modeling your data in a manner that avoids many-to-many relationships helps in a lot of scenarios with data consistency, among other things. Let&#8217;s dive into this using the ancient&hellip;<\/p>\n<p class=\"more-link\"><a href=\"https:\/\/datadandies.nl\/index.php\/2024\/12\/27\/why-many-to-many-relationships-are-evil\/\" class=\"themebutton\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":554,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[16,3,4],"class_list":["post-538","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-datamodeling","tag-powerbi","tag-sql"],"_links":{"self":[{"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/posts\/538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/comments?post=538"}],"version-history":[{"count":11,"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/posts\/538\/revisions"}],"predecessor-version":[{"id":585,"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/posts\/538\/revisions\/585"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/media\/554"}],"wp:attachment":[{"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/media?parent=538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/categories?post=538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/datadandies.nl\/index.php\/wp-json\/wp\/v2\/tags?post=538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}