Welcome Guest, Not a member yet? Register   Sign In
3 DELETE queries or 1 combined DELETE query?
#1

[eluser]RS71[/eluser]
Hello

I am currently working out a couple queries and I needed to delete all rows with a certain value and replace them with rows coming from a form.

Currently I need to alter 3 tables, so at first I was doing three separate queries just for deleting.

The -SUM- of the 3 queries would average out to be 0.0034

Now I recently put them all into one DELETE query and that one combined query is taking about 0.0268

My application will have many users connecting to this form at once and I think I should probably have 7+ queries every time the form is successfully submitted.

Should I stick with the combined query?

Also, is there a simpler way to replace all rows = to a certain value instead of 1 delete query and 3 separate inserts?

Thanks in advance
#2

[eluser]RS71[/eluser]
By the way, this is the way I am deleting rows from 3 tables:

DELETE FROM `table_1`, `table_2`, `table_3` USING `table_1`, `table_2`, `table_3` WHERE table_1.user_ID = table_2.user_ID AND table_1.user_ID = table_3.user_ID AND table_1.user_ID = 1
#3

[eluser]devbro[/eluser]
i am not sure about this but does your database supports database-side scripting? if so you can write a simple script that does the deleting and insertion for you in the database.

i know that oracle has this but not sure about mysql.
#4

[eluser]bitist[/eluser]
[quote author="devbro" date="1233472819"]i am not sure about this but does your database supports database-side scripting?[/quote]

Yes, starting from MySQL 5.1 it has trigger support and you can write database side scripts.




Theme © iAndrew 2016 - Forum software by © MyBB