Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MYSQL


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Triggers Or Stored Functions


I am developing a membership system wherein every year, the status of all registered members would be changed to something else. I want this function to execute automatically. I think this has something to do with triggers but I can't find a tutorial that can clearly explain how to do it.




View Complete Forum Thread with Replies

Related Forum Messages:
Mysql And Triggers/stored Procedures
I have a question regarding the use of triggers. I have difficulties implementing trigger that let's say reacts before/after select statement (select of user), and increments the counter value (of the selected user). Is there a way to achieve this through triggers, or it's not possible?

View Replies !
Socket Programming With Stored Procedures/triggers
I'm currently working on a project where we may need publish/subscribe functionality (ie. a client registers an interest in a certain event, and the server will publish an update notice to the client when that event occurs).
One way I was thinking of doing this is to create an AFTER INSERT trigger on the table in question and get it to somehow notify either the middleware (a daemon running on localhost) or the client (a standalone java app running on a remote machine) that a change has occurred. To do this I'd most likely need to write to a socket from within the trigger or stored procedure.

Does anyone know if this is possible? I've had a brief look in the MySQL documentation and nothing seems to jump out at me.

View Replies !
Can Arrays Be Used In Stored Procedures And Triggers In Mysql?
I was trying to use arrays in stored procedures but it resulted in syntax errors.Is there any way to use arrays in stored procedures.

I have one more question,in triggers if we want to check each column of a table if updated ,is there any way that i can write then in a loop.

In the example given below I tried to check change for each column in a table.If there are 10 columns then I have to wirte 10 if statements.
Is there any way that I list all the columns of the given table with in a trigger and write loop that contain a if statement that works for all the columns.

create trigger updata after update on dataid_list for each row
BEGIN
if NEW.databaseid <>OLD.databaseid
then insert into view_changes
SET old=OLD.databaseid,new=NEW.databaseid, operation='UPDATE',column_name='databaseid'
end if;
if NEW.databasename <>OLD.databasename
then insert into view_changes
set old=OLD.databasename,new=NEW.databasename, operation='UPDATE',column_name='databasename'
end if;
END;

View Replies !
Stored Functions.
Can stored functions return triggers?

View Replies !
Exporting MySQL Database Including Stored Procedures And Triggers
How do I export a mysql database including all related triggers and stored procedures?

I want to make a copy of the entire thing into a new database for testing.

View Replies !
SET Datatype In Stored Functions
i'm trying to create a stored function that can tokenize a file path and give me access to each directory in the path. i hoped to do this by replacing the slashes with commas and then treating the result as a set. below is the function. the 'FIND_IN_SET' command works properly, so that proves that the file path variable can be treated like a SET, at least in some respects. i need to to be able to supply an integer index and retreive the corresponding string in the set from within my function. is there any way to do this?

delimiter $
CREATE FUNCTION ADD_FILE (filepath VARCHAR(256) )
RETURNS VARCHAR(25)
BEGIN
DECLARE i INT;
SET filepath = REPLACE(filepath, '/', ',');
SET i = FIND_IN_SET('luma', filepath );
RETURN filepath;
END$
delimiter ;

View Replies !
Stored Procedure And Functions?
I would like to ask some questions about stored procedure and functions.
I know some of their difference when it comes to returning values, stored procedures can return many values while stored functions can only return single value.

I want to know if they have difference when it comes to speed, is stored procedures faster than stored functions?

Follow up question,doing some procedures and functions in my database, does it make my applications fast?

Actually I studied this features hoping to make my applications run fast. So that's why Im asking about the speed.

View Replies !
Why Dont Shared Hosting Accounts Provide Stored Procedures And Triggers?
i am searching for 3 days now for a reliable, fast hosting company, which supports stored procedures and triggers on mysql5. most of them dont support this, because mysql5 has a design-flaw in which it stores procedures and triggers on a root level-area (tables mysql information_schema). due this logic, most of the hosting companies wont allow you to create/run procedures and triggers. funny, that hosting companies forbid you to use new technologies and methods to build faster.

View Replies !
Stored Procedures & Filesystem Functions
I've seen this done with MSSQL, I'm wondering if there is a way to do it with MySQL 5.0.

I want to have a table where each record stores some meta data about a file. Instead of having a longblob column to store the binary of the file in, I'd prefer to just write each file to disk and name it with the auto increment value of the table.

If I delete a row, I want it to automatically delete the associated file from the disk as well.
The problem is that I don't see any filesystem functions. Is this functionality missing from MySQL?

View Replies !
Can A Stored Procedure Call C++ Functions?
I need to parse a string in the stored procedure. Parsing a string in C++ is easy and fast,so I'm wondering if the stored procedure can call some C++ functions?

View Replies !
Roles, Stored Procedures, User-defined Functions
We are considering switching to mySQL for a Web application. The
current functionality relies on roles, stored procedures, and
user-defined functions that are created specifically for the
application. We use roles to provision different access levels to
groups of users.

I understand that mySQL v4.1 does not have these features yet.
However, is there a timetable for when these will be available?

View Replies !
DDL Triggers
Is it possible to create DDL triggers in MySQL? For example:

CREATE TRIGGER my_trigger AFTER ALTER ON my_table

View Replies !
Triggers?
I am using an Update trigger and I need to pull a variable to place in my log table out of the update query.

I noticed you can select from "inserted" and "deleted", is "updated" also a valid table to select from? Is there documentation on this somewhere.

View Replies !
Using Triggers With PHP
I can't seem to make this work. I've been feeding this into a MySQLi object:
DELIMITER |
CREATE TRIGGER trigger AFTER INSERT ON msp_account
FOR EACH ROW BEGIN
INSERT INTO log_table_change (
table,
table_id,
user
)
VALUES (
'test_table',
NEW.msp_account_id
'test_user'
)
END
|
... and using the multi_query() method, But never seems to work. No errors, just no work.

View Replies !
Triggers In MaxDB 7.5*
I have a situation where in my program written in "C" has to wait. Is there a convenient facility to do this in MaxDB. For Ex:

calling "C" function from the trigger itself, or waiting for a event in the "C" program and posting such an event from a trigger etc.

View Replies !
Writing Triggers
I need to write trigger which will update 3-4 table ,with relevant records.The sceneriao is as under.We have 2 databases server.We have set up the replication successfully with these 2 servers for database A .One is the master (MYSQL 4.1) on linux and the second one is slave(MYSQL 5.0) on windows.
Now on the slave server we have a another db B which consist of 5 tables.We need to fire a trigger to insert,update,delete records into these 5 tables every time data is replicated to slave.The problem is that not the entire record is to be inserted from the replicated table.Only few coloumns is to be iserted,say col1,col5 , col9 to be inserted in table1;col1,col3,col8 to be insrted in table2 ;col 3,col6,col7 in table3 and so on.I am wondering how to achive this.Please help me in this .Its really very urgent.

View Replies !
System Log For Triggers
Is there a system log file which can be checked to see the histroy of triggers. I am trying to debug a trigger that is not executing when it should.


View Replies !
Create Triggers
Ive been using SQL: Beginner's Guide Second Edition, and have been doing the projects that go along with each module. I've had trouble with the following command and was just wondering what I could to do troubleshoot.

CREATE TRIGGER InsertLog
AFTER INSERT ON Artists
REFERENCING NEW ROW AS New
FOR EACH ROW
BEGIN ATOMIC
INSERT INTO ArtistLog ( ActionType, ArtistID )
VALUES ( 'INSERT', New.ArtistID );
END ;

Both tables were created with no problem. The error I kept recieving was error 1064 (42000) saying that I had some syntax error near the REFERENCING line (line 3). There was also an error saying I had a syntax error near END.

View Replies !
Triggers Implemented...
Bit of a simple question for you all...

Using: MySql 5, Suse 10, myAdmin...

I have my triggers ready to spring into action when my database is modified.

How do I attach/make it listen to my database?


View Replies !
Creating Triggers
following error:

Script line: 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insert into mysql_product(Pro_Id,Name,Rank,Flag) values(New.pid,New.Pname,'7','Tr' at line 4

This is my trigger:

CREATE TRIGGER mysqltri After insert on product
for each Row
begin
insert into mysql_product(Pro_Id,Name,Rank,Flag) values(New.pid,New.Pname,'7','True');
END$
delimiter$

View Replies !
While Creating Triggers
I am trying to create a simple trigger by query as:

CREATE TRIGGER interactiontrigger AFTER INSERT ON InteractionDetails
FOR EACH ROW
BEGIN
UPDATE LeadDetails SET SalesStage= NEW.SalesStage WHERE Id = NEW.LeadId;
END

when i execute this query i get the following error as:

ERROR 1314 (0A000): Statements like SELECT, INSERT, UPDATE (and others) are not
allowed in a FUNCTION

View Replies !
Mysql 3.23.58 And Triggers
I know that mysql 3.23.58 does not have triggers but what do to get around that? I am working on a banking project. We have a table for accounts and a table for transactions. The accounts table has a attribute for the balance but everytime there is a transaction the balance needs to be updated to reflect it. How can I accomplish this without triggers?

View Replies !
Triggers Problems
I am running 5.0.18 and am trying to create a trigger. with the following

CREATE TRIGGER updatenumb AFTER INSERT ON childtable
BEGIN
UPDATE parenttable SET postnumb = (postnumb +1) WHERE childtable.pt_id = parenttable.id
END;

The table is innoDB with a foreign key reference (to the parent table) When I try I get the following error.

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BEGIN UPDATE.


View Replies !
Validating Using Triggers?
If i have a table that includes start_date and end_date,
how can i validate this data in the DBMS without using a stored procedure? I have already written the application, i just want to add DBMS validation on new rows that will be inserted so that start_date is always less than or equal to end date..
In oracle i would simply raise an application error in the trigger and then i could assign an error message with it.. I can't seem to find any such ability in mysql.. can i even restrict inserts/updates within triggers in mysql,

View Replies !
Question About Triggers
I want to install a trigger that updates a total (subtracting 1) whenever a row is deleted. Does it make sense to do it the following way?

Create Trigger:

CREATE TRIGGER trigger_name AFTER DELETE ON table_name
FOR EACH ROW SET @rows_deleted = @rows_deleted + 1;

Delete Rows:

SET @rows_deleted = 0;
DELETE FROM table_name WHERE column_name = 3434;
UPDATE table_name SET count = (count - @rows_deleted) WHERE id = 767;

So instead of issuing an update for each row that's deleted, it records how many were deleted and then issues one update after they're all deleted.

View Replies !
Triggers To A Remote Database
We make use of a PACS (Picture Archiving and Communication System) and
system to store DICOM (Digital Imaging and Communication in Medicine)
images (like CT scans, MR images etc.) in our Oncology Center. This PACS
system uses mysql as it's native database, in which it stores certain
data as date and time of the examination, it uses InnoDB tables.

We are building another application around it, which will use data from
the PACS tables and will hold additional data in a seperate database in
it's own tables.

Every study has it's own unique identifier which is stored in the PACS
database. Additional data is stored in the additional database, under
the same unique identifier to be able to keep track of the data and link
it to each other.

Now I would like to know if it is possible to add a trigger to the PACS
database which will delete the related information in the additional
database if a record in the PACS database is dropped. This trigger will
have to delete the records in the additional tables before dropping the
data in it's own database, so we can maintain a more compact database
and don't store data which we cannot link to the PACS system anymore.

View Replies !
Triggers - Compare With Null
I am new to mySQL. I am an Oracle Developer, learning mySQL. Thank you for looking at this post.

1. What is the best tool for mySql front end.

2. Is MySQL code (such as triggers code or names of the columns) are case sensitive when porting from Windows to Linux?

3. Is it possible to write one single trigger on multiple events as in Oracle.
For example in Oracle ....

View Replies !
Triggers And Store Procedure
Can I use triggers and store procedure in mySQL 4.0.20? If not, is it possible to fulfill it in another way?

View Replies !
Triggers To Update Another Table
I see there is a limitation with triggers about refering to table names. So if I wanted to have a trigger on 1 table to update another table, I'm assuming this isn't possible? Bascially it's a reload project.

When one table's flag is set to released, I want to add a record into a Reload table, that has some record information from the updated table. A process is reading the Reload table and when it has records it reloads some data based on the records.

View Replies !
Mysqldump Restore Triggers
I have inherited a stone-aged RedHat 8.0 system running mysql 3.23.52 which cannot be upgraded for various reasons I won't go into here. However the powers that be are finally interested in backing this system up, so I have started looking into mysqldump. In the interests of recoverability, I have created a RedHat 9 system running mysql version 3.23.54 which I am now attempting to restore my dump file to.

So. To create my dump, I am doing this:

# mysqldump --opt --all-databases --user="root" -p > all-databases.dump

On the restore system, I do this:

# mysql -u root -p < all-databases.dump

...and it ticks along for a while and finally announces:

ERROR 1062 at line 6005: Duplicate entry '1' for key 1

Looking at line 6005, it says (line numbers added by me):

6004: LOCK TABLES groups WRITE;
6005: INSERT INTO groups VALUES (0,'Administrators'),(1,'Anonymous'),(2,'File Admin'),(3,'Company');

This does not appear to be a TINYINT problem; the table does not appear to be defined with a TINYINT.

I have googled around and the lack of an answer implies I'm doing something trivially incorrect.

View Replies !
Triggers/Locking/Constraints
I have two issues. Firstly, I have a table of users and a table of permissions. Is there a way to use a trigger or some kind of locking in InnoDB tables such that the superuser and its permissions cannot be deleted?

I also would like to know if it's possible to constrain insertions into a certain table such that one and only one of two fields must be null. In this case, my table of permissions has two foreign keys for each record: a user ID and a group ID. If the permission applies to a user, the group ID should be null, and vice versa.

For security reasons, I would greatly prefer if this logic could be put in the database so that I can simply revoke ALTER privileges from the DB user so nothing can be done from PHP.

View Replies !
Do Triggers Support Transactions?
Do triggers in MySQL support transactions?

Also, are there any pros/cons of using triggers as opposed to stored procedures?

View Replies !
Cascade Delete Or Triggers?
Something that annoys me about MySQL is the fact that triggers are not activated when a row is deleted as a result of a cascade delete. I fail to see why this is, but perhaps there is a good reason, or its a bug, who knows.

Anyway, I want to use some triggers here and there to ensure the data is as tidy as possible, and remove anything that doesn't need to exist any more (e.g. I have a couple of 1 to 1 relationships that really do need to be two separate tables), but the lack of cascade delete is causing problems.

I started replacing one or two of the cascade deletion settings with triggers, to simulate the cascade, and allow the other triggers to work, but as I add more tables and it all gets more complicated its becoming a real nightmare maintaining it, and working out which cascades need to be triggers.

My question is this, is there any way at all to get cascades to activate triggers? Or would there be a major performance impact if I just dropped all cascades and replaced them all with triggers?

View Replies !
Using Triggers For An Event Logger
I have to build an event logger so I have to save in a MySQL table every change that I user can make in his profile. I think triggers would be the best choice in this case so here goes my question: is it possible to make a trigger which can save in another table:

- the name of the field that has been modified,
- the previous value of that field,
- the current value of that field?

View Replies !
Enable/Disable (toggling) Triggers
I want to ENABLE/DISABLE my triggers time to time based upon certain conditions multiple times. How can I do that in MySQL ?

View Replies !
Triggers To Confirm Update Or Delete
I need to create a trigger that notifies me that a table I have created has been updated or added to. Basiccally I am using a website to send details to my database but I need to know when data has been submitted.

View Replies !
MySql Triggers And Foreign Keys
I would like to know if MySql supports triggers. I would also like to know if i can cascade updates and deletes on foreign keys. Please supply me with a sample code to create triggers if they exist and for cascading deletes and updates if any.

View Replies !
Impossible To Create/delete Triggers
DELIMITER $$ 
DROP TRIGGER IF EXISTS `mydatabase`.`definitions_after_insert` $$ 
CREATE TRIGGER `mydatabase`.`definitions_after_insert`AFTER INSERT ON `mydatabase`.`definitions`FOR EACH ROWBEGINEND;$$

I get the following errors:
Script line: 3 Trigger does not exist
Script line: 5 Trigger already exists

So, basically, MySQL tells me I can't delete a trigger because it doesn't exist, and then it tells me I can't create a new one because it *does* exist, after all.

The information schema's triggers table is also empty.

Furthermore, the "Trigger does not exist" message should not even appear, since I use "drop trigger IF EXISTS"...

View Replies !
Triggers Stop Update And Insert
I have a table with dates and I want to make a before insert and update trigger that check the dates for a condition and then stop the update and the insertion if the condition is true.

View Replies !
How To Create Triggers From Mysql Query Browsers
i am using mysql5.0 on linux.when i am creating triggers in mysqlquery browser. got the error. my trigger code: ...

View Replies !
I Need A Triggers That Calls External Dlls To Perform Action
Is it possible to create a trigger that calls an external dll to perform an action? If so, does anyone know how to write such a trigger.

View Replies !
Functions
I am developing applications using PHP and MySQL.

There are various functions in MySQL that is also implemented in PHP. Such
as date arithmetic, string, numeric, etc...

Do I get better performance if I do them in MySQL (or PHP) and why?

View Replies !
Min Max Functions
I can't find documentation on this facet of max, min. Consider

id item category price
1 nail fastener 0.25
2 screw fastener 0.38
3 hammer tool 12.98
4 plier tool 6.99
5 level tool 27.99
7 anchor fastener 31.23
6 gum fastener 0.10

want to find max price in each category AND WHAT IT IS.

SELECT
id,
item,
category,
max(price) AS price
FROM
hardware
GROUP BY
category

Is the SELECT correct? Is the item and id returned for the price where it is MAX. It does not appear it works in all cases. Is there a way to put MAX in the where clause like:

WHERE
max(price) = price

View Replies !
Using VB Functions In SQL
I have a field named "users" with a list of users:

0001-username1
0002-username2
0003-username3
0004-username4
0005-username5

and I want to sort the query by only the "username" half of it.
ie. (if RS = recordset) right(RS.fields("users"), len(RS.fields("users")) - 5)

what would be the SQL statement to get the desired results?

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved