Chapter 10: Programmable Objects Flashcards

(4 cards)

1
Q

How do I declare a variable in SQL Server?

A

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 @.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s the difference of assing a value to a variable using SET and assining in a SELECT query context?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does do the command GO?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the statements that cannot be combined in the same batch?

A

CREATE DEFAULT, CREATE FUNCTION, CREATE PROCEDURE, CREATE RULE, CREATE SCHEMA, CREATE TRIGGER, and CREATE VIEW.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly