Operations like DROP, DELETE, INSERT, and UPDATE don't have an "undo" operation.
When you're experimenting with a database, it's good to have a backup. See
this discussion of pg_dump to
see how to back up your database and restore it later.
Creating a table
DROP TABLE IF EXISTS populations;
CREATE TABLE populations (
city text,
year int,
population int
);
Completely removing a table.
DROP TABLE tablename;
Inserting a new row.
INSERT INTO populations (city, year, population) VALUES ('Northfield', 2010, 20);
Changing an existing row.
UPDATE populations SET population=21 WHERE city='Northfield' AND year=2010;
Finding and arranging data with certain properties.
SELECT * FROM populations WHERE year=1900 ORDER BY population DESC;
SELECT population FROM populations WHERE year=1900 AND city='Minneapolis';
SELECT cities.name, pops.population
FROM cities, pops
WHERE year=1970
AND pops.city_id=cities.id
ORDER BY pops.population DESC;