<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.webhuis.nl:443/index.php?action=history&amp;feed=atom&amp;title=Foreign_key</id>
	<title>Foreign key - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.webhuis.nl:443/index.php?action=history&amp;feed=atom&amp;title=Foreign_key"/>
	<link rel="alternate" type="text/html" href="https://wiki.webhuis.nl:443/index.php?title=Foreign_key&amp;action=history"/>
	<updated>2026-09-03T17:20:03Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.17</generator>
	<entry>
		<id>https://wiki.webhuis.nl:443/index.php?title=Foreign_key&amp;diff=4326&amp;oldid=prev</id>
		<title>Martin at 09:53, 8 June 2022</title>
		<link rel="alternate" type="text/html" href="https://wiki.webhuis.nl:443/index.php?title=Foreign_key&amp;diff=4326&amp;oldid=prev"/>
		<updated>2022-06-08T09:53:23Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 09:53, 8 June 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 40:&lt;/td&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 40:&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  SELECT * FROM foobar WHERE id_foo = 1; -- that one is gone as well&lt;/div&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  SELECT * FROM foobar WHERE id_foo = 1; -- that one is gone as well&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;hr/&amp;gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td colspan=&quot;2&quot; class=&quot;diff-empty diff-side-deleted&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Terug naar: [[Standaard opzetjes]]&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Martin</name></author>
	</entry>
	<entry>
		<id>https://wiki.webhuis.nl:443/index.php?title=Foreign_key&amp;diff=4320&amp;oldid=prev</id>
		<title>FrankHeikens: Created page with &quot;Aanmaken van foreign keys, zonder actions, en later het wijzigen van de foreign key om wél een action in the stellen:     CREATE	TABLE foo(id_foo INT PRIMARY KEY, content TEX...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.webhuis.nl:443/index.php?title=Foreign_key&amp;diff=4320&amp;oldid=prev"/>
		<updated>2022-06-08T07:32:55Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Aanmaken van foreign keys, zonder actions, en later het wijzigen van de foreign key om wél een action in the stellen:     CREATE	TABLE foo(id_foo INT PRIMARY KEY, content TEX...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Aanmaken van foreign keys, zonder actions, en later het wijzigen van de foreign key om wél een action in the stellen:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  CREATE	TABLE foo(id_foo INT PRIMARY KEY, content TEXT);&lt;br /&gt;
&lt;br /&gt;
  CREATE TABLE bar(id_bar INT PRIMARY KEY, content TEXT);&lt;br /&gt;
&lt;br /&gt;
  CREATE TABLE foobar(&lt;br /&gt;
    id_foo INT&lt;br /&gt;
  , id_bar INT&lt;br /&gt;
  , PRIMARY KEY (id_foo,id_bar)&lt;br /&gt;
  , CONSTRAINT fk_id_foo FOREIGN KEY (id_foo) REFERENCES foo(id_foo) -- no action defined, falls back to DEFAULT&lt;br /&gt;
  , CONSTRAINT fk_id_bar FOREIGN KEY (id_bar) REFERENCES bar(id_bar) -- no action defined, falls back to DEFAULT&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
-- some data in all tables:&lt;br /&gt;
  INSERT INTO foo(id_foo, content) VALUES(1, &amp;#039;foo content&amp;#039;);&lt;br /&gt;
  INSERT INTO bar(id_bar, content) VALUES(1, &amp;#039;bar content&amp;#039;);&lt;br /&gt;
  INSERT INTO foobar(id_foo, id_bar) VALUES(1,1);&lt;br /&gt;
&lt;br /&gt;
-- now try to delete some data from &amp;quot;foo&amp;quot;:&lt;br /&gt;
  DELETE FROM foo WHERE id_foo = 1; -- fails!&lt;br /&gt;
&lt;br /&gt;
-- And this is why:&lt;br /&gt;
  SELECT * FROM foobar WHERE id_foo = 1; -- this record is linking to &amp;quot;foo&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  BEGIN; -- always within a single transaction to avoid data corruption&lt;br /&gt;
  	ALTER TABLE foobar &lt;br /&gt;
    		DROP CONSTRAINT fk_id_foo;&lt;br /&gt;
  	&lt;br /&gt;
  	ALTER TABLE foobar -- what table?&lt;br /&gt;
    		ADD CONSTRAINT fk_id_foo -- what constraint name?&lt;br /&gt;
      			FOREIGN KEY (id_foo) -- what column for this table?&lt;br /&gt;
        		REFERENCES foo(id_foo) -- referencing what table? (in what schema?)&lt;br /&gt;
        		ON DELETE CASCADE -- what to do when a delete happens?&lt;br /&gt;
        		ON UPDATE CASCADE; -- what to do when an update happens?&lt;br /&gt;
  COMMIT;&lt;br /&gt;
&lt;br /&gt;
  DELETE FROM foo WHERE id_foo = 1; -- works!&lt;br /&gt;
&lt;br /&gt;
  SELECT * FROM foobar WHERE id_foo = 1; -- that one is gone as well&lt;/div&gt;</summary>
		<author><name>FrankHeikens</name></author>
	</entry>
</feed>