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




Table Locking When Updating From DataSet?


I have a bunch of code that updates tables from a VB.Net DataSets.

The original code updated Access2000 tables, I migrated the MDBs to MySql and have converted the data adaptors and command builders to MySqlClient statements.

Does anyone have any code examples to to the table locking using DataSets???




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Locking Table?
I've got two tables that control my menu on my site (which is coded in ASP).
The first table (cam_menu) contains info about the sort order of the menu
and the second about my content. To insert a menuitem above a previous
menuitem I use these SQL-sentences: Code:

Table Locking
I just have a question about the table locking in 3.23.56. If I am inserting a
row into a table that is MyISAM type, is the entire table locked? And, if so,
what does this mean for concurrent selects?

Locking Table?
I've got two tables that control my menu on my site (which is coded in ASP).
The first table (cam_menu) contains info about the sort order of the menu
and the second about my content. To insert a menuitem above a previous
menuitem I use these SQL-sentences: Code:

About Table Locking
One thread insert data to a specific table continuously using 'LOAD DATA INFILE..' or 'INSERT INTO ...' query. Actually, this table maintains only for one hour's data, so the delete query is performed before every insert query.
At the same time, another thread issues select query on that table periodically.

What I want to know is, whether it is free from the table corruption or not. Table level locking is performed in MySQL server? Or, I have to do explicitly?

Table Locking
I just have a question about the table locking in 3.23.56. If I am inserting a
row into a table that is MyISAM type, is the entire table locked? And, if so,
what does this mean for concurrent selects?

What Are The BIG Reasons For Locking The TABLE?
What are the BIG reasons for locking the table? :)
Why do we need to lock the table?

Table Locking When Using Left Join
I need someone to clarify something for me.
If I have a SELECT query on tableA that uses a left join to TableB, does TableB get locked for the duration of the entire select query? Suppose that the SELECT on tableA is slow, but the join to tableB is really fast, does tableB experience a lock for the duration of the query on tableA?

Is it better to just run a query on tableA, and after run fast indexed queries on tableB?

Table Locking & Multiple Jobs
I'm using mySQL 4.1 (will be upgrading to 5 soon), and I have a problem with table locking.

My table is MyISAM.

I have a job running every x seconds that loops round the following process 10 times.
Each time it loops round it locks the table, reads into memory the oldest record in the table, deletes this oldest record and then unlocks the table and does some further processing of the data in memory.

Problem is that I need to have two or more of these jobs running at once, and when this happens, occasionally each of the two jobs will process the same record in the table ... how can this be????? I'm doing a table lock which I thought would prevent two seperate jobs accessing the same record?!?!

Locking A Table/Record/Field
Is there a way to actually insert data into the table and then lock it, disallowing all write attempts to the table/record/field?

Locking Of Table Through VB For Write/Update
Can anybody help me out by giving some hint on how to lock MySQL tables from VB for doing write or update?

Denormalized Tally, Table Locking Issues?
Say I have a `news` table (MyISAM). People can vote an article up/down. User votes are recorded in `news_votes`. To alleviate the need for performing expensive AGGREGATE functions with a join between the two, I was thinking of keeping a running tally in the news table (`tally`, mediumint).

Assume a few hundred news stories per day each with hundreds of votes per day. I'm afraid that the table-level locking of MyISAM on the news table will result in performance degradation due to the fact that SELECTS can't run concurrently with UPDATES.

What are you thoughts about this method of slight denormalization? I've seen it on lower concurrency system archetecture like Wordpress blogs.

Updating Rows In Table B Based On Related Field In Table A
Ver 4.1.8-standard for apple-darwin7.6.0 on powerpc (Official MySQL-standard binary)

I am trying to do some data migration based. I have several tables that contain our legacy pkey field and I want to update the tables with new ID's.
I need to do this several times and have tried it several ways to no avail.

Table A
---------
companyID int(10) pKey
legacyID int(10) old legacy pkey

Table B
---------
bAID int(10) pkey
companyID int(10)
legacyID int(10)

Table A has values for both companyID (unique key) and legacyID.
Table B has values for bAID (unique key) and legacyID but companyID is empty.

I need to update tableB.companyID with tableA.companyID based on tableb.cSerialID to tablea.cSerialID relationship.

I need a query that will update ALL rows.

Updating Table Based Upon Matching Field In Second Table
I have a database of books that was originally created as a flat file.
Each record has a number of fields, including the authors name. I'm
trying to convert the database to something a little more efficient.
I've created a new table (called Authors) of unique authors names and
assigned each one a unique ID. I've added a new field in the original
table (called Books) for the author's ID. Now, I need to update the
original table with the author ID from the Author's table.

Something like this:

UPDATE Books SET AuthorID = Authors.AuthorID WHERE AuthorName =
Authors.AuthorName

This obviously doesn't work. Any assistance on how to forumulate this
query (or, if I'm headed down the wrong path, the correct way to do this
operation) greatly appreciated.

Dataset Collation
I am using phpMyAdmin for a database and when creating a new table it ask me to specify the table's "collation". I am a bit baffled on this and if someone might shed some light I'd appreciate it. I realize this may not be the forum but hopefully someone can point me in the right direction. My site is a site that will only have English characters in it.

How To Assign Value To A Percentage Of Dataset
I'm actually working in SQL within SAS. Bit of a n00b i'm afraid. I need to assign a value to a percentage of a table.. for example

the first third of records myVal=1
the second third of records myVal=2
the third third of records myval=3

So just to clarify in a table of 30 records, i need records 1-10  myval = 1
11-20 myval = 2
21-30 myval = 3

Compare Difference Between Dataset
My mysql database will take in a larget set of data periodically. Each set of data has a unique ID that I can control. I'm looking for a simple way to display the difference between each set of data. The data is in the following format

SET 1
ip port runid
192.168.0.1 20 1
192.168.0.1 23 1
192.168.0.2 20 1


SET 2
ip port runid
192.168.0.1 20 2
192.168.0.2 20 2

The difference is that one of the IP in SET 1 is gone in SET 2. This is the type of difference that I'm looking for.

Can anyone tell me what's the simplest way to generate a differential report? I was thinking about putting each set of data in their own seperate databases(9 tables in each set, but only 1 needs to be compared), then run some kind of command that compare databases.

Automatic Dataset Refresh
I want to display records from my database in a GUI (windows form). Specifically, I want to display the newest record and I want it to update the display (ideally) every time the database receives a new record. I can easily fill the dataset no problem. I have also tried to use the tableAdapter.FIll() function, but iterating over this doesn't seem efficient and I can't get it to work.

How To Find A List Of All The Tables In The Dataset
I'm a complete n00b to MySQL. I have populated a database from a dump file containing 1700 emails. I want to write a script that will can find a list of all senders in the entire dataset, (ie, email addresses in the From: field) but dont know any of the table names in the database, as i downloaded it from a dump file.

Does anyone know how to find a list of all the tables in the dataset, or to run this query without the table names?

Sliding Window Over A Large Dataset
Given: A really big table whose contents I want to view by "lazyloading" parts of it at a time. The entire database is too big to load all at once.

Requirements:
My UI is a window that shows ten records at a time. It pages up and
down. Initialy it loads with the first ten entries. I push page down
and the next ten show up. I can back up and look at the previous ten.
Right now, I'm just shooting for readonly access.

So what SQL technology is a good fit? A cursor seems like a good fit
because it can go backwards and forwards, though I've read that there
are scalability concerns.

Updating One Table With Another
My table contains a product number field 'packCode' but some clients may have their own internal product code. I have created a table ('configurators') which contains our product code along with two columns each for clients: their product code and price, i.e.:

packCode, insight_code, insight_price

The client sends me data containing our pack code matched against their product code and price. I wish to merge their data with our price list in the configurators table. The MySQL I have used is:

update configurators
set insight_code=iCode, insight_price=iPrice
where configurators.packCode=config_insight.iPackCode;

(The columns from the client data are preceded with 'i', i.e. 'iCode', 'iPrice' and 'iPackCode')

However, when I run the query, I get the unusual error

"ERROR 1109 (42S02): Unknown table 'config_insight' in where clause"

suggesting that the table 'config_insight' does not exist, which it clearly does. Is this the correct way to merge data from one table into another? Is my SQL query valid or am I missing something?

Updating Table
I'm sure this is possible, probably with a sub-query.I want to update a record with a value from another record in the same table.

E.G.
CODEName     Val_1     Val_2    Check_col
Test1    0         0        s
Test1    10        20       M
Test2    0         0        s
Test2    20        25       M

Updating Table
I have a database table and 1 column has positive and negative values in it.

I want to update the table so that all entries in this column are positive... so all negative values like -3, -2, and -1 become 3,2 and 1 respectively in the table.

Updating Table
I have a database of books that was originally created as a flat file.
Each record has a number of fields, including the authors name. I'm
trying to convert the database to something a little more efficient.
I've created a new table (called Authors) of unique authors names and
assigned each one a unique ID. I've added a new field in the original
table (called Books) for the author's ID. Now, I need to update the
original table with the author ID from the Author's table.

Something like this:

UPDATE Books SET AuthorID = Authors.AuthorID WHERE AuthorName =
Authors.AuthorName .

Updating Table Value
update jobs set paid=true where jobid in (SELECT jobid from jobs where CreatedBYusername='roop')

after executing this query i got an ERROR:

You can't specify target table 'jobs' for update in FROM clause.....
same thing i executed in mssql....how can i do this in mysql

Updating Table
I have two tables:

table1:
id code
1
2
3 aa
4

table2:
id code2
1
2
3 xx
4 zz

I am looking for a way to update table1 with some sort of sql statement. I looked into update and joinn but I couldn't find any relevant information. The reason I don't have any success is prbably because I don't have the correct keyword.

Updating Table From File
I have a table and I need to update records in one column. There are 450 records in the table. I know I can insert records to table from file, but is there a way to update records from file?

Updating Table Privileges
Running MySQL 4.1.14 through Yahoo. When I access Privileges, I receive the following notice:

""Warning: Your privilege table structure seem to be older than this MySQL version!
Please run the script mysql_fix_privilege_tables that should be included in your MySQL server distribution to solve this problem!""

The Scripts folder does not include this file, and I do not know how to execute a fix for the above issue. Is there a way around this (i.e., uploading the mysql_fix_privilege_tables.sql script to run it, and if so, where can I obtain it?)

Updating Table With Datetime
I have a datetime field in a table and when I ran an update like so:

UPDATE myTable SET number=2 WHERE ID=50

I had the old datetime information in the table and that got
overwritten when I did the update. Now I am sure there is no way of
getting that back (yup, believe it or not I didn't do a backup) but
just a general question, should i have done the update like so:

UPDATE myTable SET number=2, mydatetimefield=mydatetimefield WHERE
ID=50

to keep the same information in the datetime field??

Updating A Mapping Table
I have a Publications table and a Themes table. There is also a mapping table for these tables as well.

When I input new records into Publications, my mapping does not get updated. When I delete, then the mapping table will get updated. (This is MySQL 4.x, so no trigger statements.)

My fear is that as I use the mapping table to display some information on a Web page, I will need to update that table "by hand" after I've entered a new record for Publications. Is there some method that I don't know of that will update my mapping table whenever I put in new records into Publications (esp. via a Web form)?

This is the setup for the mapping table: it has foreign keys on the primary key (ID) column of both Publications and Themes. That's it, nothing else in there.

Table Data Updating
I've heard that oracle will update data in a table when a specific event occurs and was curious if mySQL will do the same?
For my site I'm designing a comment section that will be attached to my news section. My database organization scheme will consist of two tables. One table that will hold all the news entries and another that holds all the comments. Thus, when browsing the news section visitors initially only access the news table, and once they click on the comments tab then they will access the comments table. Figured this was the best way to organize the data. However, I want the news table to contain the number of comments that exist for that news-section so that the count can be displayed.
My question is how can I make the news table update its data column containing the count for comments when the comments table recieves an update? Is this possible at all in mySQL? If there is a resource someone could point me in let me know, or if anyone has suggestions of a type of hack that would suffice as well

Updating Table With Reference To Another Table
I am trying to update two columns of a table (date and location) so that they are equal to the date and location of another table on a lastname join. Here's is the code I have right now:

update tblA
    set tblA.date = tblB.date, tblA.location = tblB.location
    where tblA.lastname = tblB.lastname;

I am getting a syntax error with the above code. Does anyone know how to do this?

Updating A Table Based On The Value In Another Table In Ver 3.23.54-Max
I am trying to update fields in table SOLAR_SYSTEM based on the values in RESEARCH_LEVEL table

This is a SQL that I am trying to use

UPDATE SOLAR_SYSTEM JOIN RESEARCH_LEVEL ON SOLAR_SYSTEM.USER_ID=RESEARCH_LEVEL.USER_ID SET
SOLAR_SYSTEM.CASH_METAL=SOLAR_SYSTEM.CASH_METAL+1000,
SOLAR_SYSTEM.CASH_CRISTAL=SOLAR_SYSTEM.CASH_CRISTAL+1000,
SOLAR_SYSTEM.CASH_ENERGY=SOLAR_SYSTEM.CASH_ENERGY+1000
WHERE RESEARCH_LEVEL.TYPE='M' AND RESEARCH_LEVEL.LEVEL=1;

I got error

"ERROR 1064: You have an error in your SQL syntax near 'JOIN RESEARCH_LEVEL ON SO
LAR_SYSTEM.USER_ID=RESEARCH_LEVEL.USER_ID SET
SOLAR_SY' at line 1"

I don't know what is wrong. Can I do such an update in Ver 3.23.54-Max in the first place ? IF yes, then what's wrong with my statement?

Updating A Table To Increment Values
Question, if I want to update all values in a certain column to increment by one, what statement could I use? In quasi-MySQL, this is my pseudocode:

UPDATE table SET fields=[previous_val+1] where [previous_val]>[my_val]

Or do I HAVE to run a SELECT query, increment the value, and THEN Update it?

I was just thinking there'd be an easier way.

Updating Table After Doing Multiple INSERT
I'm currently trying to do the following :

INSERT INTO sometable (userID,otherstuff) select ....blah blah ORDER BY RAND() LIMIT 10;

So I do that to get 10 random entries which works fine, however is there an easy way to then say...

For each of the 10 random userID's just inserted update another-field in another table with matching userID to the ones just inserted?

PHP + MySQL Updating All Record In Table
I need a loop that updates 2 fields of all the records in my table.
I will multiply these fields by a value passed as POST to php.
I'm having trouble with mysql_fetch_assoc and mYsql_fetch_array... How do I do this... all i have done so far is selecting the fields from the table and outputting to the browser.
How do I modify the values and update them in the right place?

Calculate A Moving Average And Updating A Table With It
I'm learning SQL and now I'm trying to update a table (koersen) with stockdata (date, ticker, open, close, volume, MA10vol).
The column MA10vol is empty and should contain the avg volume from the last ten records with the same ticker.
What I tried sofar:

SELECT @hdat:= (SELECT DISTINCT DATE_FORMAT(datum, '%Y-%m-%d') FROM koersen ORDER BY datum DESC LIMIT 0,1);
SELECT @ldat:= (SELECT DISTINCT DATE_FORMAT(datum, '%Y-%m-%d') FROM koersen ORDER BY datum DESC LIMIT 0,10);
SELECT tickerVL, AVG(totvolume) AS MA10
FROM(
    SELECT  SUM(k.volume) AS totvolume
        FROM koersen k WHERE k.datum BETWEEN @hdat AND @ldat
        GROUP BY k.tickerVL
    ) AS tijdelijk

The update part comes later. I'm now trying to make a subquery to get me the total volume of the last ten days. But I get a message that the subquery returns more then 1 row (more tickers I think).

But I want a query that updates every MA10vol for every ticker. I know I'm doiing something wrong but what?

Updating Column With Sumned Values For Each Record In Table
I have most of the query formulated, but am stuck on the portion where I need to specify which records to update. I want to update all the records in the table. How can I specify the request_id to be the same in both the select and update statement?

Here's the query I'm working on:

Code:


update enhancementrequests2 set
hardBenefitEffortSavings = (SELECT hardBenefitEffortSavings + hardBenefitLaborSavings + hardBenefitHardwareSoftwareSavings
+ hardBenefitOtherSavings AS hbTotal
FROM enhancementrequests where request_id = 1), hardBenefitLaborSavings = NULL, hardBenefitHardwareSoftwareSavings = NULL,
hardBenefitOtherSavings = NULL
where request_id = 1



In my example I have specified that request_id = 1, but I want request_id to match each row of the table in turn. I hope that makes sense.

Updating Table 2 Table
I would like to update a mysql table1 field4 where id 12 from table2 field5 where id is 14.

Updating Table Field From Another Table Field
I have a field called 'tel1' in table 'live_properties'
and I want to update a 'tel1' field in 'live_properties'

with

'phone_num' field from 'usersTBL'

MYSQL code is here but giving error any suggestions

UPDATE live_properties SET tel1 (SELECT phone_no FROM usersTBL WHERE username = live_properties.username)

Locking
I'm wondering if there is a way to lock the database (or do something
else) to execute more than one query with assurance that they are
executed exactly one after another (figure if there are several threads
and I give it a couple of queries they may mix). Thereason is that
suppose we have two tables, one with an auto_increment key, and the
other that references that key:

table order (id ... primary key auto_increment ...
table transaction(order_id, ... foreign key refences order(id) ...

Now, I do something like:

insert into order ...
id = last_insert_id()
insert into transaction(id,0,0,...

Updating A Date From Another Date In The Same Table.
I'm having trouble coming up with the correct SQL syntax to update a date field from another date field in the same table.

Both fields are DATE types.

I want to add 2 months to the date in the final_date field and update the keeplive_exp field with that total.

So if final_date has 2007-05-04, keeplive_exp needs to update to 2007-07-04.

Help In Locking Tables
I am trying to lock a table which was created in the MyISAM engine.
I use the following query:


LOCK TABLES A WRITE;
That works fine
At the end of my executing I invoke:


UNLOCK TABLES;
That also works fine

The problem is that in between those 2 queries, I am invoking another query on table B (different table) and I get the following error:


Table 'B' was not locked with LOCK TABLES. Error number 1100
Can anyone explain why I need to lock table B as well?
There are a few tables that I am accessing between the lock and unlock queries. Do I need to lock all of them?

Do I Need To Implement Locking
I have an app I have written in Delphi which will eventually have up to 30 concurrent users. Do I need to implement my own read and write locks, or does MySQL take care of this? What about commiting queries?

Locking Tables
I have a rather simple Select query that has a LEFT JOIN between two tables. I want to take the results of this query and store it in a third table.

The two joined tables are called `new data` and `fast`. The third table where the results are to be stored is called `fall outs`.

When I try this as an INSERT INTO query, I get the error message that I've exceeded the number of locks (both the `fast` table and `new data` table have 7 million rows each).

So I've used this code thanks to the help file:

SET @@AUTOCOMMIT=0;
LOCK TABLES `fall outs` WRITE, `new data` READ;
INSERT INTO `fall outs`
SELECT (insert my select statement here)
WHERE (insert my where statement here);
UNLOCK TABLES;

When I do this, I get an error message that the table `fast` was not locked, and thus I get 0 results.

How do I make `fall outs` WRITE and have both `fast` and `new data` as READ? I can't seem to find any tutorials that do this.

Locking Records?
I am using MSAccess 2000 to run against MySQL 4.0.12.  What I need to have happen is when a user pulls up a record and begins updating it, another user on another workstation cannot access that same record.

Where do I begin with this?  Is it a simple setting in the .ini file or using MySQLAdmin?

Locking Issue
I am running MySQL 4.0.20 on redhat 9.

But i frequently face a problem of that the table is being lock. i see from the process list that i am the only one trying to update the record and the rest of the connection do nothing. Below is the log file i get when i try to show the innodb status when the table is lock. Code:

Optimistic Locking?
Can anyone tell me if MySQL uses optimistic or pessimistic locking with
InnoDB tables? And can this be modified in any way?

When I use the search function on the mysql site, it only gives me
search results for MaxDB...

Locking Tables
I am trying to install a web based game and it says my tables need to be locked. So I created a new database and ran the installer file and everything installed fine except the test for lock tables it failed so the install stopped. This is run in php. I can't find anything in my database on how to lock tables.

I am running MySQL 4.0.16 on a phpMyAdmin 2.7.0-pl2

Row Locking Issue
I am running a MySQL server for a department-critical function at my company. The basic setup is a MyISAM-based MySQL 5.1 installation, with one specific table to hold the work that is to be distributed among the employees. Other tables are for user settings (based out of the client, written in C++ with a wxWindows base, using libmysql as the medium for query submission and retrieval).

Overall, the most troublesome problem yet encountered is that each query -- one to locate a workable row, the next to pull the information from that row, and the last to mark that row as touched and no longer available to others (three in total, all occurring within one connected session) -- has a very undesireable tendency to collide during the initial "locate query." When this occurs, one employee ends up with their ID in the "worked by" field, but both clients have the same information given to them.

I've read up on InnoDB, and explored some of the locking mechanisms, but even when the DB type is migrated to InnoDB, the server runs inexcusably slow (sometimes taking up to nine seconds to return a query). It's row locking features seemed to accomplish very little in the way of preventing a read from occurring on the row, though UPDATE and DELETE statements where blocked.

In the end, I am simply wondering if there is a way to force the DB to block read access to a row that has already been read by another client, and move on to the next record in the DB, while being invisible to the user (and preferrably the client application). The only solution I can derive from all of this is to actually mark the first returned work record as completed, and then (somehow) locate it after it's been marked, preventing further reads from the row based solely on the client's rules of retrieval.


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