Jump to content

Is it possible to do this in MYSQL


lampstax

Recommended Posts

Is it possible to create something in MySQL ( trigger ? stored procedure ? something else ? ) so that when any table is created on a DB thats has a name fitting a certain structure .. lets say like "user1_data", "user2_data" .. to insert a row into that newly created table?

 

Ofcourse this structure is a pretty ugly db design ( not mine ) and it could be done easily a php / java / ruby script, the situation dictates that no script is used.

 

I'm stumped.  What about you guys?

Link to comment
Share on other sites

Actually if I can get this trigger to work, it would solve my problems too, but I'm have some syntax issues

 

DELIMITER |

CREATE TRIGGER wpmu_new_blog_set_default_options AFTER INSERT ON wp_blogs
FOR EACH ROW BEGIN
SELECT SLEEP(2);                                                                                                                                 
SET @var := CONCAT('wp_', NEW.blog_id ,'_options');
UPDATE @var SET option_value = '0' WHERE option_name = 'option_x'; 

END;
|

DELIMITER ;

 

I feel like I'm sooo close, but its not working.  I"m not too familiar with triggers.  I bet its something small that I'm not seeing.

 

The MySQL error that I see is :

 

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 '@var
SET option_value = '0' WHERE option_name = 'option_x';

Link to comment
Share on other sites

Tried it too ways:

 

DELIMITER |

CREATE TRIGGER set_default_options AFTER INSERT ON authors
FOR EACH ROW BEGIN
SELECT SLEEP(2);  
PREPARE stmt_name FROM "UPDATE authors SET issued = '9' WHERE authorID = ?";
SET @test_parm = "2";
EXECUTE stmt_name USING @test_parm;
END;
|

DELIMITER ;

 

and even this didnt work

 

DELIMITER |

CREATE TRIGGER set_default_options AFTER INSERT ON authors
FOR EACH ROW BEGIN
SELECT SLEEP(2);                                                                                                                                 
PREPARE stmt_name FROM "UPDATE authors SET issued = '9' WHERE authorID = '2'";
EXECUTE stmt_name;
END;
|

DELIMITER ;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.