Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




Best Way To Update Multiple Tables At Once


I need to update a few tables at once. I have a form, were I fill in some information about a concert, which updates thez concert-table. Next to this, I need to update the bands-table, the statistics-table, and some others. What would be the safest, and fastest way to achieve this?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Update Multiple Tables?
situation:
a user wants to change their username on my site and their username is littered accross many tables in the DB. If in every one of those tables i've got a static "user_id" column as well as the "username" column, what is the best way to update all of the different tables with the most efficiency?


UPDATE Multiple Tables Difficulties
I've been creating a stock update system that needs to be integrated with an existing database. To update the stock I need 2 tables updated in the same query (unless there is better way).

In one table, items_ordered, holds every single product that has been sold and has a field StockUpdated which holds a 1 or 0 depending on whether they have been stock counted already. This will stop future queries counting stock that has already been counted. i.e. the query will look and update each record that has a 0. So far the query is able to update this table successfully.....

Extract Multiple Columns From Multiple Tables
For hours and hours I've been trying to work out how to write the sql query to extract some data from some tables, but with no luck.....

Joins With Multiple Tables And Multiple Rows
I'm making a good ol' forum, and i have three tables, users, threads
and posts. when i query my threads table with a join, i need to access
the users table twice to get the username of the first poster and last
poster. But how? I can only figure out how to get one or the other. Is
my design bad? eg

SELECT TopicID, FirstPostID, LastPostID, Replies, Views, Topic,
username FROM DiscussionThreads, users WHERE
DiscussionThreads.FirstPostID=users.ID ORDER BY FirstPostDT DESC LIMIT
10 .

Multiple Smaller Tables V.s. Fewer Bigger Tables
What is the best way to store data in a database? Multiple smaller tables (which means many Inner/Left Joins when fetching the information) or fewer bigger tables (which means few or no Inner/Left Joins when fetching information).

Multiple Batabases Vs. Multiple Tables
I am about migrate from an old program database to MySql (Running under RH
LINUX)and I'm wondering which is the best option to do :

I currently have one file for each of my modules, (I'm using filepro plus) ,
so like CUSTOMER, WARRANTY, ZIPCODES, INV, etc... like 2,000 files each with
their own fields.

1) Should I create multiple databases on MySQL

2) Should I create a single database on MySql and with multiple tables ?

Which one of these options is the best and more safer ?

Multiple Databases Or Multiple Tables
I have an application that is supposed to make multiple connections [around 10 connections per second] to a mysql database. The connections are done by mutlitple users at potentially the same time.

I have to decide if I should use :

1)one database with one table for all users.
2)one database for each user.
3)one database with one table for each user.

I would really appreciate if you can tell me what choice is best and why.

Multiple Update.
I am starting with a datbase structure like this:

 ID  |  filename  |  info1fromfile  | info2fromfile
-------------------------------------------------------
   1      file1        
   2      file2

My query loops through the filename column and then opens each file listed in turn.

Whilst open it extracts strings from the text files.
These are to be entered into the rows relative to that filename. So I should end up with this:

 ID  |  filename  |  info1fromfile  | info2fromfile
-------------------------------------------------------
   1      file1        someinfo1        someinfo2
   2      file2        someinfo3        someinfo4

To be able to run the UPDATE I need to know which row I am currently on. Is there a way to do that as the filename QUERY pulls out the filenames? I guess Ideally I need to know what ID we are on.

Also is there an easy way to count how many filenames have been looked at so I can use LIMIT so that the UPDATE statement doesn't try to UPDATE the whole database every time. (The number of files will get larger over time so I only want to update the rows necessary!)

Multiple Update
I have two simple tables t1 and t2. I want to update the price field in t2 with the values of the (selected) price field in t1. I have followed other threads regarding similar problems and have worked out that these two attempts should work. Alas, they don't. Anybody any ideas?

UPDATE t2, t1
SET t2.price = t1.price
WHERE t1.item_code=t2.item_code
AND (((t1.selected)= 1))

UPDATE t2 INNER JOIN t1 ON t1.item_code=t2.item_code
SET t2.price = t1.price
WHERE (((t1.selected)= 1))

I am pasting these directly into mysql using phpmyadmin.

Multiple Update
I'm looking at producing an application that will allow multiple users to
order multiple items/ parts from what would effectively be an online store.

These users could be ordering several hundred items/ parts at a time, each
item/ part ordered representing one box or several hundred.

Each part record will require the "total stock" to be down dated and each
unit will require updated to show it as having been picked (plus other
info).

I'm looking at programming this in php 4.3 or php 5 using a current version
of mysql. Looking around etc. I believe there are various options options
open to me :

1 Create a pick list in a database table and have a "pick" routine pick the
stock. This would ensure that the actual pick could only be carried out by
a single process and the result of the pick request could be emailed to the
user. This approach would provide the user with a very fast, responsive
acceptance of an order request (but not real time - albeit almost).

2 Use Table Locks - This I understand may be the fastest but potentially
could leave users with apparently hung screens, eg. if three picks were
issued each taking 10 secs, then pick 3 would not start until the first two
picks completed (20 secs).

3 Record Locks - I'm concerned that doing this would increase the time taken
to pick the stock. But if the times were not excessive this would provide
the user with an immediate "real time" response.

Multiple UPDATE
I have a txt file with around 5000 lines that look like

UPDATE `members_user` SET `user_forums` = '0' WHERE `user_name` = 'user'


when i go to SQL query in phpmyadmin and give it 1 of the lines individually it will take it, and when I give it 2 lines, or all of them it wont, saying there is a syntax error. I used 'find/replace' to format the file so each line is exactly the same, so obviously it wont allow me to do this command more then 1 at a time, but I cant do every single line like that, there must be a faster way.

Multiple UPDATE
i'm trying to update 3 different rows in my DB...can this be done with one query ? i tried a couple different methods, but kept giving me errors

Multiple Update Of 21 Rows
I have a database table which holds price ranges for various classes of hire car and various hire periods. There are 7 different hire classes and 3 different hire periods. 21 records in total.

Heres an example of what the table contains:

ID......HIRE PERIOD.....HIRE GROUP....PRICE
1..........14.....................a...............25.00
2..........28.....................c...............15.00

The rows are shown in an editable form, which is basically a grid of text fields.

I need to figure out the most efficient way of updating all the records when the grid is edited. Do I need to perform 21 individual updates? as I'm worried that this will be too cumbersome when there are multiple users.

I thought of one way which involves having a hidden field for each row, called 1,2,3 etc, each with a value of eg. 14,a,25.00 as a comma seperated list. Then I split the post values into arrays and perform various updates.
Seems a bit clunky though,

Update Multiple Rows
I have about 20 rows that need to updated together and would rather not have 20 seperate update lines but am not sure what else to do. At the moment it looks something like this:

UPDATE movies SET mon='10pm', tues='10pm', wed='11pm' WHERE movie_id='19'...
UPDATE movies SET mon='9pm', tues='11pm', wed='4pm' WHERE movie_id='37'...
UPDATE movies SET mon='8am', tues='1pm', wed='5pm' WHERE movie_id='19'...

There is no logical order to the movie_id's they are selected from the movies table using specific criteria.


Update Multiple Fields
I need to update some 900,000 records, each different. I will be pasting the code into the sql window of PHPMyAdmin at my web site. The individual updates look like this:

UPDATE table SET Field1='sample', Field2='sample1' WHERE UniqueID=12345

UPDATE table SET Field1='sample2', Field2='sample3', Field3='yes' WHERE UniqueID=2021432

How can I string together a bunch of these where the SET field values are always different and there is one each for 900,000 different ID's. Right now, I have these in 30 text files but I can't seem to get the syntax correct.

Update Multiple Rows
I have an array that I need to put into an existing db column using a perl foreach loop. I can do this using an INSERT statement but the script will be run every day and the source array will be changing as it is based on directory contents so I need to UPDATE vs. INSERT

With the INSERT statment the script places each array element on a new row of the db as it should but when I try to use an UPDATE statement, I get a single array element written over and over on each row of the db. Code:

Update Multiple Fields With 'OR'
Is there a better way to do this (more efficient).

I have up to 200 items to update per query, the id's are not sequential. Using up 200 (well 199) OR's in a single query doesnt strike me as being the best way to do this. All the fields get set to the same value.

# Example
UPDATE table SET value=value WHERE id=11 or id=23 or id=31 or id=74 or id=56 or id=96;
# Up to 200 fields

Or am I stuck with this query? (which works).

Multiple-table Update With Sum()
I have the quantities from different warehouses for each product in products_quantities, and the aggregate quantity for each product in products. I want to update products with the total from products_quantities. Why does this not work?

UPDATE products p, products_quantities pq
SET p.products_quantity = SUM(pq.quantity)
GROUP BY pq.products_id

I've tried every variation I can think of, but always get a syntax error near 'GROUP BY pq.products_id'. Can I not update one table with the sum of values from another table, in one query? I'm using 4.0.26.

Multiple Update In 1 Query
I am trying to do the following using PHP and Mysql:

$sql="
UPDATE records set appear_order='2' WHERE id='19';
UPDATE records set appear_order='3' WHERE id='17';
UPDATE records set appear_order='4' WHERE id='18';
UPDATE records set appear_order='5' WHERE id='20';
UPDATE records set appear_order='6' WHERE id='16';
";

I am getting the following error message:
" Cannot update records: 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 'UPDATE records set appear_order='2' WHERE id='19'; UPDATE recor"

I don't know why this isn't working.
when I paste this query to phpMyAdmin (I hope you guys know phpMyAdmin) - it works.
somehow using a PHP code it does'nt - I get that error message.
did anyone every come across this error and knows how to overcome it?

Multiple-table UPDATE.
I'm trying to update multiple-tables at the same time but I read somewhere that you could do it if you had mysql version 4.0.4. But currently, I have version 4.0.0 and I want to know how to do it with this version

Update Multiple Columns
I get an error on this command:
UPDATE patchMapTable SET row=0,column=0,patchNumber=23

"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 'column=0,patchNumber=23' at line 1"

row, column, and patchNumber are columns in patchMapTable
all 3 are int
row and column are primary keys

Multiple UPDATE Entry
I just want to update 2 or more things at the same time... but dunno how... here's what i would use:Code:

UPDATE users SET location = 'changed' , password = 'new pass' WHERE username = 'david'
OR SET location = 'changed too' , password = 'new pass too' WHERE username = 'brett'

But that doesn't work, (it's not like i thought it would anyway)... how would i update 2 or more different fields at the same time?

How To Update All Fields With A Multiple Of The Field Value?
Is there a MySQL command to replace all the values of a field with the field's original value that's had a mathematical formula applied to it? Basically, I want to divide the field's original value in half, then add 40% more. The formula would be y=x/2+.2x where y is the new value and x is the original value.

I know I could write a PHP script that would select each field's value, apply the formula, then update the new value, but it'd be cool if there's a MySQL built-in function to do this.

How To Update Multiple Rows With One Query?
I am using PHP/MySQL and need to update 7 rows with one query. Can someone tell me how to do the following so it will update the row for each day of the week? (This obviously doesn't work)

$sql = "UPDATE business_hours SET hours='$sunday' WHERE id='$id' AND day='sunday' AND SET hours='$monday' WHERE id='$id' AND day='monday'";

Update Multiple Rows Outside Loop
I know it possible to update rows in loop. But how about outside the loop?
Normally i update in loop like this:

How Do I Update Multiple Rows In One Query?
How do I update multiple rows in 1 query? I try not to do a loop of update queries.

Update Syntax For Multiple Columns
I'm looking for a feature I'm accustomed to with other SQL products, whereby multiple columns can be updated with a single SET clause, e.g.:

UPDATE tab1 SET (col1, col2, col3) = (SELECT col4, col5, col6 FROM tab2 WHERE tab2.col1 = tab1.col1);

I don't see this feature documented for MySQL. Is there a way to accomplish it?

Multiple-table UPDATE Does Not Work
I installed mysql-server-3.23.54a-11 and mysql-3.23.54a-11 rpms on RH9. Everything works fine. But when I try multiple-table UPDATE statement, it show me syntax error:

SQL statement:

mysqk> update country,city set country.cCode='A' where country.cCode = '1' and city.areaCode = country.cCode;

Error message:
ERROR 1064: You have an error in your SQL syntax near 'city set country.cCode='A' where country.cCode = '1' and city.areaCode =country.' at line 1

Update Multiple Rows Within One Table
I have a Dynamically created formfield. Tgis field shows the attached devices off a selected device (for instance you have a pc and in the formfields it shows two attached monitors). The monitors however are in the same database table. (with an other device_id ofcourse). The page with the pc info is shown by using the device_id in the URL.

What I want to do is update some fields in this table for the pc but also for the attached devices....

When I do it like this:

UPDATE dev SET .... etc.
WHERE device_id IN ('#FORM.koppel_2#')

It selects both device id's like this: WHERE dev_volgnr IN ('602,603')
This doesn't work! However in this example the table should be updated for the devices with device_id 602 and 603.

Is this possible? How would I do that?

Update Function With Multiple Databases
We are looking for a way without having the possibility to install the last version of MySQL to do the equivalent of

Update t1,t2 set t1.fielda=1 where t1.key=t2.key and t2.field='processed'

meaning that we want to be able to update certains values in the table t1 depending on values coming from t2 having the same key number.

Multiple Updates Per Row In A Multi-table Update
I'm wondering how exactly a multi-table update works. I'm using the following queries.
I expect t to contain (1, 2) and (2, 0), but it contains (1, 1) and (2, 0).
Why? .....

UPDATE Multiple Values - Proper Syntax?
I use powerbuilder with mysql database.I want to get server's datetime.

Can't Update Multiple Rows Via PHP, But Works In PhpMyAdmin
My php script will update 1 row fine, but fails on 2. However, the exact same query works when pasted into phpMyAdmin.

THIS QUERY WORKS BOTH IN MY PHP AND PHPMYADMIN:

$sql = "update table set color='red' where id='1';";
$sql_do = mysql_query($sql);

THIS QUERY WORKS ONLY IN PHPMYADMIN:

$sql = "update table set color='red' where id='1'; update table set color='green' where id='2';";
$sql_do = mysql_query($sql);

I know the second query is correct, because when I copy it from my php code and paste it into phpMyAdmin, it works. But only the first query, with 1 row update, works from my php code.

The Most Efficient Manner To Update Multiple Rows
I have a table that holds information about people
The table is quite large (300,000 rows)
I need to write code that update many of the rows in the table

Here is what I need to do
Two of the fields that I store about each person are: location and country
The location is some free text which the user can type in, while the country is the ISO country code, like "US", "ES" and so on

I need go over all the records in the database, and for those that have a non-empty location field, to extract the value and to try to guess what country the user is from and to update the Country field accordingly

My problem is that I might find that most of the records need updating, and this might lead to 100,00+ update statements

I cannot use LOAD DATA as this is product database

Is there a way to update multiple rows (each with a different value and condition in a single query?

How To Insert And Update Multiple Values In One Record
How do I insert and update multiple values in one record. e.g.

1. How do I insert "dogs,cats, snakes" in one record
2. If I have "dogs, cats, snakes" in one record and I want to update it and add 'pigs' to make it "dogs, cats, snakes, pigs", how do I do that?

Incremental Backups Using Update Logs With Multiple Databases
I've set up my server to keep update logs for incremental backups, as described in Kevin Yank's book (Build Your Own... 3rd Edition), but I've noticed that the update.* files have entries from all the databases on my server. Is there a way to automatically split up the log files so that I can have separate update.* files for each database?

Running Multiple Update Querries In Query Browser
I am trying to run multiple update statements together from the MySQL Query Browser. For example:

update table1 set field1 = "123", field2 = '456' where rowid = 'abc'
update table1 set field1 = "321", field2 = '654' where rowid = 'efg'

I can run them one at a time, but I cannot run multiple updates at the same time. I have 1100 of them to run, so I don't want run them individually.

In M$ SQL I can just put a ; or GO at the end of each line to seperate it from the next. How can I do this in MySQL?

Update All Tables
Is it possible to update all tables in my DB on one query

Multiple Tables
Why yes! I am new and terrible at both mysql & php! Now that I got that off my chest...

Can you pull data from 2 tables in the same database onto the same page? What about more than 2 tables?

Here is my dilema: I currently have a database with 1 table, and a ton of rows. The information is property information, and each property has multiple empty suites. As of now, I have columns for Building Name, Address, and then columns for Unit Type A (for the first unit), Rent A, Type B, Rent B, etc....

I was wondering if I would be able to put the listings we have into thier own property table, and then one bigger table of all the properties individual information. Keep in mind I need to call all tables together on my portfolio pages, so I would be connecting to quite a few tables at once.

Or my other option I was thinking about was to just have 2 tables: 1 Buildings info, and 1 units info.

Which of these would you do, or how would you organize this data.

You can see an example of the data I am inserting into tables here (http://www.webpropertiesinc.com/compor.php).

Multiple Tables
I have a db, with several tables in it, I have now reached to the point where I need to pull data from several tables. What is the best way to do this?

Should I put a column in each table, and then insert a unique key in all of them at the time the record(row) is being created? If this is the way to do it, when I am putting the unique key in each table would I just do an insert in each of the tables?

Multiple Tables DB
Does anyone know of a practical tutorial (with code) that uses multiple related tables.
I want to learn how to update all related data when doing an insert.

e.g.: if I add a user to users table and each user gets a car by defualt, how do I insert a car to cars table and keep a reference to the user (owner of this car).

Multiple Tables Or Just One?
I want to store a large set of variables into a database that are all characteristics of the users of my site. They can register by filling out their name/ adres/ city / day of birth etc.

Besides that they can set a number of preferences (e.g. 'available on monday', 'available on tuesday', 'category 1', 'category 2' etc.) that can be either '1' or '0'.

Furthermore I want to store some variables that tell me if the supplied email adress is validated, what the ip-adress of the registrant is and on what date he registered.

Using MySql, what method is preferred to store the data:

1) one table with +/- 40 columns (note that there a lot of values are booleans).

2) 3 tables, e.g. users, preferences, other with 5 to 20 columns each.

The thing is that I want to be able to perform searches that include all types of characteristics. E.g. I want to select all users that are:

'male, older that 18, are available on monday, preffer category 2 and where the email adress is validated'

Multiple Tables
I have two tables that have item information that I am trying to make a search for. I have it working for searching one table, but I can't figure out how to make it search both.

Current:
"SELECT * FROM `god_items` WHERE `item_name` LIKE '%$search%' OR `guardian` LIKE '%$search%' ORDER BY type ASC"

second table is set_items

Multiple Tables
I have 7 tables with identical fields (OK ideally therefore they should just be in one big table! But cos it's maintained in MS Access originally using forms etc, I'd like that option to be a last resort).

I simply want to sort them into alphabetical order where the 'for_sale' AND 'new' fields equal 1.

Should I just do 7 separate queries? Should I use the UNION function (which seems very complicated at the moment)?


Multiple Tables
I am setting up a staff contact list. Basically fields like, First Name, Spouse, Last Name, Address, Phone, Birthday, Children and their birthdays, job title, email, and a few other fields.
Also need to learn how to put a photo on here as well.

Multiple Tables
i have a database with 10 tables, each table has around 9,000 record, is it faster and better to put all records in ONE HUGE TABLE and define each table with a column ?? i mean i have table for games, softwares, movies, etc ... so i put ALL the records in one table and make a column named "type" and i insert in each column the corresponding value.

Multiple Tables
I would like to SELECT information out of around 100 tables. The thing is I would like to avoid typing all those 100 names manually.
Is there a way of doing something like:

sql Cod
Original
- sql Code




SELECT oneCell FROM tablePrefix_% WHERE id=1;



SELECT oneCell FROM tablePrefix_% WHERE id=1;


The tables are named as tablePrefix_ and than the name of the table like tablePrefix_A, tablePrefix_B and so on.The version I am using is mySQL 4.0.27.


Update - Mult Tables
Early experimentail stages with Databases. I have this little faq sys running on my dev server BUT just uiploaded to my host and what yer know it aint working..

two tables question and answers
two "Poted vars" $an and $id

I am trying to update the answer to a qu....

UPDATE answers,questions SET anstext = '$an' WHERE questions.ans_id = answers.id AND questions.id= '$id'
I read that multiple tables was only suppoerted on later vers on Mysql...OR is my syntax just wrong

How To Update Two Or More Tables Simultaneously
How can I update two or more tables simultaneously with single update query ?



Copyright © 2005-08 www.BigResource.com, All rights reserved