Last week’s quiz was on Table Value Constructors in TSQL.
Table value constructors let you create a dataset on the fly. These can occasionally be useful in writing queries, but I think playing with them has another benefit: they provide a simple, lightweight framework to let you develop your ability to think in sets.
BREAK is a useful piece of control-of-flow language in SQL Server, but it only works in specific situations.
Break Questions, Answers, and Explanations 1) If you run this code in a SQL Server Management Studio session, what will appear in the Messages window? BREAK; PRINT 2; Answer:
Msg 135, Level 15, State 1, Line 6 Cannot use a BREAK statement outside the scope of a WHILE statement.
How’d people do?
RETURN is a “control of flow” language keyword in Transact-SQL. It’s very useful for managing when code does – and does NOT – get executed in procedural code, and it can also be used to communicate the status from procedural code.
But not everyone knows how to use RETURN, and learning about it can be awkward because of some quirks of SQL Server Management Studio. It is well worth taking the time to get used to it, though!