Solved

running a complex sql with begin tran commit tran

Posted on 2011-09-15
3
486 Views
Last Modified: 2012-05-12
I have a complex sql that has several steps to eventually update some records in a table. To identify the records it pulls some records in three temp tables (#Priority, #pi, #he) and then finds distinct common rows by joining those three temp tables into a fourth temp table #cross, then fires an update  and a delete command which looks like the code copied below, and then it uses cursors to update some columns in another table.

UPDATE OMC
		SET SCID = c.PChart,
			SCProductID = 9,
			SCHREID = c.HREID,
			ETypeID = 2,
			ChangeID = System_User,
			ChangeDate = getdate()	
		FROM dbo.OMChart OMC
		JOIN #cross c
		ON   OMC.MCID = c.HDC
		WHERE SCID is null


DELETE FROM OMChart
		WHERE MCID IN (SELECT mc.MCID
									FROM dbo.OMChart mc
									JOIN #cross c
									  ON mc.MCID = c.PChart
									WHERE  mc.SCID IS NULL)

Open in new window



My question is that will this sql that involves all these temp tables in memory and cursors run with begin tran and commit tran. I want to see how many rows are inserted in the temp tables and how many rows are updated in each step before i commit the tran.

Thanks,


0
Comment
Question by:patd1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

Expert Comment

by:jogos
ID: 36543168
temp tables can be used within begin/commit tran

How much records are affected in your last statement you can by using the @@ROWCOUNT directly after that statement. cfr http://msdn.microsoft.com/en-us/library/ms187316(v=SQL.110).aspx
0
 

Author Comment

by:patd1
ID: 36543219
Thanks jogos. How about cursors? can cursors be used with begin/commit tran.
0
 
LVL 25

Accepted Solution

by:
jogos earned 500 total points
ID: 36543424
within  a transaction mus just be vallid sql

but off-topic  try to avoid using a cursor and especialy when nested, it's slow and gets slower the more records gets into your tables
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question