Translate

Wednesday, March 13, 2013

SET IMPLICIT_TRANSACTIONS ON

 

SET IMPLICIT_TRANSACTIONS ON sets the transactions to use COMMIT before a transaction is committed. Default setting is OFF and when it is set to OFF transactions will be committed automatically.

When the setting is set to on, following statements will start a  transaction implicitly.

 

ALTER TABLE CREATE DELETE DROP
FETCH GRANT INSERT OPEN
REVOKE SELECT TRUNCATE UPDATE
MERGE ALTER SERVER    

Transactions that are automatically opened as the result of this setting being ON must be explicitly committed or rolled back by the user at the end of the transaction. Otherwise, the transaction and all of the data changes it contains are rolled back when the user disconnects. After a transaction is committed, executing one of the statements above starts a new transaction.

SET IMPLICIT_TRANSACTIONS ON

INSERT INTO
Emp
(Name,AddressI,City)
VALUES
('Name','Add','C1')

SELECT @@TRANCOUNT

Output of this is 1 which mean there is one transaction is open which was created by setting IMPLICIT_TRANSACTIONS to ON.


Above transaction has to be finished with COMMIT or ROLLBACK.


You can monitor the trancount from perfmon as well.


image


 


User Option Setting


You have a setting for implicit transaction in the server properties in connection page as shown below.


image


This setting is for dblib network library connections and this setting has no effect on ODBC or OLEDB connections.


Also, you can set the above setting by running following script.


EXEC sys.sp_configure N'user options', N'2'
GO
RECONFIGURE WITH OVERRIDE
GO

You are not able to set this if you have contained databases in the Server.


Msg 12830, Level 16, State 1, Procedure sp_configure, Line 166
The sp_configure 'user options' setting must be zero if the Database Engine has contained databases.


However, you can set SET IMPLICIT_TRANSACTIONS ON inside a contained databases without any issues.

Using Filtered Indexes to Improve Performance

Filtered indexes were introduced with SQL Server 2008 and this article describes about features and usages of filtered indexes.

Monday, March 11, 2013

SET Statements

T-SQL programming language behavior will change  with the SET statement you are specifying. There are around 40 SET statements during next blog post, I will be discussing about those settings in coming posts.

Saturday, March 9, 2013

Collation Conflict - 3

I posted a blog post about Collation Conflict some time back. With the discussions on Temp tables and table variables we realized that we have an option with table variable as work around for the above problem.

However, we have much cleaner option in SQL Server 2012 by using contained database option.

Let us create the Contained database.

CREATE DATABASE [Danish]
CONTAINMENT
= PARTIAL
COLLATE Danish_Norwegian_CI_AS
GO


Then let me run the previous script which failed in standard databases.


USE Danish
GO

CREATE TABLE
Table1
(IDINT IDENTITY,
NameVARCHAR(50)
)

INSERT INTOTable1
(NAME)
VALUES
('A'),
(
'B'),
(
'C')

CREATE TABLE#Temp1
(MaxIDNAME VARCHAR(50)
)

INSERT INTO#Temp1
SELECTMAX(Name)FROMTABLE1

SELECT*FROMTABLE1
WHERENAMEIN
(
SELECTMAxIDNAME from#Temp1)


This time we don’t have any errors.


image


Actually, temp table  is created in the tempdb but will not have an issue as in the standard databases.

Friday, March 8, 2013

PASS Virtual Chapter : Video is Available

Date: January 23, 2013

Topic: Resource Governor

Presenter: Dinesh Asanka

Abstract:

Resource Governor is a new technology introduced in SQL Server 2008 that enables you to manage SQL Server workload and resources by specifying limits on resource consumption by incoming requests.

View: ResourceGovenor_01232013.wmv

http://dba.sqlpass.org/MeetingArchive.aspx

Thursday, March 7, 2013

Filtered Indexes with FORCE SEEK

If you closely analyzed the below query, you will see that there is a non-clustered filtered index on ScrapReasonID column and filter condition is ScrapReasonID = 17 . In the query, there is a force seek with the above index but the where condition is 30. So, you can see there is an contradiction between index and query filter condition.

image

So what do you think about the output of the above query.

You will think that index hint will be ignored.However, this is the output for the above query.

Msg 8622, Level 16, State 1, Line 2
Query processor could not produce a query plan because of the hints defined in this query.
Resubmit the query without specifying any hints and without using SET FORCEPLAN.

Tuesday, March 5, 2013

IEEE ICCSE 2013

I will be presenting at IEEE ICCSE 2013 in Data mining category. I will update more information when I get them.

image

Wednesday, February 27, 2013

Nuo DB

NuoDB is the world’s first and only patented, elastically-scalable, SQL database built for decentralized computing resources. We started with a blank slate to design a brand new kind of database that has all of the features you want (like elastic scalability on the cloud with 100% ACID guarantees and SQL compliance) – and none of the things you don’t (like complex database administration tasks involving sharding, caching clustering and performance tuning).

image

The result is a brand new kind of database that’s optimized to run and scale on the cloud. Built for you, modernized in the new age.

Download the free version of NuoDB Pro today and see what the industry’s only high-performance, emergent database can do for your app!

  • 100% SQL compliance
  • 100% ACID
  • 100% free forever
  • Performance equal to or better than open source solutions like MySQL
  • Deploy in the cloud or on-premises
  • Supports Windows, MacOS, Linux, Solaris, and Joyent SmartOS
  • ODBC, JDBC, JRuby ActiveRecord, PHP/PDO, and Hibernate drivers
  • Simple, easy to use, zero admin

February 2013 - Happenings

Just a little update on the meet-up from last week. We hosted three sessions and had a very high participation of 63. Here are a few links you would find interesting:

Summary of the meet-up | Gallery | Slide decks and sample code downloads

Tuesday, February 26, 2013

Corrupted Log File

I received a call from one of my friends saying that he is unable to access his database which is said to be one of the most critical database in the organization.

When he tried to access the database he is getting following error message.

Database ‘ABCD’ cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server errorlog for details.

When I asked few question it seems like his log drive was filled to it’s 100% and log got corrupted. Since he didn’t’ have any recent backups , I was little reluctant to delete the log fill and attached the data file. I kept that option as my last resort.

So I asked him to run following statements.

SELECT name,state,state_desc FROM sys.databases 
WHERE  name='ABCD' 

Output for state_desc was RECOVERY_PENDING.

I instructed him to set database to the emergency mode.

ALTER DATABASE ABCD SET EMERGENCY 

Then, set the database to single use mode and started the rollback.

ALTER DATABASE ABCD SET SINGLE_USER 
WITH ROLLBACK IMMEDIATE

Then rebuilt the log by ,

DBCC CHECKDB('ABCD',REPAIR_ALLOW_DATA_LOSS)


Then executed the initial statement and verified that database is ONLINE.


Below execution is to make that every use can log into the database.

ALTER DATABASE ABCD SET MULTI_USER

With this, users were able to login to the database without any issues.