Always use manualy Query (UPDATE table SET column = replace(column,"-","") WHERE `column` REGEXP '-') My question: How to build a "trigger" for the update database which removes the sign "-"?
Always use manualy Query (UPDATE table SET column = replace(column,"-","") WHERE `column` REGEXP '-') My question: How to build a "trigger" for the update database which removes the sign "-"?
D A V E schreef: ( http://www.**--****.com/ ) CREATE TRIGGER testref AFTER UPDATE ON table FOR EACH ROW BEGIN UPDATE table SET column = replace(column,"-","") WHERE `column` REGEXP '-'; END; | But i'm not sure.... Would this do an 'UPDATE' for EACH ROW it finds in table 'table'...? And would 'AFTER UPDATE' also be triggered after an insert...?
Given the syntax used it would execute against all rows. You need to look at the docs. http://www.**--****.com/ In an trigger there is an OLD and NEW column.. OLD being the existing and NEW being the new values you have supplied in the INSERT or UPDATE statement.
1.(RegExp in Access):VBA (RegExp in SQLServer):?
Currently I am using the RegExp object to parse a large dataset in an Access table - but this table was exported from SQL Server, and the very correct question was asked - why not just do it in SQL Server. What would be the best way to convert the VBA code I use in Access to SQL Server - being only marginally familiar with T-SQL syntax and not at all familiar with what can or cannot be done? -- Darryl Kerkeslager
2.create a trigger for update field
I've a member table with a field named lastvisit (type int) that contain values like 1215285455 that I've a credit field (type int) I would like to create a new trigger that add 1 value in credit field each time that a user enter in the site.... please note that I've to add 1 only one time per day if today I enter 3 time I want only add one value in credit field Can you help me?? I can also create new temp field for manage this information thanks
3.how to create error raised by trigger
Hi i would have a trigger to check the data before inserting/updating a table and if the data is not valid it would raise an error ... like if new.total < 0 then raise_error(10001, ' you cannot use the resources anymore') end if ; in oracle i used raise_application_error(errcode, 'explaination'); how to do the same thing on mysql ? I also got an 'weird' data handling in mysql, suppose the field was "not null" but when i tried to insert/update the data .. it still able to insert the data ... like tableX { id : int, auto increment, primary key name : varchar(20) ; not null ; desc : varchar(20): not null ; } when i did a script like this insert into tableX (name) values ('ABCDEF'); it would insert into database without generating error ... it should raise an error because 'desc' should be filled in (not null). how to solve this problems without my program doing a checking one by one ? Thanks adwin
4.Trigger on creating a record
Hi All I am writing an in-house application for managing our projects. all going fine so far. I would like to automatically create a folder on the server (FreeBSD 5.21) when a new record is added to the projects table. The folder will be in a samba shared folder and the name would come from a combination of two compulsory fields in the projects table. I am looking to use a trigger on the insert command but do not know how to interact with the OS. The ownership of the parent folder will be given to the mysql user. Any suggestions TIA Richard
Here is the code I tried: delimiter $; CREATE TRIGGER archive_addresses_ins BEFORE INSERT ON archive_addresses FOR EACH ROW BEGIN SET NEW.interview_date = CURRENT_TIMESTAMP; END$ delimiter ; I adapted this from an example on page 207 in the third edition of "MySQL: The definitive guide to using, programming, and administering MySQL 4.1 and 5.0" by Paul DuBois. When submitted using MySQL Query Browser, I get an error 1064, complaining about the last line shown. I was going to add this trigger to each of my archive tables, and then use an insert statement of the following form to keep the archives up to date. INSERT INTO archive_t SELECT * FROM t WHERE ..... Of course, the where clause will be structured to ensure only the current data being stored in the main tables (using either insert or update statements) will be added to the archive. The tables archive_t and t are identical, except for the engine (ARCHIVE and InnoDB respectively) and the fact archive_t has the extra field "interview_date" I want to make sure I have this right before writing the code for the several dozen archive tables. For the applications where I am doing this, the first purpose of the archive tables is to ensure there is a complete record of all data entered, for the purposes of supporting accurate audits. And for some, there is an additional purpose of supporting monthly and annual summary statistics. DuBois says that triggers can't refer to tablenames, and rightly points out that this limits their utility. If he is wrong (or has been made wrong by changes made to MySQL 5 since his book went to press), then I'd add triggers to the main tables that insert the data provided to them into the archive tables. Three questions: 1) What is wrong with the SQL statements above that create my triggers? 2) Is there a faster way to create the triggers I need for all several dozen archive tables; faster than just typing similar code for each table? 3) Is there a better way to achieve my purpose? Thanks, Ted
Users browsing this forum: No registered users and 64 guest