Chapter 10: Programmable Objects Flashcards
(4 cards)
How do I declare a variable in SQL Server?
With the keyword DECLARE, and set the value with the the keyword SET. For example:
DECLARE @i AS INT;
SET @i = 5;
By the way, it needs to has the @.
What’s the difference of assing a value to a variable using SET and assining in a SELECT query context?
Using the SET operator, if the variable’s initialization comes from a subquery, then the subquery MUST return a single value. However, intializing
the variable with the SELECT, it doens’t fail because
it overwrites the value each time access to a row.
What does do the command GO?
The command GO is a T SQL client command, not a real T SQL Server command. This command tells to SQL Server that execute all commands above the GO command as a unit, as a batch.
What are the statements that cannot be combined in the same batch?
CREATE DEFAULT, CREATE FUNCTION, CREATE PROCEDURE, CREATE RULE, CREATE SCHEMA, CREATE TRIGGER, and CREATE VIEW.