Difference between revisions of "UPDATE"

From SQLZOO
Jump to: navigation, search
(Created page with " <h1>UPDATE</h1> <table class='NoBorder'><td><tr> The table <code>games</code> shows the year and the city hosting the Olympic Games. </td><td> <table style='float:left' class...")
 
Line 23: Line 23:
 
INSERT INTO games VALUES (2004,'Athens');
 
INSERT INTO games VALUES (2004,'Athens');
 
INSERT INTO games VALUES (2008,'Beijing');
 
INSERT INTO games VALUES (2008,'Beijing');
INSERT INTO games VALUES (2012,'London');
+
INSERT INTO games VALUES (2009,'London');
 
</source>
 
</source>
 
The UPDATE statement can be used to change a values in rows that already exists.
 
The UPDATE statement can be used to change a values in rows that already exists.

Revision as of 11:52, 18 February 2013

UPDATE

The table games shows the year and the city hosting the Olympic Games.

games
yrcity
2000Sydney
2004Athens
2008Beijing
2012London
schema:scott
 DROP TABLE games
 CREATE TABLE games(
  yr INTEGER,
  city VARCHAR(20));
INSERT INTO games VALUES (2000,'Sydney');
INSERT INTO games VALUES (2004,'Athens');
INSERT INTO games VALUES (2008,'Beijing');
INSERT INTO games VALUES (2009,'London');

The UPDATE statement can be used to change a values in rows that already exists. In this example we move the 2012 games from London to Paris.

UPDATE scott.games SET city='Paris' WHERE yr = 2012;
SELECT * FROM scott.games;
UPDATE games SET city='Paris' WHERE yr = 2012;
SELECT * FROM games;

See also

Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense