On 10/17/08, Kristofer Hindersson <[EMAIL PROTECTED]> wrote: > Hi, > > I've recently started to play around with SQLite and I'm currently trying to > create a trigger for updating a timestamp field inside a table (SQL-syntax > for the creation of the table is included below.) Could someone please tell > me how I should go about writing such a trigger. I'd like the [updated]-field > to be set to the current timestamp everytime an entry is updated/modified. > > Thanks! > > /Kris > > CREATE TABLE IF NOT EXISTS Entries ( > entryID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, > title VARCHAR(50) NOT NULL, > created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, > updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, > signature VARCHAR(25) NOT NULL, > body TEXT NOT NULL); >
CREATE TRIGGER add_date AFTER INSERT ON Entries BEGIN UPDATE Entries SET updated = datetime('now') WHERE entryID = new. entryID; END; -- Puneet Kishor http://punkish.eidesis.org/ Nelson Institute for Environmental Studies http://www.nelson.wisc.edu/ Open Source Geospatial Foundation (OSGeo) http://www.osgeo.org/ _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users