Showing posts with label transaction. Show all posts
Showing posts with label transaction. Show all posts

Monday, March 19, 2012

Can multiple updates in a transaction interfere?

I have some code like:
begin transaction
update mytable
set a = x.a
from mytable m inner join xtable x on m.id = x.id
where m.a <> x.a
update mytable
set b = x.b
from mytable m inner join xtable x on m.id = x.id
where m.b <> x.b
...
commit transaction
It runs without error, but afterwards there were a few rows where a
should have been updated and was not, and a few were b should have
been updated and was not.
I am embarrased to say I did not check to see if any of these were
obviously the same rows.
But I *thought* that the code above should work cleanly, and if it did
not it would hang or complain or something, not just misfire quietly,
if indeed it did misfire.
SQL2000 sp2, fwiw.
No, I don't have to run it quite this way, or in an overall tranaction
at all, I suppose, I just though it nice and harmless. Should it have
been?
Thanks.
Joshjxstern wrote:
> I have some code like:
> begin transaction
> update mytable
> set a = x.a
> from mytable m inner join xtable x on m.id = x.id
> where m.a <> x.a
> update mytable
> set b = x.b
> from mytable m inner join xtable x on m.id = x.id
> where m.b <> x.b
> ...
> commit transaction
>
> It runs without error, but afterwards there were a few rows where a
> should have been updated and was not, and a few were b should have
> been updated and was not.
> I am embarrased to say I did not check to see if any of these were
> obviously the same rows.
> But I *thought* that the code above should work cleanly, and if it did
> not it would hang or complain or something, not just misfire quietly,
> if indeed it did misfire.
> SQL2000 sp2, fwiw.
> No, I don't have to run it quite this way, or in an overall tranaction
> at all, I suppose, I just though it nice and harmless. Should it have
> been?
> Thanks.
> Josh
Doing these updates within a single transaction would not have allowed
some records to update but not others. A conflict in a transaction
would manifest as some sort of blocking, resulting in an error.
A "trick" that you can use to test updates like this is to not COMMIT,
but ROLLBACK. Immediately before the ROLLBACK, do a select against the
affected records to make sure the changes you expect were actually made.
Don't commit until you are sure the update is correct.
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||This is a multi-part message in MIME format.
--=_NextPart_000_0110_01C6A1F0.A88836C0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
If the code below is your actual code, then you are not verifying =successful completion of each of the UPDATE queries. It is necessary to =verify each step and execute a ROLLBACK if there is a problem. And this =code will not have an @.@.Error if there are no rows that meet the =criterai to update. If it is important to abort if no rows are found, =then this has to be modified. (In SQL 2005, there is a more robust =structured error handling capability that doesn't require the constant =checking.)
Transaction code should be more like:
BEGIN TRANSACTION
UPDATE MyTable
SET a =3D x.a
FROM MyTable m
JOIN xTable x
ON m.ID =3D x.ID
WHERE m.a <> x.a
IF @.@.Error <> 0
BEGIN
ROLLBACK TRANSACTION
RETURN
END
UPDATE MyTable
SET b =3D x.b
FROM MyTable m
JOIN xTable x
ON x.ID =3D m.ID
WHERE m.b <> x.b
IF @.@.Error <> 0
BEGIN
ROLLBACK TRANSACTION
RETURN
END
COMMIT TRANSACTION
END TRANSACTION
You may be able to revise the query to UPDATE in a single query.
-- Arnie Rowland* "To be successful, your heart must accompany your knowledge."
"jxstern" <jxstern@.wherever.com> wrote in message =news:530ua21cafjbodm71j0f7pht79luofu1p8@.4ax.com...
>I have some code like:
> > begin transaction
> > update mytable
> set a =3D x.a
> from mytable m inner join xtable x on m.id =3D x.id
> where m.a <> x.a > > update mytable
> set b =3D x.b
> from mytable m inner join xtable x on m.id =3D x.id
> where m.b <> x.b > > ...
> > commit transaction
> > > It runs without error, but afterwards there were a few rows where a
> should have been updated and was not, and a few were b should have
> been updated and was not.
> > I am embarrased to say I did not check to see if any of these were
> obviously the same rows.
> > But I *thought* that the code above should work cleanly, and if it did
> not it would hang or complain or something, not just misfire quietly,
> if indeed it did misfire.
> > SQL2000 sp2, fwiw.
> > No, I don't have to run it quite this way, or in an overall tranaction
> at all, I suppose, I just though it nice and harmless. Should it have
> been?
> > Thanks.
> > Josh
--=_NextPart_000_0110_01C6A1F0.A88836C0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

If the code below is your actual code, =then you are not verifying successful completion of each of the UPDATE queries. It is =necessary to verify each step and execute a ROLLBACK if there is a problem. And this code will not have an @.@.Error if there are no =rows that meet the criterai to update. If it is important to abort if no rows are =found, then this has to be modified. (In SQL 2005, there is a more robust =structured error handling capability that doesn't require the constant checking.)
Transaction code should be more =like:
BEGIN TRANSACTION
UPDATE =MyTable
=SET a =3D x.a
=FROM MyTable m
JOIN xTable x
&nbs=p; ON m.ID =3D x.ID
=WHERE m.a x.a
IF @.@.Error = 0
BEGIN
ROLLBACK TRANSACTION
=RETURN
END
UPDATE =MyTable
=SET b =3D x.b
=FROM MyTable m
JOIN xTable x
&nbs=p; ON x.ID =3D m.ID
=WHERE m.b x.b
IF @.@.Error = 0
BEGIN
=ROLLBACK TRANSACTION
RETURN
END
COMMIT TRANSACTION
END TRANSACTION
You may be able to revise the query to UPDATE in =a single query.
-- Arnie Rowland* "To be =successful, your heart must accompany your knowledge."
"jxstern" =wrote in message news:530ua21cafjbodm71j0f7pht79luofu1p8@.4ax.com...>I =have some code like:> > begin transaction> > update mytable> set a =3D x.a> from mytable m inner join =xtable x on m.id =3D x.id> where m.a x.a > > update mytable> set b =3D x.b> from mytable m inner join =xtable x on m.id =3D x.id> where m.b x.b > > =...> > commit transaction> > > It runs without =error, but afterwards there were a few rows where a> should have been =updated and was not, and a few were b should have> been updated and was =not.> > I am embarrased to say I did not check to see if any of these were> obviously the same rows.> > But I *thought* =that the code above should work cleanly, and if it did> not it would hang =or complain or something, not just misfire quietly,> if indeed it =did misfire.> > SQL2000 sp2, fwiw.> > No, I =don't have to run it quite this way, or in an overall tranaction> at all, I =suppose, I just though it nice and harmless. Should it have> =been?> > Thanks.> > Josh

--=_NextPart_000_0110_01C6A1F0.A88836C0--|||On Fri, 7 Jul 2006 18:10:41 -0700, "Arnie Rowland" <arnie@.1568.com>
wrote:
>If the code below is your actual code, then you are not
>verifying successful completion of each of the UPDATE queries.
Thanks you for your concern!
Actual code uses
select @.myerr = @.@.error, @.mycnt = @.@.rowcount
after each update, does test @.myerr and rollback if anything is wrong,
why else use a transaction? But that part works fine, the mystery is
why some rows seem to be missed in the completed and apparently
error-free transaction.
Josh|||On Fri, 07 Jul 2006 19:59:27 -0500, Tracy McKibben
<tracy@.realsqlguy.com> wrote:
>Doing these updates within a single transaction would not have allowed
>some records to update but not others. A conflict in a transaction
>would manifest as some sort of blocking, resulting in an error.
That's what I'd expect.
>A "trick" that you can use to test updates like this is to not COMMIT,
>but ROLLBACK. Immediately before the ROLLBACK, do a select against the
>affected records to make sure the changes you expect were actually made.
> Don't commit until you are sure the update is correct.
Oh, it's much worse than that!
:)
I actually run a pre-check report on what needs to be fixed, so I
already have a count of records that the same logic picks out as a
pure select, so if I'm running it manually, I can see right away that
the count is wrong. And when I run it as a script, I have print
statements (nicer than nocount off!) that reports the number of rows
affected by each statement, that I can compare to the pre-check. And
afterwards I run a post-check that should report zero - and doesn't.
But freakily enough, simply rerunning the same script as second time,
seemed to pick up the missed rows.
(worse yet, I actually ran the same script against three related
databases, and it worked 100% on the first two, it was only the third
database where it acted weird)
It's as if someone wrote some new rows in immediately after the update
script ran, but nobody was, and indeed the rows have create date and
modified date fields, the later kept by trigger, and they haven't been
touched in a month.
--
But I gather from both responses so far that at least I haven't
overlooked some basic kind of known interference (feature or bug) that
might allow some rows to be skipped in this kind of code structure.
Thanks for the reality checks.
Josh|||JXStern wrote:
> On Fri, 07 Jul 2006 19:59:27 -0500, Tracy McKibben
> <tracy@.realsqlguy.com> wrote:
>> Doing these updates within a single transaction would not have allowed
>> some records to update but not others. A conflict in a transaction
>> would manifest as some sort of blocking, resulting in an error.
> That's what I'd expect.
>> A "trick" that you can use to test updates like this is to not COMMIT,
>> but ROLLBACK. Immediately before the ROLLBACK, do a select against the
>> affected records to make sure the changes you expect were actually made.
>> Don't commit until you are sure the update is correct.
> Oh, it's much worse than that!
> :)
> I actually run a pre-check report on what needs to be fixed, so I
> already have a count of records that the same logic picks out as a
> pure select, so if I'm running it manually, I can see right away that
> the count is wrong. And when I run it as a script, I have print
> statements (nicer than nocount off!) that reports the number of rows
> affected by each statement, that I can compare to the pre-check. And
> afterwards I run a post-check that should report zero - and doesn't.
> But freakily enough, simply rerunning the same script as second time,
> seemed to pick up the missed rows.
> (worse yet, I actually ran the same script against three related
> databases, and it worked 100% on the first two, it was only the third
> database where it acted weird)
> It's as if someone wrote some new rows in immediately after the update
> script ran, but nobody was, and indeed the rows have create date and
> modified date fields, the later kept by trigger, and they haven't been
> touched in a month.
> --
> But I gather from both responses so far that at least I haven't
> overlooked some basic kind of known interference (feature or bug) that
> might allow some rows to be skipped in this kind of code structure.
> Thanks for the reality checks.
> Josh
>
Could you possibly have dupes that are confusing things? Just guessing...
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||jxstern wrote:
> I have some code like:
> begin transaction
> update mytable
> set a = x.a
> from mytable m inner join xtable x on m.id = x.id
> where m.a <> x.a
> update mytable
> set b = x.b
> from mytable m inner join xtable x on m.id = x.id
> where m.b <> x.b
>
Josh,
I would first of all combine these 2 updates into one:
update mytable
set a = case when m.a <> x.a then x.a else m.a end,
b = case when m.b <> x.b then x.b else m.b end
from mytable m inner join xtable x on m.id = x.id
where m.a <> x.a
This under most circumstances performs better.
Next, because you did not post DDL, I can only make a wild guess.
Suppose m.a is null and x.a = 12. Note that m.a <> x.a is FALSE, and
m.a will not get updated. If m.a and x.a are nullable, instead of m.a
<> x.a you should use:
(m.a <> x.a ) or (m.a is null and x.a is not null) or (m.a is not null
and x.a is null)|||On 8 Jul 2006 13:16:25 -0700, "Alexander Kuznetsov"
<AK_TIREDOFSPAM@.hotmail.COM> wrote:
>Josh,
>I would first of all combine these 2 updates into one:
>update mytable
> set a = case when m.a <> x.a then x.a else m.a end,
> b = case when m.b <> x.b then x.b else m.b end
> from mytable m inner join xtable x on m.id = x.id
> where m.a <> x.a
>This under most circumstances performs better.
>Next, because you did not post DDL, I can only make a wild guess.
>Suppose m.a is null and x.a = 12. Note that m.a <> x.a is FALSE, and
>m.a will not get updated. If m.a and x.a are nullable, instead of m.a
><> x.a you should use:
>(m.a <> x.a ) or (m.a is null and x.a is not null) or (m.a is not null
>and x.a is null)
The actual code is rather more complicated (!), sometimes it does
involve nulls but I take care of those properly, and there would be a
lot of tables involved in different joins for the different cases, so
I'm guessing it might not be all that much faster due to caching and
such. It's a batch process that runs only on special occassions, so
efficiency isn't the major concern, anyway. FWIW, takes about twenty
minutes on the dev box for six to ten update statements, probably run
2x faster on the production box with more processors and more RAM.
(actually, I though I should probably break up the transaction anyway
to make the script more production-friendly, now that you mention it!)
But I remain mystified by the behavior seen.
Josh|||On Sat, 08 Jul 2006 13:06:30 -0500, Tracy McKibben
<tracy@.realsqlguy.com> wrote:
>Could you possibly have dupes that are confusing things? Just guessing...
It's a thought, I know eliminate-dups scripts act like that, don't
they? The only way that would happen here is if I failed to fully
define my joins ... hey, that's something to look at on Monday,
thanks!
Josh

Sunday, March 11, 2012

Can Kill Command undo changes outwith a transaction?

In SQL 2000 I have a problem whereby it appears that a process successfully
saved data (inserts followed by updates), hung, and when I killed the proces
s
some of the data disapeared. I had understood that only declared transaction
s
would be rolled back, but in this case it appears that untransacted changes
were undone.
When I say that the process successfully saved data, the data was read from
the database in a separate program (Crystal Reports) and was printed out.
By "the data disappeared", I mean that the inserted rows are no longer in
the database, and the rows that were updated (according to the hard copy) ar
e
in a previous state. The tables involved in this have insert/update/delete
triggers that record all changes; they do not record the changes that are
involved, and have been working without fault for several months.
The updates were grouped in transactions, whereas the inserts were not.
There was no over-all transaction.
Sure, at first glance you might think it's just a transaction that did not
complete and that I'm overlooking something, however I have the print out of
the missing data to show the data was in there.
Can someone confirm or refute that my interpretation of what happened is
possible, or suggest an alternative explanation?My guess is the report was run under the Read Uncommitted isolation level
(or used NOLOCK). As such it would see the changes if run while the
transaction was in progress and they would have been rolled back when you
killed it.
Andrew J. Kelly SQL MVP
"woodk" <woodk@.discussions.microsoft.com> wrote in message
news:F6E9C8E0-BD1C-49BF-BDB8-094BFC68C964@.microsoft.com...
> In SQL 2000 I have a problem whereby it appears that a process
> successfully
> saved data (inserts followed by updates), hung, and when I killed the
> process
> some of the data disapeared. I had understood that only declared
> transactions
> would be rolled back, but in this case it appears that untransacted
> changes
> were undone.
> When I say that the process successfully saved data, the data was read
> from
> the database in a separate program (Crystal Reports) and was printed out.
> By "the data disappeared", I mean that the inserted rows are no longer in
> the database, and the rows that were updated (according to the hard copy)
> are
> in a previous state. The tables involved in this have insert/update/delete
> triggers that record all changes; they do not record the changes that are
> involved, and have been working without fault for several months.
> The updates were grouped in transactions, whereas the inserts were not.
> There was no over-all transaction.
> Sure, at first glance you might think it's just a transaction that did not
> complete and that I'm overlooking something, however I have the print out
> of
> the missing data to show the data was in there.
> Can someone confirm or refute that my interpretation of what happened is
> possible, or suggest an alternative explanation?|||Thank you for your suggestion. The operations were not wrapped in a single
transaction, and some of them should have been atomic in their own right.
However as we've found an indication that Crystal does indeed read
uncommitted, we're investigating the possibility that an earlier transaction
by that user may not have been properly committed. If this is the case, it
may be that this was also what led to the situation where I had to issue the
Kill command in the first place.
"Andrew J. Kelly" wrote:

> My guess is the report was run under the Read Uncommitted isolation level
> (or used NOLOCK). As such it would see the changes if run while the
> transaction was in progress and they would have been rolled back when you
> killed it.
> --
> Andrew J. Kelly SQL MVP

Can Incremental Backup be done with Simple recovery Model?

For SQL2000 - Just wondering if the incremental backup requires transaction
logs.
We have a database upgrade process that performs a lot of updates. In order
to keep the transaction log from growing out of control - I would like to be
able to set the recovery model as "simple". I am hoping that I could do the
following:
1. Perform a full DB backup
2. Set the recovery model to Simple
3. Run the upgrade
4. Set the recovery model back to Full
5. Run an incremental backup
Does this sound reasonable? Should steps 4 and 5 be reversed?
Thanks in advance.No, Incremental backups (which are called transaction log backups in SQL server) are based on the
transaction log. If you are missing log records in the transaction log, you wouldn't be able to
restore from the transaction log backups.
Consider differential backups, perhaps?
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"TJT" <TJT@.nospam.com> wrote in message news:OWT5nJ%23eFHA.3808@.TK2MSFTNGP14.phx.gbl...
> For SQL2000 - Just wondering if the incremental backup requires transaction
> logs.
> We have a database upgrade process that performs a lot of updates. In order
> to keep the transaction log from growing out of control - I would like to be
> able to set the recovery model as "simple". I am hoping that I could do the
> following:
> 1. Perform a full DB backup
> 2. Set the recovery model to Simple
> 3. Run the upgrade
> 4. Set the recovery model back to Full
> 5. Run an incremental backup
> Does this sound reasonable? Should steps 4 and 5 be reversed?
> Thanks in advance.
>|||"TJT" <TJT@.nospam.com> wrote in message
news:OWT5nJ#eFHA.3808@.TK2MSFTNGP14.phx.gbl...
> For SQL2000 - Just wondering if the incremental backup requires
transaction
> logs.
> We have a database upgrade process that performs a lot of updates. In
order
> to keep the transaction log from growing out of control - I would like to
be
> able to set the recovery model as "simple". I am hoping that I could do
the
> following:
> 1. Perform a full DB backup
> 2. Set the recovery model to Simple
> 3. Run the upgrade
> 4. Set the recovery model back to Full
> 5. Run an incremental backup
> Does this sound reasonable? Should steps 4 and 5 be reversed?
> Thanks in advance.
>
If this is a one-time upgrade, I would suggest the following...
1. Perform Full DB Backup
2. Set to Simple
3. Run upgrade
4. Perform Full DB Backup
5. Test your upgraded information. If all is OK
6. Set recovery back to full.
I'm not sure why you need the incrementals.
Rick Sawtell
MCT, MCSD, MCDBA|||Hi Tibor,
Actually - I really meant to ask the question about Differential backups
(and not Incremental). I just had my terminology messed up.
So - would I be able to do this for Differential backups...
1. Perform a full DB backup
2. Set the recovery model to Simple
3. Run the upgrade
4. Set the recovery model back to Full
5. Run a differential backup
Thanks!
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:u4zfMN%23eFHA.3012@.tk2msftngp13.phx.gbl...
> No, Incremental backups (which are called transaction log backups in SQL
server) are based on the
> transaction log. If you are missing log records in the transaction log,
you wouldn't be able to
> restore from the transaction log backups.
> Consider differential backups, perhaps?
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "TJT" <TJT@.nospam.com> wrote in message
news:OWT5nJ%23eFHA.3808@.TK2MSFTNGP14.phx.gbl...
> > For SQL2000 - Just wondering if the incremental backup requires
transaction
> > logs.
> >
> > We have a database upgrade process that performs a lot of updates. In
order
> > to keep the transaction log from growing out of control - I would like
to be
> > able to set the recovery model as "simple". I am hoping that I could do
the
> > following:
> > 1. Perform a full DB backup
> > 2. Set the recovery model to Simple
> > 3. Run the upgrade
> > 4. Set the recovery model back to Full
> > 5. Run an incremental backup
> >
> > Does this sound reasonable? Should steps 4 and 5 be reversed?
> >
> > Thanks in advance.
> >
> >
>|||Hi Rick,
The database is rather large (90GB) and we are trying to minimize downtime.
This is why I was hoping to perform a differential backup.
If the database were small and downtime were not a problem - I would perform
another Full backup after the upgrade as you suggest.
Thanks,
Tom
"Rick Sawtell" <r_sawtell@.hotmail.com> wrote in message
news:uvuhVO%23eFHA.1448@.TK2MSFTNGP14.phx.gbl...
> "TJT" <TJT@.nospam.com> wrote in message
> news:OWT5nJ#eFHA.3808@.TK2MSFTNGP14.phx.gbl...
> > For SQL2000 - Just wondering if the incremental backup requires
> transaction
> > logs.
> >
> > We have a database upgrade process that performs a lot of updates. In
> order
> > to keep the transaction log from growing out of control - I would like
to
> be
> > able to set the recovery model as "simple". I am hoping that I could do
> the
> > following:
> > 1. Perform a full DB backup
> > 2. Set the recovery model to Simple
> > 3. Run the upgrade
> > 4. Set the recovery model back to Full
> > 5. Run an incremental backup
> >
> > Does this sound reasonable? Should steps 4 and 5 be reversed?
> >
> > Thanks in advance.
> >
> >
> If this is a one-time upgrade, I would suggest the following...
> 1. Perform Full DB Backup
> 2. Set to Simple
> 3. Run upgrade
> 4. Perform Full DB Backup
> 5. Test your upgraded information. If all is OK
> 6. Set recovery back to full.
>
> I'm not sure why you need the incrementals.
> Rick Sawtell
> MCT, MCSD, MCDBA
>
>|||Yes, that should work. Just test on a test server that the steps are fine first (possibly with less
data volume). Also, be aware that you have now broken your chains of log backups. The log backup
taken after this will not be able to apply after a log backup taken before all this. Only from the
last db backup.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"TJT" <TJT@.nospam.com> wrote in message news:eySKSR%23eFHA.2244@.TK2MSFTNGP15.phx.gbl...
> Hi Tibor,
> Actually - I really meant to ask the question about Differential backups
> (and not Incremental). I just had my terminology messed up.
> So - would I be able to do this for Differential backups...
> 1. Perform a full DB backup
> 2. Set the recovery model to Simple
> 3. Run the upgrade
> 4. Set the recovery model back to Full
> 5. Run a differential backup
> Thanks!
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
> message news:u4zfMN%23eFHA.3012@.tk2msftngp13.phx.gbl...
>> No, Incremental backups (which are called transaction log backups in SQL
> server) are based on the
>> transaction log. If you are missing log records in the transaction log,
> you wouldn't be able to
>> restore from the transaction log backups.
>> Consider differential backups, perhaps?
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://www.solidqualitylearning.com/
>>
>> "TJT" <TJT@.nospam.com> wrote in message
> news:OWT5nJ%23eFHA.3808@.TK2MSFTNGP14.phx.gbl...
>> > For SQL2000 - Just wondering if the incremental backup requires
> transaction
>> > logs.
>> >
>> > We have a database upgrade process that performs a lot of updates. In
> order
>> > to keep the transaction log from growing out of control - I would like
> to be
>> > able to set the recovery model as "simple". I am hoping that I could do
> the
>> > following:
>> > 1. Perform a full DB backup
>> > 2. Set the recovery model to Simple
>> > 3. Run the upgrade
>> > 4. Set the recovery model back to Full
>> > 5. Run an incremental backup
>> >
>> > Does this sound reasonable? Should steps 4 and 5 be reversed?
>> >
>> > Thanks in advance.
>> >
>> >
>>
>|||I can backup 90GB in just a few minutes using no third party tools
How long is "Too Long" ?
What kind of IO subSystem do you have ? (RAID Array, SAN, NAS)
Greg Jackson
PDX, Oregon

Thursday, February 16, 2012

Can I restore just a data file (not the transaction log)

I have a 33 gig backup file that I need to restore. I think it's so
large because when the SQL 2000 database was backed up, it wasn't backed
up in a while and the transaction log was quite large. So can I restore
just the data file?
Here is some info:
When I do the RESTORE FILELIST only, I get:
RESTORE FILELISTONLY
FROM DISK = 'g:\MEIS'
MEIS_dat E:\MSSQL7\DATA\MEIS.mdf D PRIMARY 46424915968 35184372080640
MEIS_log E:\MSSQL7\DATA\MEIS.ldf L NULL 3002073088 35184372080640
You see the size of the log file is 46 gig. But the size of the data
file is 3 gig.
The syntax that I came up with (but I have not tried, because I am not
at that point yet so I wanted to find out if it will work) is:
RESTORE DATABASE MEIS
FROM DISK = 'g:\MEIS'
WITH MOVE 'MEIS_dat' TO 'D:\Program Files\Microsoft SQL
Server\MSSQL\Data\MEIS.mdf'
And just leave the line off dealing with the transaction log. So will
this restore just the data and not the transaction log?
The database was using either a Full or Simple recovery model, I am not
sure.
Thanks
-C
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Restore database just restores the database. It's only if you specify
NORECOVERY for the database restore, that you can restore additional backups
(eg log backups). If the database was using the simple recovery model, the
transaction log is automatically truncated. The log is probably so large
because SQL does shrink the file and return the empty space back to the OS
unless you issue a DBCC SHRINKFILE command on the log file. Your restore
command should work provide the device names and OS file locations are ok.
--
***********************************
Andy S.
andy_mcdba@.yahoo.com
***********************************
"Colin Colin" <ccole@.ghs.guthrie.org> wrote in message
news:e0YB8UIfDHA.2236@.TK2MSFTNGP12.phx.gbl...
> I have a 33 gig backup file that I need to restore. I think it's so
> large because when the SQL 2000 database was backed up, it wasn't backed
> up in a while and the transaction log was quite large. So can I restore
> just the data file?
> Here is some info:
> When I do the RESTORE FILELIST only, I get:
> RESTORE FILELISTONLY
> FROM DISK = 'g:\MEIS'
> MEIS_dat E:\MSSQL7\DATA\MEIS.mdf D PRIMARY 46424915968 35184372080640
> MEIS_log E:\MSSQL7\DATA\MEIS.ldf L NULL 3002073088 35184372080640
> You see the size of the log file is 46 gig. But the size of the data
> file is 3 gig.
>
> The syntax that I came up with (but I have not tried, because I am not
> at that point yet so I wanted to find out if it will work) is:
> RESTORE DATABASE MEIS
> FROM DISK = 'g:\MEIS'
> WITH MOVE 'MEIS_dat' TO 'D:\Program Files\Microsoft SQL
> Server\MSSQL\Data\MEIS.mdf'
> And just leave the line off dealing with the transaction log. So will
> this restore just the data and not the transaction log?
> The database was using either a Full or Simple recovery model, I am not
> sure.
> Thanks
> -C
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!|||RESTORE will re-create all files, with the same size as they had when you took the backup. The MOVE
option will only allow you to specify a new logical name. Not specifying MOVE mean that SQL Server
will keep the same logical name.
To shrink log, Check out below KB articles:
INF: How to Shrink the SQL Server 7.0 Transaction Log
http://support.microsoft.com/default.aspx?scid=kb;en-us;256650
INF: Shrinking the Transaction Log in SQL Server 2000 with DBCC SHRINKFILE
http://support.microsoft.com/default.aspx?scid=kb;en-us;272318
http://www.mssqlserver.com/faq/logs-shrinklog.asp
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as ugroup=microsoft.public.sqlserver
"Colin Colin" <ccole@.ghs.guthrie.org> wrote in message news:e0YB8UIfDHA.2236@.TK2MSFTNGP12.phx.gbl...
> I have a 33 gig backup file that I need to restore. I think it's so
> large because when the SQL 2000 database was backed up, it wasn't backed
> up in a while and the transaction log was quite large. So can I restore
> just the data file?
> Here is some info:
> When I do the RESTORE FILELIST only, I get:
> RESTORE FILELISTONLY
> FROM DISK = 'g:\MEIS'
> MEIS_dat E:\MSSQL7\DATA\MEIS.mdf D PRIMARY 46424915968 35184372080640
> MEIS_log E:\MSSQL7\DATA\MEIS.ldf L NULL 3002073088 35184372080640
> You see the size of the log file is 46 gig. But the size of the data
> file is 3 gig.
>
> The syntax that I came up with (but I have not tried, because I am not
> at that point yet so I wanted to find out if it will work) is:
> RESTORE DATABASE MEIS
> FROM DISK = 'g:\MEIS'
> WITH MOVE 'MEIS_dat' TO 'D:\Program Files\Microsoft SQL
> Server\MSSQL\Data\MEIS.mdf'
> And just leave the line off dealing with the transaction log. So will
> this restore just the data and not the transaction log?
> The database was using either a Full or Simple recovery model, I am not
> sure.
> Thanks
> -C
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Sunday, February 12, 2012

Can I place Lock for some time in a Transaction

Dear all,

I have a transaction performing some oeprations. Can I Lock (UPDLOCK) some table for some time in transaction and then release the lock. Basically if i place the lock on table it remains there for whole transaction duration. What to do if I want to release it explicitly in transaction?

Thanks in advance,
AvneeshI do not understand,
can you please be more specific?|||Lets take an example to be more specific about problem
--------------------
Begin tran
Lock mytab with UPDLOCK
...Do Some operation...
Release lock on mytab
...Do some operation....
Commit tran
--------------------

Is this possible?

If you have some idea then most welcome.

Thanks in advance,
Avneesh