mirror of
https://github.com/sqlfluff/sqlfluff
synced 2025-12-17 19:31:32 +00:00
31 lines
1.0 KiB
SQL
31 lines
1.0 KiB
SQL
-- Test special characters in T-SQL identifiers
|
|
-- According to Microsoft spec:
|
|
-- https://learn.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers
|
|
--
|
|
-- First character: letter, underscore, @, or #
|
|
-- Subsequent characters: letters, numbers, @, $, #, underscore
|
|
|
|
-- Variables with @ prefix can have $, #, _ in subsequent positions
|
|
DECLARE @variable INT = 1;
|
|
DECLARE @$variable INT = 2;
|
|
DECLARE @#variable INT = 3;
|
|
DECLARE @_variable INT = 4;
|
|
DECLARE @var$test INT = 5;
|
|
DECLARE @var#test INT = 6;
|
|
DECLARE @var_test INT = 7;
|
|
|
|
-- Temp tables with # prefix can have @, $, _ in subsequent positions
|
|
CREATE TABLE #temp (id INT);
|
|
CREATE TABLE #$temp (id INT);
|
|
CREATE TABLE #@temp (id INT);
|
|
CREATE TABLE #_temp (id INT);
|
|
CREATE TABLE ##global (id INT);
|
|
|
|
-- Regular identifiers can have @, $, # in subsequent positions
|
|
CREATE TABLE Table$name (Column@name INT, Column#test INT, Column_test INT);
|
|
|
|
-- Using these identifiers in queries
|
|
SELECT @variable, @$variable, @#variable;
|
|
SELECT * FROM Table$name;
|
|
SELECT Column@name, Column#test FROM Table$name;
|