Difference between revisions of "CREATE TABLE"

From SQLZOO
Jump to: navigation, search
(Blanked the page)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  
<h1>CREATE TABLE</h1>
 
<p>The table <code>games</code> shows the year and the city hosting the Olympic Games.</p>
 
<table>
 
<caption align='center'>games</caption>
 
<tr><th align='center'>'''yr'''</th><th align='center'>'''city'''</th></tr>
 
<tr><td>2004</td><td align='left'>Athens</td></tr>
 
<tr><td>2008</td><td align='left'>Beijing</td></tr>
 
</table>
 
<div class='ht'>
 
<div class=params>schema:scott</div>
 
<source lang=sql class='tidy'> DROP TABLE games</source>
 
The CREATE statement builds an empty table to hold rows.
 
In this example the column yr is the PRIMARY KEY:
 
<source lang='sql' class='def e-oracle'>
 
CREATE TABLE games
 
(yr  INT NOT NULL PRIMARY KEY
 
,city VARCHAR(20)
 
);
 
INSERT INTO games(yr,city) VALUES (2004,'Athens');
 
INSERT INTO games(yr,city) VALUES (2008,'Beijing');
 
SELECT * FROM games;
 
</source>
 
<source lang='sql' class='def'>
 
CREATE TABLE games
 
(yr  INT NOT NULL PRIMARY KEY
 
,city VARCHAR(20)
 
);
 
INSERT INTO games(yr,city) VALUES (2004,'Athens');
 
INSERT INTO games(yr,city) VALUES (2008,'Beijing');
 
SELECT * FROM games;
 
</source>
 
</div>
 
 
<p>See also</p>
 
<ul>
 
  <li>[[INSERT_.._VALUES |INSERT]]</li>
 
  <li>[[DROP |DROP]]</li>
 
</ul>
 

Latest revision as of 18:20, 8 November 2015