4 Replies - 540 Views - Last Post: 19 December 2011 - 08:13 AM Rate Topic: -----

Topic Sponsor:

#1 dameon51  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 73
  • Joined: 07-June 10

syntax style

Posted 05 December 2011 - 09:41 PM

Hey everyone. I've noticed that on some of the tools I use the produce sql code they put single quotes around table names and field names, so it would look like

select 'someField' from 'your_table'


Any idea why they add these? Just curious
Is This A Good Question/Topic? 0
  • +

Replies To: syntax style

#2 Ionut  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 327
  • View blog
  • Posts: 914
  • Joined: 17-July 10

Re: syntax style

Posted 06 December 2011 - 08:21 AM

This way you can use reserved words as table names or column names(words like select, date).
Single quotes are used in MySQl, MSSQL uses square brackets. In MSSQL, using square brackets also permits you to use space in the name of the column/table(e.g. [Column Name])
Was This Post Helpful? 2
  • +
  • -

#3 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1754
  • View blog
  • Posts: 2,688
  • Joined: 08-June 10

Re: syntax style

Posted 11 December 2011 - 03:26 AM

View PostIonut, on 06 December 2011 - 03:21 PM, said:

Single quotes are used in MySQl

Actually, that's not correct. MySQL uses back-ticks (`) for identifiers and single-quotes (') for string values.

If you use single-quotes for database or table names, you will get a syntax error. If you use single-quotes for column names, you will get the column name as the value for every row. (Reads as: "Select the following string(s) for every row in the table.")

This post has been edited by Atli: 11 December 2011 - 03:29 AM

Was This Post Helpful? 1
  • +
  • -

#4 ReekenX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 20-January 07

Re: syntax style

Posted 12 December 2011 - 12:37 PM

This is also documented in Mysql official documentation.
Was This Post Helpful? 0
  • +
  • -

#5 Ionut  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 327
  • View blog
  • Posts: 914
  • Joined: 17-July 10

Re: syntax style

Posted 19 December 2011 - 08:13 AM

Quote

MySQL uses back-ticks (`)


I always saw that character as being single quote. I thought that the form is from the font. :stupid:

This post has been edited by Ionut: 19 December 2011 - 08:14 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1