tags:

views:

56

answers:

3

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"?

+3  A: 

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

Steve Syfuhs
I tested it: works for both Access and SQLServer :D :D :D
yelinna
+9  A: 

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"
Mark Byers
+1 for pointing out the differences between flavours of SQL
AdaTheDev
+1  A: 

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
....
Jeffrey L Whitledge