开发者

How can I use the "Select" statment from a table with a name that contains blankspaces?

开发者 https://www.devze.com 2022-12-25 07:51 出处:网络
开发者_开发技巧When using this SQL query: \"Select * from table_name\" what happens if the name of the table contains blankspaces? Is there an special SQL sintax for selecting a table with a name suc

开发者_开发技巧When using this SQL query: "Select * from table_name"

what happens if the name of the table contains blankspaces? Is there an special SQL sintax for selecting a table with a name such as "Author Code"?


It depends on which database you are using.

  • For SQL Server you can use square brackets: [My Table]
  • For MySQL you can use backticks: `My Table`
  • For Oracle you can use quotes: "My Table"


Yes, use square brackets SELECT * FROM [Author Code]


Any object in SQL can have any name. You just need to put square brackets around it. [Like this] or [^!@*@# EVEN THIS @#(*@#)] or even [SELECT].

I use this frequently in column aliases to make my reports purdy.

select
  c.first_name + ' ' + c.last_name as [Customer Name],
  o.order_number as [Order #],
  o.total_amount as [Total Amount],
  o.order_date as [Date]
from
  customer c
  order o ON o.customer_id = c.customer_id
....
0

精彩评论

暂无评论...
验证码 换一张
取 消