<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://sqlzoo.net/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://sqlzoo.net/w/index.php?title=Composite_primary_key&amp;feed=atom&amp;action=history</id>
		<title>Composite primary key - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://sqlzoo.net/w/index.php?title=Composite_primary_key&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Composite_primary_key&amp;action=history"/>
		<updated>2013-05-24T22:42:31Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.4</generator>

	<entry>
		<id>http://sqlzoo.net/w/index.php?title=Composite_primary_key&amp;diff=1102&amp;oldid=prev</id>
		<title>Marek: Created page with &quot;CREATE TABLE with a composite primary key &lt;div class='ht'&gt; &lt;div class=params&gt;schema:scott&lt;/div&gt; &lt;div&gt; A composite key has more than one attribute (field). In this example we s...&quot;</title>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Composite_primary_key&amp;diff=1102&amp;oldid=prev"/>
				<updated>2012-07-12T15:04:04Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;CREATE TABLE with a composite primary key &amp;lt;div class=&amp;#039;ht&amp;#039;&amp;gt; &amp;lt;div class=params&amp;gt;schema:scott&amp;lt;/div&amp;gt; &amp;lt;div&amp;gt; A composite key has more than one attribute (field). In this example we s...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;CREATE TABLE with a composite primary key&lt;br /&gt;
&amp;lt;div class='ht'&amp;gt;&lt;br /&gt;
&amp;lt;div class=params&amp;gt;schema:scott&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div&amp;gt;&lt;br /&gt;
A composite key has more than one attribute (field).&lt;br /&gt;
In this example we store details of tracks on albums - we need to&lt;br /&gt;
use three columns to get a unique key - each album may have&lt;br /&gt;
more than one disk - each disk will have tracks numbered 1, 2, 3...&lt;br /&gt;
&lt;br /&gt;
The primary key must be different for each row of the table.&lt;br /&gt;
The primary key may not contain a null.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;source lang=sql class='tidy'&amp;gt;DROP TABLE track&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;source lang=sql class='setup'&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;CREATE TABLE track(&lt;br /&gt;
  album CHAR(10),&lt;br /&gt;
  disk INTEGER,&lt;br /&gt;
  posn INTEGER,&lt;br /&gt;
  song VARCHAR(255),&lt;br /&gt;
  PRIMARY KEY (album, disk, posn)&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;source lang='sql' class='def e-mysql e-sqlserver e-sybase e-db2'&amp;gt;CREATE TABLE track(&lt;br /&gt;
  album CHAR(10) NOT NULL,&lt;br /&gt;
  dsk INTEGER NOT NULL,&lt;br /&gt;
  posn INTEGER NOT NULL,&lt;br /&gt;
  song VARCHAR(255),&lt;br /&gt;
  PRIMARY KEY (album, dsk, posn)&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;ecomm e-mysql e-sqlserver e-sybase e-db2&amp;quot; style=&amp;quot;display: none&amp;quot;&amp;gt;&lt;br /&gt;
We must explicitly state that the components are NOT NULL.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
{{CREATE and DROP ref}}&lt;/div&gt;</summary>
		<author><name>Marek</name></author>	</entry>

	</feed>