SQL Server Managment Studio and commit - sql-server

Suppose I had a table with a large number of records, I wanted to update all the record in that table using SQL Server managment studio 2008, I typed:
Update Table set col1 = val
It will take a while for this command to update all the records, now if I pressed stop excutioin, what exactly will happen, some records will be upodated and committed or non like I've never excuted that command?

it will be all or nothing, it is a set based operation
SQL Server uses implicit transaction if an explicit one has not been started, this is a way to ensure ACID
so to answer your question if you stop it it will be in the same state as it was before you pressed ! or F5

Related

Delphi Firedac SQL Server: no error raised when update fails because record is locked

I'm currently working on a project to migrate code base from using Advantage Database Server to SQL Server.
I'm using Firedac of XE8 linked to a Microsoft SQL Server 2014 Express.
I have a small test project. There's a TDBGrid showing the content of a table (the query lock mode is Pessimistic, lockpoint immediate).
I have another TQuery with a SQL command like this:
update myTable
set firstName = 'John'
where id = 1
What I do :
I put the first row in Edit mode (by writing something in the cell)
When I press a button, it runs executeSQL on the Update query
Nothing happens -- the update query does not go through
That's fine ... but I was expecting an error message telling me the UPDATE didn't go trough...
How can I get the same behavior but with an error message triggered ?
Essential connection settings to work with row locks :
TFDConnection.UpdateOptions.Lockmode := lmPessimistic;
TFDConnection.UpdateOptions.LockPoint := lmImmediate;
TFDConnection.UpdateOptions.LockWait := False;
Behaviour described is SQL Server waiting for the lock to be removed to finish commiting the UPDATE. By setting your FireDACconnection to 'no wait' it's going to raise an exception as soon as you attempt to do something on the row you've locked by putting the dataset in Edit. Then you can catch this exception to do what you want.

SQL Server 2008: Is it possible to view current modifications to database?

Consider the following scenario: programA opened transaction, did UPDATE.
Transaction is not yet commited.
Is it possible from SQL Server Management Studio to see what is being changed because of this transaction?
So for example if programA did
UPDATE Customers
SET ContactName = 'Alfred Schmidt', City='Hamburg'
WHERE CustomerName = 'Alfreds Futterkiste';`
then ideally I want to see that it is because of program A's current transaction dirty read returns Hamburg. Ideally I want to get something like
|SPID |Column |OldValue |NewValue
----------------+-----------+-----------------+---------
|<programA spid>|City |OldHamburg |Hamburg
|<programA spid>|ContactName|OldAlfred Schmidt|Alfred Schmidt
Or at least I want to know if the record where CustomerName='Alfreds Futterkiste'; is being changed and reading it returns dirty data.

"The column cannot be modified because it is an identity, rowversion or a system column" - but it isn't

I am getting this error:
The column cannot be modified because it is an identity, rowversion or
a system column. [Column name = BatchClosed]
But [BatchClosed] is a nullable bit column and identity is false.
I am using Sql Server Compact Edition and the table is used in merge replication.
There are system columns ( _sysIG, _sysCG, _sysCD, _sysP1, _sysMC, _sysMCS, _sysSR) and a rowguid for the purpose of replication in the table.
The table is not marked as download-only in the publication.
The table is filtered though, and the BatchClosed field is used as a part of that filter:
WHERE surveyorid = convert(int, HOST_NAME()) AND BatchClosed = 0
When I test it in Management Studio connected to the Sql Server CE database with this sql I get the same error
UPDATE tblBatch SET BatchClosed = 0 WHERE BatchClosed = 1 AND SurveyID = 160;
Interestingly, this sql would not actually do an update because there are no records with BatchClosed = 1. (I assume that's just something to do with the way Sql Server CE works)
NB the test sql will work in Sql Server 2008 R2 but not on the Sql Server CE version after synchronization
EDIT
If I try to update any column in that table I get the same error message - as if all columns are system columns, not just the one in the filter
EDIT 2
I checked my installation and noted that the server tools had an older installation date while the x64 version was at SP1:
So I un-installed the x64 components, then downloaded and installed the server tools. It now looks like this:
I immediately lost my web synchronization. It took me a painful day of working through various dead ends before I found out how to get that back. (Solution here: Configuring Web Synchronization for Merge Replication to Sql Server CE)
Result? Still get the same error. :-(
I can both delete and insert in the table in question, and also update like this:
-- Script Date: 05-07-2014 09:26 - ErikEJ.SqlCeScripting version 3.5.2.39
UPDATE [tblBatch]
SET [SamplePercentage] = 0
WHERE BatchId = 2;
GO
I think you cannot update any other columns, as they are either system controlled (PK or rowguid) or participate in join filters in the publication. But to do updates, you can do a DELETE followed by an INSERT.

SQL Server timeout on specific record

I have this query:
UPDATE Table SET Field = #value WHERE id = #id
id is the primary key.
When I execute this query against an arbitrary record, it works fine and returns almost imediately. But when I execute it against id 178413 specifically it runs forever, until a timeout is triggered.
No queries should be locking this record for more than a few milliseconds.
The server runs SQL Server 2012.
What can be happening?
I found the problem.
Apparently one of the clients has crashed and kept the database connection open, probably in the middle of a transaction.
As soon as I restarted the faulty program, the record become updatable again.

SQL Server 2008 Express (shared hosting) Times Out When Changing Data Type on Field

I'm changing some bad design on a table. The field I'm trying to change holds IIS7 session id's which are long numbers. I'm trying to change the field from nvarchar(20) to int. There are 349,000 records in the table.
SQL Server Management Studio times out after 35 seconds. However, if I check the query timeout setting for the connection it is set at 600 seconds (and I can't change it either).
Is there another timeout setting that could be causing this problem?
Here's the error message I'm getting:
- Unable to modify table.
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
I've been able to change several other tables with no problem. Of course, they had fewer rows.
This database is on a shared hosting package at Arvixe.com. Do you think this could be part of the problem?
Can you try to run a T-SQL script instead of doing this using the visual designer?
ALTER TABLE dbo.YourTable
ALTER COLUMN YourColumn INT
Now, this will only work if all rows are truly valid INT values! Otherwise, it'll bomb out at some point....
To check if all your rows are truly valid INT, you could run this query:
SELECT * FROM dbo.YourTable
WHERE ISNUMERIC(YourColumn) = 0
This will select all rows that are not valid numerics ... if you get rows here, you have a problem...

Resources