In Transact-SQL (T-SQL) for Microsoft SQL Server, do parameters and variables begin with the percent sign (%) rather than the at sign (@)?

Difficulty: Easy

Correct Answer: Incorrect

Explanation:


Introduction / Context:
T-SQL has consistent identifier conventions for variables and parameters. Recognizing these is fundamental to writing correct stored procedures, functions, and scripts in SQL Server.


Given Data / Assumptions:

  • We are using Microsoft SQL Server’s T-SQL dialect.
  • We consider local variables, procedure/function parameters, and system functions.
  • No vendor-specific non-SQL Server syntax is mixed in.


Concept / Approach:
In T-SQL, both local variables and parameters are prefixed with the at sign (@). The percent sign (%) is used in pattern matching with LIKE and modulo arithmetic, not for variable/parameter names. System global variables do not exist; instead, SQL Server exposes system functions and metadata (e.g., @@VERSION is a function-like global).


Step-by-Step Solution:
Declare a local variable: DECLARE @i int = 5;Use a parameter in a stored procedure: CREATE PROC dbo.p @id int AS SELECT @id;Observe that both use @, not %.Use % for LIKE patterns (e.g., WHERE col LIKE @p + \'%\') or modulo (e.g., 7 % 3).


Verification / Alternative check:
Attempting to declare %i int will fail with a syntax error. Documentation and SSMS IntelliSense both show @ for variables and parameters.


Why Other Options Are Wrong:
Settings like ANSI_NULLS do not change identifier syntax. “Variables use @@” is incorrect; @@ introduces built-in global functions, not user variables. Splitting conventions between variables and parameters is false; both use @.


Common Pitfalls:
Confusing % in LIKE patterns with variable prefixes; conflating @@VERSION (a system function) with user variables.


Final Answer:
Incorrect

More Questions from SQL Server 2000

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion