Simon Slavin-3 wrote: > >> CREATE TRIGGER UpdateSaleItemDescription BEFORE INSERT ON SaleItem >> BEGIN >> SET NEW.SaleItem_Description='Fish'; >> END; > > Yes. You can look at values using 'new.' but you cannot change them. > However, you do not need to. To perform such an operation as you list > above simply define a default value for the SaleItem_Description column. >
Thanks, Simon. If I wanted to do CREATE TRIGGER UpdateSaleItemDescription AFTER INSERT ON SaleItem BEGIN UPDATE SaleItem SET SaleItem_Description='Fish' WHERE SaleItem_Type='1' AND SaleItem_ID=New.SaleItem_ID; UPDATE SaleItem SET SaleItem_Description='Chips' WHERE SaleItem_Type='2' AND SaleItem_ID=New.SaleItem_ID; END; ...then I couldn't use default values, because you can't make defaults conditional. (Background: I've got a database schema in the form of a text file, which some software reads and converts to a SQLite database. I also need php to be able to read that text file and convert it into a MySQL database. I'm trying to work out how to define triggers so that I can change the schema information and have it work for both MySQL and SQLite... and am getting a headache in the process!) Thanks, Hamish -- View this message in context: http://old.nabble.com/SET-NEW.FieldName-in-trigger-tp33413040p33413181.html Sent from the SQLite mailing list archive at Nabble.com. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users