SQL Server Questions and Answers – Variables

This set of SQL Server Multiple Choice Questions & Answers (MCQs) focuses on “Variables”.

1. Variables was added newly to SQL Server version _____________
a) 2005
b) 2008
c) 2012
d) 2014
View Answer

Answer: b
Explanation: Variable feature was introduced in SQL Server 2008.

2. Point out the wrong statement.
a) All the global variables represent information specific to the server or a current user session
b) SQL Server provides only three global variables
c) Global variables represent a special type of variable
d) None of the mentioned
View Answer

Answer: b
Explanation: SQL Server provides a massive number of global variables, which are very effective to use in our regular Transact-SQL.

3. Which of the following keyword is not associated with initialization of variable?
a) DECLARE
b) SET
c) SELECT
d) All of the mentioned
View Answer

Answer: d
Explanation: Variables are declared in the body of a batch or procedure with the DECLARE statement and are assigned values by using either a SET or SELECT statement.
advertisement
advertisement

4. Which of the following is a global variable?
a) @@CPU_BUSY
b) @@CPU_IO
c) @@CPU
d) @@I_BUSY
View Answer

Answer: a
Explanation: @@CPU_BUSY denotes the amount of time, in ticks, that the CPU has spent doing SQL Server work since the last time SQL Server was started.

5. Point out the right statement.
a) The server always maintain the values of local variable
b) Local variable names begin with a @@ prefix
c) T-SQL restricts the use of variables in ways that aren’t common in other development environments
d) None of the mentioned
View Answer

Answer: c
Explanation: T-SQL supports variables, as do most other development environments.

Note: Join free Sanfoundry classes at Telegram or Youtube

6. Which of the following global has return type ‘numeric’?
a) @@ERROR
b) @@MAX_CONNECTIONS
c) @@CPU_BUSY
d) @@IDENTITY
View Answer

Answer: d
Explanation: @@identity retains the last value inserted into an IDENTITY column, even if the statement that inserted it fails to commit.

7. Value of the @techonthenet variable can be changed using the SET statement, as follows __________

advertisement
DECLARE @techonthenet VARCHAR(50);

a) SET @techonthenet = ‘Example showing how to declare variable’;
b) SELECT @techonthenet = ‘Example showing how to declare variable’;
c) SET @techonthenet == ‘Example showing how to declare variable’;
d) None of the mentioned
View Answer

Answer: a
Explanation: SET keyword sets the specified local variable, previously created by using the DECLARE.
advertisement

8. _________ gives amount of time, in ticks, that SQL Server has been idle since it was last started.
a) @@ERROR
b) @@IDLE
c) @@LANGID
d) @@LANGUAGE
View Answer

Answer: b
Explanation: Return type of @@IDLE is int.

9. What will be the output of the following code?

SELECT @@IO_BUSY*@@TIMETICKS AS 'IO microseconds', 
   GETDATE() AS 'as of'

a)

 IO microseconds AS OF 
--------------- -----------------------
590       2009-08-19 22:09:44.013

b)

IO microseconds AS OF
--------------- -----------------------
5906250         2009-08-19 22:09:44.013

c)

 IO microseconds AS OF
--------------- -----------------------
59250         2009-08-19 22:09:44.013

d) None of the mentioned
View Answer

Answer: b
Explanation: @@IO_BUSY gives amount of time, in ticks, that SQL Server has spent doing input and output operations since it was last started. Return type is an integer.

10. @@LANGUAGE variable whose return type nvarchar is specified in _____________
a) sys.name
b) syslang.name
c) syslanguages.name
d) syslanguages.id
View Answer

Answer: c
Explanation: The name of the language currently in use is specified in syslanguages.name.

Sanfoundry Global Education & Learning Series – SQL Server.

To practice all areas of SQL Server, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.