Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Table Variables


Table Variables

Author
Message
DugyC
DugyC
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1324 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 :-D


...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"
Hugo Kornelis
Hugo Kornelis
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8343 Visits: 11587
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
Stewart "Arturius" Campbell
Stewart "Arturius" Campbell
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5826 Visits: 7142
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”
Jamsheer
Jamsheer
Say Hey Kid
Say Hey Kid (665 reputation)Say Hey Kid (665 reputation)Say Hey Kid (665 reputation)Say Hey Kid (665 reputation)Say Hey Kid (665 reputation)Say Hey Kid (665 reputation)Say Hey Kid (665 reputation)Say Hey Kid (665 reputation)

Group: General Forum Members
Points: 665 Visits: 237
Very very Good Question... :p

Got 1 out of 6 is correct ;(
TomThomson
TomThomson
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10769 Visits: 12019
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

TomThomson
TomThomson
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10769 Visits: 12019
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

Rich Mechaber
Rich Mechaber
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1089 Visits: 3661
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.
Kick6Tiger
Kick6Tiger
SSChasing Mays
SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)SSChasing Mays (641 reputation)

Group: General Forum Members
Points: 641 Visits: 761
Excellent question. This took some time to research because I rarely use table variables.

Aigle de Guerre!
patrickmcginnis59
patrickmcginnis59
SSC-Addicted
SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)

Group: General Forum Members
Points: 431 Visits: 2333
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.
Dan Graveen
Dan Graveen
Old Hand
Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)Old Hand (375 reputation)

Group: General Forum Members
Points: 375 Visits: 69
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. w00t
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search