Unix Technical Forum

PROCEDURES and TRIGGERS - inserting into multiple tables problem

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) ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 08:34 AM
D.B.
 
Posts: n/a
Default PROCEDURES and TRIGGERS - inserting into multiple tables problem

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?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:18 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com