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 ««12345»»»

Table Variables Expand / Collapse
Author
Message
Posted Friday, October 19, 2012 3:32 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, August 27, 2013 4:28 AM
Points: 1,248, Visits: 779
I got it wrong, you can have multi almost everything except rowguid (which is the only one I got right)... ah well... good question though my brain hurts


...and just in case anyone else was wondering...
http://www.scottishpoetrylibrary.org.uk/poetry/poems/cruaidh

nuair a ruigeas tu Tìr a’ Gheallaidh,
mura bi thu air t’ aire,
coinnichidh Sasannach riut is plion air,
a dh’ innse dhut gun tug Dia, bràthair athar, còir dha anns an fhearann.


...translates to...

when you reach the Promised Land,
unless you are on your toes,
a bland Englishman will meet you,
and say to you that God, his uncle, has given him a title to the land.



_____________________________________________________________________
"The difficult tasks we do immediately, the impossible takes a little longer"
Post #1374703
Posted Friday, October 19, 2012 4:39 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 12:26 PM
Points: 6,007, Visits: 8,269
Very good question overall.

Only (minor) issue - picking 6 out of 17 answer options is a task that appears daunting at first sight. The answer options were luckily well organized so that it soon becamse apparent that these were actually six different (but related) multiple choice questions. But it might have been better to create two or three seperate questions, each covering a subset of the answers.

Also: only 9% correct answers so far. With so many things to get right, I'd expect a high failure rate - but not this high!



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1374727
Posted Friday, October 19, 2012 5:51 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: Today @ 2:20 PM
Points: 3,966, Visits: 5,207
Good question, thanks Tom
very nearly stumbled on the non-clustered index option, but remembered a wee discussion with Gail in this regard...


____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
Post #1374766
Posted Friday, October 19, 2012 6:04 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, September 18, 2014 2:30 AM
Points: 595, Visits: 219
Very very Good Question... :p

Got 1 out of 6 is correct ;(
Post #1374774
Posted Friday, October 19, 2012 6:14 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:20 AM
Points: 7,696, Visits: 9,424
ako58 (10/19/2012)
Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64) Apr 2 2010 15:48:46 Copyright (c) Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 6.0 <X64> (Build 6002: Service Pack 2)

DECLARE @t TABLE (id INT IDENTITY,
id1 INT CHECK (id>id1))

Msg 8141, Level 16, State 0, Line 1
Column CHECK constraint for column 'id1' references another column, table '@t'.

Just put a comma before CHECK so that you are declaring a table constraint instead of trying to declare a column constraint that references another column.
DECLARE @t TABLE (id INT IDENTITY,
id1 INT,
CHECK (id>id1))

and you will get "Command(s) completed successfully".


Tom
Post #1374776
Posted Friday, October 19, 2012 6:29 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:20 AM
Points: 7,696, Visits: 9,424
Hugo Kornelis (10/19/2012)
Very good question overall.

Only (minor) issue - picking 6 out of 17 answer options is a task that appears daunting at first sight. The answer options were luckily well organized so that it soon becamse apparent that these were actually six different (but related) multiple choice questions. But it might have been better to create two or three seperate questions, each covering a subset of the answers.

Also: only 9% correct answers so far. With so many things to get right, I'd expect a high failure rate - but not this high!

I was expecting a pretty high failure rate (perhaps not quite as high as it has been so far), because there are a lot of myths about table variables; the myths about them being held in main store, not on disc, or not being held in tempd, and various associated rullbis have been addressed by questions from other question authors, and I thought it would be a good idea to address most of the myths about what constraints they have. Maybe it would have been better split into smaller questions, or maybe it's good to have it all in one place - I didn't actually flip a coin, but I did dither briefly before deciding to put everything in one place.


Tom
Post #1374780
Posted Friday, October 19, 2012 6:34 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Saturday, September 6, 2014 8:20 AM
Points: 686, Visits: 3,004
Nils Gustav Stråbø (10/19/2012)
Aaaaarg!!! Got it wrong because of the unclustered index options.

I know that SQL Server enforces unique constraints by creating unique indexs, but I wasn't sure if this was what the author meant.

+1

This kind of gotcha is common on QotD, and it's always a guessing game what the author intended. I say "gotcha" not b/c I think it was a deliberate attempt by Tom to mislead, but b/c of the 2 different ways in which people can interpret this.

Good question though...
Rich

Edited to add hyperlink: There's a nice write-up about table variables at this link on SSC. Although that article's intent was to compare table variables to temp tables, I find the tabular summary presented there to be handy.
Post #1374782
Posted Friday, October 19, 2012 6:37 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: Today @ 1:17 PM
Points: 526, Visits: 568
Excellent question. This took some time to research because I rarely use table variables.

Aigle de Guerre!
Post #1374785
Posted Friday, October 19, 2012 6:48 AM
SSC-Addicted

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

Group: General Forum Members
Last Login: Wednesday, January 16, 2013 4:23 PM
Points: 415, Visits: 2,333
Hugo Kornelis (10/19/2012)
Very good question overall.

Only (minor) issue - picking 6 out of 17 answer options is a task that appears daunting at first sight. The answer options were luckily well organized so that it soon becamse apparent that these were actually six different (but related) multiple choice questions. But it might have been better to create two or three seperate questions, each covering a subset of the answers.

Also: only 9% correct answers so far. With so many things to get right, I'd expect a high failure rate - but not this high!


Well I for one just picked an arbitrary line and clicked it, and I don't care to get over 4 digits worth of points here, I was interested in the discussions. I'm pretty confident that I don't know all the rules for table variables or even a nontrivial amount of facts regarding SQL server for that matter.

What this does bring up for me though is that if I'm not that interested in certification, what do I and other new DBA's do to find THE important things to know about SQL Server? For instance, while I'm sure knowing the table variable stuff would be good to know, if SQL rejected a construct I offered, I'd pretty much hit books on line and see what the rules are for this particular situation so no big deal. However I recently read that its not a good idea to resize a tempdb and this seems much more critical to know (and very unintuitive btw, if a systems coder shipped a storage system that couldn't dynamically (and correctly) manage utilization, I would have to have him fix it or find someone who could), yet this is another arbitrary bit of trivia an SQL user would NEED to know because it doesn't seem that Microsoft considers this a bug (while the programmer in me certainly does).

This is not an invite to argue, I'm just offering up an interesting perspective I've been viewing the SQL world from lately.
Post #1374788
Posted Friday, October 19, 2012 6:55 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, July 14, 2014 7:18 AM
Points: 369, Visits: 67
The index fooled me too. I was not thinking about the PK.. At least I learned more about table variables today. I use them quite often, especially if I need to use a cursor.
Post #1374799
« Prev Topic | Next Topic »

Add to briefcase ««12345»»»

Permissions Expand / Collapse