473,662 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select and Update of records without being used by other users?

Hi All,

I need to change a column value in several thousand records in a table
and output a list of the record ids of the records I've updated into
another table.

The table, however, is being used by other users via a website, so I
need to make certain that website requests don't touch on the records
I'm selecting / updating.

My attempt at a stored procedure goes thus:

CREATE proc dbo.stp_mw_tag_ irecords
AS
BEGIN TRANSACTION

INSERT INTO tbl_tagged (recid)
select top 100000 recid
FROM tbl_active with(UPDLOCK)
WHERE rectype='a'
and used=0

UPDATE tbl_active set used = 1 where recid in (select recid from
tbl_tagged)

COMMIT TRANSACTION

As near as I can tell, I'll end up with a table with 100000 records in
it, comprising the record id of each of the records that meet my
criteria, and the source records will now be tagged as used (ie used =
1).

I'm wondering if anyone can tell me if there's a more efficient way of
achieving this result, in terms of load on the server?

Any help much appreciated!

Much warmth,

Murray
Jul 20 '05 #1
2 3112
Dear M. Wells

Please see online books for DELETED, INSERTED Cursors. by using insert
into .... select ....... you may copy deleted, updated, inserted
records to other table.

Example "Select * from Deleted" or "Select * from Inserted"

I hope it will help you! Best of luck!

Me,
Saghir Taj

M Wells <pl**********@p lanetthoughtful .org> wrote in message news:<t5******* *************** **********@4ax. com>...
Hi All,

I need to change a column value in several thousand records in a table
and output a list of the record ids of the records I've updated into
another table.

The table, however, is being used by other users via a website, so I
need to make certain that website requests don't touch on the records
I'm selecting / updating.

My attempt at a stored procedure goes thus:

CREATE proc dbo.stp_mw_tag_ irecords
AS
BEGIN TRANSACTION

INSERT INTO tbl_tagged (recid)
select top 100000 recid
FROM tbl_active with(UPDLOCK)
WHERE rectype='a'
and used=0

UPDATE tbl_active set used = 1 where recid in (select recid from
tbl_tagged)

COMMIT TRANSACTION

As near as I can tell, I'll end up with a table with 100000 records in
it, comprising the record id of each of the records that meet my
criteria, and the source records will now be tagged as used (ie used =
1).

I'm wondering if anyone can tell me if there's a more efficient way of
achieving this result, in terms of load on the server?

Any help much appreciated!

Much warmth,

Murray

Jul 20 '05 #2
Hi Murray,

It might be a little faster to temporarily create an update trigger on
the table that only does anything if it's you running it that just
inserts into the table that records which records have been updated.
That way you don't have to join against your 100000 row table.

create trigger...
if system_user = 'your system user name'
Begin
insert into ... values (inserted.recid ...)
End

Then you can just update the original table as you'd like.

Bruce
M Wells <pl**********@p lanetthoughtful .org> wrote in message news:<t5******* *************** **********@4ax. com>...
Hi All,

I need to change a column value in several thousand records in a table
and output a list of the record ids of the records I've updated into
another table.

The table, however, is being used by other users via a website, so I
need to make certain that website requests don't touch on the records
I'm selecting / updating.

My attempt at a stored procedure goes thus:

CREATE proc dbo.stp_mw_tag_ irecords
AS
BEGIN TRANSACTION

INSERT INTO tbl_tagged (recid)
select top 100000 recid
FROM tbl_active with(UPDLOCK)
WHERE rectype='a'
and used=0

UPDATE tbl_active set used = 1 where recid in (select recid from
tbl_tagged)

COMMIT TRANSACTION

As near as I can tell, I'll end up with a table with 100000 records in
it, comprising the record id of each of the records that meet my
criteria, and the source records will now be tagged as used (ie used =
1).

I'm wondering if anyone can tell me if there's a more efficient way of
achieving this result, in terms of load on the server?

Any help much appreciated!

Much warmth,

Murray

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6134
by: shank | last post by:
Visually, the page will look somewhat like a spreadsheet. It could have hundreds of records (rows) displayed. I want to enable the user to edit any one or any number of records and any fields, then click a save button to UPDATE the SQL table. I'd like to use stored procedures if possible. How is this done? Where do I start? thanks
2
889
by: M Wells | last post by:
Hi All, I need to change a column value in several thousand records in a table and output a list of the record ids of the records I've updated into another table. The table, however, is being used by other users via a website, so I need to make certain that website requests don't touch on the records I'm selecting / updating.
17
5006
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by cust_no, ded_type_cd, chk_no)
1
4170
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two fields from a *single* record from a table called 'Locations' and then apply one of these field's values...
33
4280
by: Lee C. | last post by:
I'm finding this to be extremely difficult to set up. I understand that Access won't manage the primary key and the cascade updates for a table. Fine. I tried changing the PK type to number and setting default value to a UDF that manages the auto-numbering. Access won't take a UDF as a default value. Okay, I'll use SQL WITHOUT any aggregate functions, for the default value. Access won't do that either. Okay, I create a second...
6
9335
by: GSteven | last post by:
(as formerly posted to microsoft.public.access.forms with no result) I've created a continuous form which is based on a straightforward table (ex - customers - 100 records). On the form there is a checkbox with a control source named "MARK" (boolean) from customer table. I can check and uncheck individual records fine. Then I created 2 command buttons named "Select All" and "Deselect All". The Onclick property of these buttons runs code...
4
1910
by: Lada 'Ray' Lostak | last post by:
Hello there, I am thinking how to solve another typical problem of online systems with combination of thin client... Imagine simple case, 2 users are going to edit 'same' datas. Both see on the 'screen' the same, after they started edit them. First one changes datas and submit changes (sucessfully). Database (set tables - inserts/updates/deleting) was changed. At this point, datas which second user is watching are not valid anymore. They...
30
3384
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and commits it. How does the other user get the updated view without polling for changes? Is there some sort of callback mechanism that can be set up on the dataset or connection? TIA
5
2256
by: Chris Cowles | last post by:
I use an application that uses Oracle 8.1.7. All functions of the application are completed with calls to stored procedures. A data entry error occurred that caused thousands of records to be created with a consistent error in a single field. I can identify those easily records with a select statement. I'd *really* rather not have to change them all manually. I do have access to run a simple update query to correct only the field in...
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8856
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.