Difference between revisions of "CREATE a VIEW"

From SQLZOO
Jump to: navigation, search
(Created page with "CREATE a VIEW. <div class='ht'> <div class=params>schema:scott</div> <div> A view is a named SELECT statement. In this example we show only European countries, we also show t...")
 
Line 12: Line 12:
  
 
<source lang=sql class='tidy'>DROP VIEW v_europe</source>
 
<source lang=sql class='tidy'>DROP VIEW v_europe</source>
<source lang=sql class='tidy e-access'>DROP TABLE v_europe</source>
+
<!--<source lang=sql class='tidy e-access'>DROP TABLE v_europe</source>-->
 
<source lang=sql class='setup'>DROP TABLE world;  
 
<source lang=sql class='setup'>DROP TABLE world;  
 
CREATE TABLE world(
 
CREATE TABLE world(

Revision as of 15:00, 17 July 2012

CREATE a VIEW.

schema:scott

A view is a named SELECT statement.

In this example we show only European countries, we also show the population in millions.

Note how the columns of the table may be named.

DROP VIEW v_europe
DROP TABLE world; 
CREATE TABLE world(
   name VARCHAR(50) NOT NULL
   ,region VARCHAR(60)
   ,population DECIMAL(11)	
   ,PRIMARY KEY (name)
   );
INSERT INTO world VALUES ('China','Asia',1261);
INSERT INTO world VALUES ('France','Europe',59);
INSERT INTO world VALUES ('India','Asia',1014);
INSERT INTO world VALUES ('Italy','Europe',57);
INSERT INTO world VALUES ('Japan','Asia',126);
INSERT INTO world VALUES ('Russia','Asia',146);
INSERT INTO world VALUES ('Spain','Europe',39);
CREATE VIEW v_europe AS
 SELECT name,
        population AS pop
  FROM world 
  WHERE region='Europe';
 
SELECT * FROM v_europe
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense