473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 3100
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**********@planetthoughtful.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**********@planetthoughtful.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
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...
2
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...
17
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...
1
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...
33
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...
6
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...
4
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...
30
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.