Reply
is it efficient to insert several table for executing 1 process?
Old 05-14-2007, 11:13 AM is it efficient to insert several table for executing 1 process?
Average Talker

Posts: 22
hi..

sorry, if i ask a simple question but it quite confusing me anyway..
so i have 3 table..
MR(MRId->pk, regDate)
patient(patientId->pk, fname, lname)
havepatient (MRId ->pk, patientId->pk)

my question is, if i want to add new MR, in which 1 MR can has several patients, it means that i have to execute3 different insert commands for both these 3 tables?

please reply me as soon as possible =)
thx for your attention
moccacinoe is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-15-2007, 06:20 AM Re: is it efficient to insert several table for executing 1 process?
chrishirst's Avatar
Super Moderator

Posts: 13,625
Location: Blackpool. UK
maybe, maybe not

depends on your DB server. Some versions will allow inserts into multiple tables in a single query

Code:
INSERT ALL INTO table1 (fieldlist1) VALUES(valuelist1) INTO table2 (fieldlist2) VALUES(valuelist2) ;
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-15-2007, 03:59 PM Re: is it efficient to insert several table for executing 1 process?
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,024
Name: Forrest Croce
Location: Seattle, WA
Chris - does that still fire off three inserts behind the scenes? Somehow I get the feeling that type of syntax is really more about easy SQL than efficiency inside the db engine?

Moccacinoe - What you're doing actually is pretty efficient. Databases are meant to do exactly what you're talking about, and optimized in many ways to get the job done more quickly. But consider the alternative; you could put everything in one table with lots more fields, and repeat the MR on every row. Then when you need to change, say, a last name, you might need to update several thousand rows instead of one. When you need to do a particular query, say to get the average of whatever, you'll be able to write queries that read in far less data, because the data is divided up between three tables. In a lot of different scenarios, accessing a smaller part of your data ( because you broke it up into relational tables ) is much faster than accessing all of it.

Three inserts might sound bad, but they're the price you pay for all this efficiency down the line.
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 05-15-2007, 10:00 PM Re: is it efficient to insert several table for executing 1 process?
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 984
Name: Jeremy Miller
Location: Reno, NV
Quote:
Originally Posted by chrishirst View Post
Code:
INSERT ALL INTO table1 (fieldlist1) VALUES(valuelist1) INTO table2 (fieldlist2) VALUES(valuelist2) ;
That's so cool. I never knew you could mix tables like that! Thanks.
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-16-2007, 06:39 PM Re: is it efficient to insert several table for executing 1 process?
chrishirst's Avatar
Super Moderator

Posts: 13,625
Location: Blackpool. UK
Quote:
Chris - does that still fire off three inserts behind the scenes? Somehow I get the feeling that type of syntax is really more about easy SQL than efficiency inside the db engine?
Never had the chance to test it on a real DB it's an Oracle syntax as I recall. MySql doesn't support it and I've never bothered to try it in MS, it's as easy to write a SP and fire the data to that.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-16-2007, 07:21 PM Re: is it efficient to insert several table for executing 1 process?
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,024
Name: Forrest Croce
Location: Seattle, WA
Ahhh, Oracle. They let you write queries like "Select * From A Join B Using xID" ... instead of "Select * From A Join B On A.xID = B.xID" Their SQL dialect is a lot more featured, letting people do things like store the data in two tables pre-joined on disc. I haven't had much opportunity to work with Oracle, but whenever I have, I've been amazed at all of what's available.
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 05-17-2007, 10:38 PM Re: is it efficient to insert several table for executing 1 process?
Learning Newbie's Avatar
Moderator

Posts: 5,199
Name: John Alexander
Oracle is way too complex. SQL Server really strikes the perfect balance between use and complexity. Seriously, we're talking like 40 or 50 keywords compared to like 400 or 500.
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 05-22-2007, 04:41 AM Re: is it efficient to insert several table for executing 1 process?
Average Talker

Posts: 22
Hi,

thx for your replies..
i just read the forum again =)
thx..

regards,


Lena
moccacinoe is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to is it efficient to insert several table for executing 1 process?
 

Thread Tools

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 Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15584 seconds with 12 queries