DATA MANAGEMENT STATEMENTS - INSERT: already seen that - UPDATE table SET ... WHERE ... - DELETE FROM table WHERE ... - caution: these operate on whole tables if unqualified - strategies to avoid catastrophes -- just subconsciouly be careful, like holding a kitchen knife -- put comment in front: -- DELETE FROM ..., then remove comment -- do SELECT first, then replace SELECT with DELETE <- allows inspection of what's about to be deleted -- tweak table name, put x in front, then remove I/O - all RDBMSs have scriptable I/O tools - generally, INSERT one at a time is slow - output to CSV -- COPY Species TO 'species_fixed.csv' (HEADER, DELIMITER ','); - loading CSVs: see build script -- 1. CREATE a new empty table in the database: CREATE TABLE Snow_cover ( Site VARCHAR NOT NULL, Year INTEGER NOT NULL CHECK (Year BETWEEN 1950 AND 2015), Date DATE NOT NULL, Plot VARCHAR, -- some Null in the data :/ Location VARCHAR NOT NULL, Snow_cover INTEGER CHECK (Snow_cover > -1 AND Snow_cover < 101), Observer VARCHAR ); -- 2. Copy the data from a csv COPY Snow_cover FROM 'snow_cover_fixedman_JB.csv' (header TRUE); NOTE: If you run this last lines several times you will keep adding the data to the table!!! TRIGGERS - on some event, take some action(s) - event: insert, update, delete on some table - action: insert or update in same table or any other table - example: SQLite imports empty columns as empty strings, not NULLs, which is lame - database.db build script (look at it) does post-import updates - trigger approach! - can't play with real Species table due to foreign keys -- .import --csv species.csv new_species - .nullvalue --NULL-- - notice no NULLs! - CREATE TRIGGER fix_species AFTER INSERT ON new_species FOR EACH ROW BEGIN UPDATE new_species SET Scientific_name = NULL WHERE Code = new.Code AND Scientific_name = ''; END;