简体   繁体   中英

Strange SQL-Statement

I just found an SQL-Statement with a syntax I never seen before. And I found nothing in the internet about this syntax. Does anybody knows what [field] means?

SELECT 'Customer' AS Tablename
, [Ct_ID] AS ID
, [Ct_Name] AS Name
FROM Customer

在MS TransactSQL(又名SQL Server)中,在否则无效的字段名称(保留字,带空格的名称或其他特殊字符)周围使用方括号。

What is strange about this syntax? The square braces are used by some databases as escape characters. They are not needed here. This query returns three columns. The placement of commas at the beginning of a line is a style, which I as a human being who reads languages with commas, do not agree with.

I would write it without the escapes:

SELECT 'Customer' AS Tablename, Ct_ID AS ID, Ct_Name AS Name
FROM Customer;

It is a field... really. Optional but the way to refer a field if for example it has a space in the name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM