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 «««1112131415

What will be the output of the following? Expand / Collapse
Author
Message
Posted Thursday, July 1, 2010 9:08 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, December 28, 2011 6:08 AM
Points: 2, Visits: 19
Create Table MyTable
(
mainkey int not null identity (-1,-1)
)
GO
insert into MyTable default values
insert into MyTable default values
insert into MyTable default values

Select * from MyTable

== > ok in that case mainkey will increase by -1 ,

it will show -1,
-1+(-1)=-2
-2 + (-1) =-3

and so on
Post #946242
Posted Thursday, July 1, 2010 10:07 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Saturday, May 24, 2014 7:58 PM
Points: 219, Visits: 824
UMG Developer (6/28/2010)
Also, if the identity increment was -1, then both option 1 and 3 would be correct, as there is no clustered index to order it, and no ORDER BY statement specified, so either -1, -2, -3 or -3, -2, -1 could be the result.


+1

Without explicit ORDER BY, there is no way we can predict the order. We could get any permutation, such as 1-,-3,-2 or -2,-1,-3 and so on.

Can you fix the incorrect multiple choice?
Post #946300
Posted Thursday, July 1, 2010 12:09 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 12:34 PM
Points: 31,181, Visits: 15,626
Added an order by to the question.






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #946386
Posted Friday, July 2, 2010 9:28 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Saturday, May 24, 2014 7:58 PM
Points: 219, Visits: 824
Thank you Steve!
Post #946933
Posted Thursday, July 15, 2010 12:49 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, June 20, 2013 4:59 AM
Points: 272, Visits: 32
Nice question. now I got clear idea on Identity(seed, increment). Thanks
Post #952881
« Prev Topic | Next Topic »

Add to briefcase «««1112131415

Permissions Expand / Collapse