Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««23456»»

Predict output Expand / Collapse
Author
Message
Posted Thursday, January 21, 2010 8:38 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Thursday, April 10, 2014 7:08 AM
Points: 3,448, Visits: 4,406
pg53 (1/21/2010)
Apart from that, what's going on with the transaction? ... that rollback in the middle - can you do that?

You can roll back a transaction in the middle, in the end, or even in the beginning of a batch – it's no problem with that
Post #851314
Posted Thursday, January 21, 2010 9:41 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, July 05, 2013 11:51 PM
Points: 488, Visits: 336
I too, like most others, initially felt inclined to believe none of the answers was PERFECTLY CORRECT because the text - in the middle of the answer set - was a bit misleading - mainly because everyone expected the OUTPUT to come from the select * from #temp, which could not "emit" the output displayed in the answer choices.

However, I chose the right answer because there didn't seem to be any other answer coming close. The "right answer" had all the ingredients though not exactly in the 'proper way'.

I see both sides of the argument - one asserting that "There is no correct answer" and the other inviting us to focus on the "larger picture".

My only submission is for us to be a little more considerate for the poster. Someone has spent some time and effort creating the question. Creating is not an easy business and I quite liked the frankness displayed by another poster on the forum who openly accepted he wasn't quite wired for doing such a thing. Let's be a little considerate, folks. Let's also keep in mind that even those posting the questions may not be experts at creating questions. I don't think we have folks dedicated here to proof-read questions thoroughly before the questions are printed. If we are so irked by "inappropriate/incorrect" question why don't we form a volunteer group (on a revolving basis maybe) who would do the needful.

Somebody brought GRE type questions into the picture which was again very surprising. This is a forum for learning and sharing. Let's give kudos and help make this forum a great learning experience for everyone.

If anything - pure criticism without being properly backed by a plan of action to fix the source of criticism is a sheer waste of time IMHO.

Regards
Saurabh


Saurabh Dwivedy
___________________________________________________________

My Blog: http://tinyurl.com/dwivedys

For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537

Be Happy!
Post #851381
Posted Thursday, January 21, 2010 10:39 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, July 18, 2010 7:16 AM
Points: 4, Visits: 4
Hi,

The CATCH clause in SQL server does exactly what a catch(Exception ex) in C# does. Also the ROLLBACK is perfectly valid; imagine what would happen if there was no TRY.. CATCH within the given sample code. In that case after opening a transaction, there would be a divide by zero error and this is analogous to an error in the transaction which would eventually result in it's roll back.
Post #851427
Posted Friday, January 22, 2010 1:41 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, March 27, 2014 8:16 AM
Points: 534, Visits: 282
Saurabh Dwivedy (1/21/2010)

<snip>
My only submission is for us to be a little more considerate for the poster. Someone has spent some time and effort creating the question. Creating is not an easy business and I quite liked the frankness displayed by another poster on the forum who openly accepted he wasn't quite wired for doing such a thing. Let's be a little considerate, folks. Let's also keep in mind that even those posting the questions may not be experts at creating questions.
<snip>
Regards
Saurabh


Hear hear!


Kelsey Thornton
MBCS CITP
Post #851805
Posted Friday, January 22, 2010 5:26 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, March 19, 2014 1:27 AM
Points: 2,366, Visits: 1,837
Learnt some thing . But does'nt Set ansi_warning have an impact.

"Keep Trying"
Post #851929
Posted Thursday, January 28, 2010 12:03 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, October 18, 2011 12:57 AM
Points: 213, Visits: 97
Output answer should be
1
2
4
5


why this option was not there??


Mohammad Irfan
http://matespoint.blogspot.com
http://www.irfit.com
Post #854950
Posted Thursday, January 28, 2010 8:36 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 2:28 AM
Points: 237, Visits: 121
the select only returns 1 2 4 5 .
this is an exception is not returned by the select, so actually i don't feel this is a good question.
I knew which one to choose but it's not 100% correct.
Post #855334
Posted Friday, January 29, 2010 1:23 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, April 07, 2014 3:41 PM
Points: 2,259, Visits: 5,395
Mohammad Irfan-488206 (1/28/2010)
Output answer should be
1
2
4
5


why this option was not there??

I guess u did not look up at the "Messages" tab in the Results Pane..

For those intending to get the exact answer given in the choices, run this code

set nocount on
drop table #temp
declare @i int, @j int
set @i = 1
create table #temp (id int)
while (@i<=5)
begin
begin try
begin transaction
if (@i = 3)
set @j = @i/0
insert into #temp values (@i)
print cast (@i as varchar(5))
commit transaction
end try

begin catch
rollback transaction
print 'this is an exception';
end catch

set @i = @i + 1
end

Excellent question to learn exception-catching in a loop...
Post #855847
Posted Friday, January 29, 2010 1:38 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, October 18, 2011 12:57 AM
Points: 213, Visits: 97
COldCoffee (1/29/2010)
Mohammad Irfan-488206 (1/28/2010)
Output answer should be
1
2
4
5


why this option was not there??

I guess u did not look up at the "Messages" tab in the Results Pane..

For those intending to get the exact answer given in the choices, run this code

set nocount on
drop table #temp
declare @i int, @j int
set @i = 1
create table #temp (id int)
while (@i<=5)
begin
begin try
begin transaction
if (@i = 3)
set @j = @i/0
insert into #temp values (@i)
print cast (@i as varchar(5))
commit transaction
end try

begin catch
rollback transaction
print 'this is an exception';
end catch

set @i = @i + 1
end

Excellent question to learn exception-catching in a loop...


Ok thanks, but the question was about what will be the output, not message, else you may get many messages like 1 row affected...


Mohammad Irfan
http://matespoint.blogspot.com
http://www.irfit.com
Post #855858
Posted Friday, January 29, 2010 9:43 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, February 16, 2012 12:57 AM
Points: 63, Visits: 29
Hi, This question havn't right answer.

at condition when i = 3 then exception will be occur , in that case transaction not commit and rollback in catch block, so that record will not inter in the #temp..

That why Select * from # Temp, will give the following answer...

1
2
4
5

Please Check you question and answer before post.
Post #856206
« Prev Topic | Next Topic »

Add to briefcase «««23456»»

Permissions Expand / Collapse