<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>constraint Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/tag/constraint/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/tag/constraint/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Thu, 11 Dec 2025 13:13:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>SQL-Basics: Relations</title>
		<link>https://creatronix.de/sql-basics-relations/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Thu, 18 Apr 2019 08:02:28 +0000</pubDate>
				<category><![CDATA[Data Science & SQL]]></category>
		<category><![CDATA[constraint]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[join]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=1326</guid>

					<description><![CDATA[<p>As the Junior Data Scientist of Knight Industries we created a table to keep track of all our operatives: SQL-Basics: Create, Read, Update, Delete Devon asks us to keep track of our operations aka missions as well. For the first implementation let us assume that a mission has one operative and an operative can participate&#8230;</p>
<p>The post <a href="https://creatronix.de/sql-basics-relations/">SQL-Basics: Relations</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>As the Junior Data Scientist of Knight Industries we created a table to keep track of all our operatives: <a href="https://creatronix.de/sql-basics-create-read-update-delete/">SQL-Basics: Create, Read, Update, Delete</a></p>
<p>Devon asks us to keep track of our operations aka missions as well. For the first implementation let us assume that a mission has one operative and an operative can participate in multiple missions. that&#8217;s what we call an 1 to many relationship.</p>
<pre>  +------------+                 +----------+
  |            |1   active in   n|          |
  | operative  +-----------------+ missions |
  |            |                 |          |
  +------------+                 +----------+
</pre>
<p>Missions have an id, a code name like &#8220;Phantom Liberty&#8221;, an operative id and a total cost.</p>
<p>To say that the operative id is equivalent to the id in the operative column we use the FOREIGN KEY constraint.</p>
<p>So let&#8217;s create the new table in our database:</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-sql" data-lang="SQL"><code>CREATE TABLE ki_missions 
(id INTEGER, code_name TEXT, operative_id INTEGER, total_cost DECIMAL(15,2), PRIMARY KEY(id), FOREIGN KEY (operative_id) REFERENCES operatives(id));
INSERT INTO ki_missions VALUES (1, "Knight of the Phoenix", 1, 6246382.43);
INSERT INTO ki_missions VALUES (2, "Deadly Maneuvers", 1, 4568893.53);</code></pre>
</div>
<p>Our first join</p>
<div class="hcb_wrap">
<pre class="prism line-numbers lang-sql" data-lang="SQL"><code>SELECT ki_missions.code_name, ki_operatives.name FROM ki_missions LEFT JOIN ki_operatives ON ki_missions.operative_id = ki_operatives.id;</code></pre>
</div>
<p>More on joins <a href="https://dsin.files.wordpress.com/2013/03/sqljoins_cheatsheet.png">https://dsin.files.wordpress.com/2013/03/sqljoins_cheatsheet.png</a></p>
<p>Next chapter: <a href="https://creatronix.de/sql-functions/">SQL-Functions &#8211; SQL-Basics 3</a></p>
<p>&nbsp;</p>
<p>The post <a href="https://creatronix.de/sql-basics-relations/">SQL-Basics: Relations</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
