This is a discussion on PROCEDURES and TRIGGERS - inserting into multiple tables problem within the MySQL forums, part of the Database Server Software category; --> I have 2 tables: article_list and article_data. CREATE TABLE article_list ( id int(10) unsigned NOT NULL auto_increment, title varchar(100) ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I have 2 tables: article_list and article_data. CREATE TABLE article_list ( id int(10) unsigned NOT NULL auto_increment, title varchar(100) default NULL, PRIMARY KEY (id) ) CREATE TABLE article_data ( id int(10) unsigned NOT NULL auto_increment, articleID int(10) unsigned default NULL, story text, PRIMARY KEY (id), KEY (articleID), CONSTRAINT `FK_data_list` FOREIGN KEY (articleID) REFERENCES article_list (id) ON DELETE CASCADE ) What i'm trying to do is - insert story into table article_data at the same time as inserting title into table article_list (id from table article_list and articleID from table article_data must be the same, i hope u understand); Therefore, i've created trigger (on table article_list) and procedure: CREATE PROCEDURE insertData(tmpTitle varchar(100), tmpStory text) BEGIN SET @fullStory=tmpStory; INSERT INTO article_list(title) values (tmpTitle); END CREATE TRIGGER articleListTitle AFTER INSERT ON article_list FOR EACH ROW BEGIN INSERT INTO article_data SET articleID= NEW.id; UPDATE article_data SET story=@fullStory WHERE articleID=NEW.id; END; For example after query: CALL insertData('My title', 'My full story') table article_list contains values (1, 'My title') and table article_data (1, 1, 'My full story'). Basicly, this works just fine for me... But i was wondering, what if, for example, procedure "insertData" has about 1000 calls at the same time (or at very small interval)??? How does it work? Does second call of the same procedure starts at the same time or after the first call has finished? I hope you understand my question! Am i doin' it right? Can I end up with mixed titles and stories? Is there any other way of doin' it? |