Validate MSSQL identifier (parameter) in .NET or regular expression

In a .NET project, I need to check if a string is a valid Microsoft SQL Server 2005 parameter identifier.

Example: SELECT * FROM table WHERE column = @parameter

Is there a runtime class method for checking a string for a parameter, or is there a regular expression that checks the rules? (see below)

From the documentation on identifiers, parameters must comply with these general identifier rules:

  • The first character must be one of the following: * The letter as defined by the Unicode 3.2 standard. Unicode definition of letters includes Latin characters from a to z, from A to Z, as well as letters characters from other languages. * Underscore (_), with a @ sign or a number sign (#).
    Certain characters at the beginning of the identifier are special values ​​in SQL Server. A regular identifier that begins with the at sign always denotes a local variable or parameter and cannot be used as the name of any other type of object. An identifier starting with a number sign indicates a temporary table or procedure. An identifier that begins with a two-digit character (##) denotes a global temporary object. Although a number sign or double number sign can be used to start the names of other types of objects, we do not recommend this practice. Some Transact-SQL functions have names that begin with a double in the signs (@@). To avoid confusion with these functions, you should not use names starting with @@.
  • : * , Unicode 3.2. * Basic . * at, ($), .
  • Transact-SQL. SQL Server .
  • .
  • .

Transact-SQL, , .

, @ .

+3
2

Unicode, , .NET, , :

@[\p{L}{\p{Nd}}$#_][\p{L}{\p{Nd}}@$#_]*

:

  • @, .
  • @ TSQL.
  • , .
+6

TSQL, VBScript,

, , , ,

@parameter sysname, ,

0

Source: https://habr.com/ru/post/1706862/


All Articles