0
0
SQLquery~5 mins

Variables and SET statements in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a variable in SQL?
A variable in SQL is a named storage that holds a value temporarily during the execution of a batch or procedure.
Click to reveal answer
beginner
How do you declare a variable in SQL?
You declare a variable using the DECLARE statement, for example: <br>DECLARE @myVar INT;
Click to reveal answer
beginner
What does the SET statement do in SQL?
The SET statement assigns a value to a variable, for example: <br>SET @myVar = 10;
Click to reveal answer
intermediate
Can you assign a value to a variable during declaration in SQL?
No, in standard SQL you declare a variable first and then assign a value using SET. Some SQL dialects allow assignment during declaration, but it's not standard.
Click to reveal answer
intermediate
What is the difference between SET and SELECT for assigning variables?
SET assigns one variable at a time and is standard. SELECT can assign multiple variables at once but may behave differently if no rows are returned.
Click to reveal answer
Which SQL statement is used to declare a variable?
ADECLARE
BSET
CSELECT
DCREATE
How do you assign the value 5 to a variable named @count?
ASET @count = 5;
BDECLARE @count = 5;
CSELECT @count = 5;
DCREATE @count = 5;
Which statement is true about SET and SELECT for variable assignment?
ASET can assign multiple variables at once.
BBoth SET and SELECT cannot assign variables.
CDECLARE assigns values to variables.
DSELECT can assign multiple variables at once.
What happens if you use SET to assign a variable but the value is missing?
AThe variable is set to NULL.
BThe variable keeps its previous value.
CAn error occurs.
DThe variable is deleted.
Which of these is a valid variable name in SQL?
AtotalAmount
B@totalAmount
C#totalAmount
D$totalAmount
Explain how to declare and assign a value to a variable in SQL using SET statements.
Think about the two-step process: first create the variable, then give it a value.
You got /4 concepts.
    Describe the difference between SET and SELECT when assigning values to variables.
    Consider how many variables each can assign and what happens if no data is returned.
    You got /4 concepts.