How to use symbols in SQL column names?

Related searches

I tried to use column names with symbols like minus, dot and a few others. Oracle SQL parser doesn't except them. Like this:

select
    a.ID as Article-Number, a.Name as Name
from
    Articles a
where
    (a.ID = '3264')

And it doesn't except a.ID as 'Article-Number' (says "FROM keyword not found where expected"). Can I have symbols in column names?

You can use double quotes (") to escape aliases and column names:

select
    a.ID as "Article-Number", a.Name as "Name"
from
    Articles a
where
    (a.ID = '3264')

Can I use special characters in column name in SQL Server and C# , Because the SQL Server datatype column_name is nvarchar( 128 ). For C# , as mukesh kudi said, you should use [] brackets. For example, if you want to select the column with special character '#', the code should like this: var rows = dt. Using backticks around the column name will allow you to use special characters. Let us first create a table − mysql> create table DemoTable -> (-> `Student-Id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> `Student-Name` varchar (100), -> `Student-Age` int ->); Query OK, 0 rows affected (0.55 sec)

The issue is only with Article-Number as an alias. The alias name is perfectly fine.

SQL> select e.ename as name from emp e where rownum = 1;

NAME
----------
SMITH

SQL> select e.ename as Article-Number from emp e where rownum = 1;
select e.ename as Article-Number from emp e where rownum = 1
                         *
ERROR at line 1:
ORA-00923: FROM keyword not found where expected


SQL> select e.ename as "Article-Number" from emp e where rownum = 1;

Article-Nu
----------
SMITH

SQL>

So, double-quotation marks are required only for Article-Number as alias to escape -.

Special Characters in Column Names, Column names with special characters require special treatment. It is good practice for administrators to define column names that follow the SQL identifier rules. The underscore (_), at sign (@), or number sign (#). Certain symbols at the beginning of an identifier have special meaning in SQL Server. A regular identifier that starts with the at sign always denotes a local variable or parameter and cannot be used as the name of any other type of object.

Characters that are not allowed in table name & column name in sql , Certain symbols at the beginning of an identifier have special meaning in SQL Server. A regular identifier that starts with the at sign always� SQL Server reserves both the uppercase and lowercase versions of reserved words. Embedded spaces or special characters are not allowed. Supplementary characters are not allowed. edit. refering to NinthSense: the specs also says: Certain symbols at the beginning of an identifier have special meaning in SQL Server.

1. I guess use bracket []

Select [Name@Symbol], [#Sharp!#Column] from Your table

before this you need create by this names

2. you can use synonym for use 2 names or more than...

if you need this way in comment say.

TKU

Column Name Limitations, A name that in Microsoft Excel would use the "!" character must be enclosed in back quotes (`). The "!" character is converted to the "$" character,� Table of Symbols. The following are the literal symbols used in InterSystems SQL on InterSystems IRIS® data platform. (This list does not include symbols indicating format conventions, which are not part of the language.) There is a separate table for symbols used in ObjectScript. The name of each symbol is followed by its ASCII decimal code

How to use special characters in column names with MySQL?, Using backticks around the column name will allow you to use special characters . Let us first create a table −mysql> create table DemoTable� Get Column Names From Table Example 2. This Frequently asked Questions explains how to find the list of Column names in a Table using sys.columns.-- Query to Get Column Names From Table in SQL Server USE [SQL Tutorial] GO SELECT name FROM sys.columns WHERE OBJECT_ID = OBJECT_ID('NewCustomers') OUTPUT

Certain symbols at the beginning of an identifier have special meaning in SQL Server. A regular identifier that starts 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 that starts with a number sign denotes a temporary table or procedure.

In MS SQL Server Database, use this query to get the tables and respective column names that contains the input text: SELECT t.name AS tableName, c.name AS columnName FROM sys.tables as t INNER JOIN sys.columns AS c ON t.object_id=c.object_id WHERE c.name LIKE '%<your_search_string>%'. share.

Comments
  • Hmpf, my bad. I didn't try double quotes. I thought " and ' were just the same in Oracle and I just prefer ' because I don't have to escape them in C#.
  • name alias is fine, it doesn't need double-quotation marks.
  • @LalitKumarB I went for consistency (although you're correct, of course).
  • @LalitKumarB I'm automating stuff here so all my aliases will get double quotes. Important is that I know how to use any strings in my aliases.