2

I am trying to query my SQL CE to retrieve database meta data - at the moment I am trying to fetch the index data using:

select * from information_schema.indexes

However this query is going to be run programatically - and needs to return the needed columns in the right order. Therefore, I have built the following select statement:

select Table_Name, Table_Schema, Index_Name, Clustered, Unique, Column_Name from information_schema.indexes

However, the words Clustered and Unique are reserved keywords and they cannot be used in a select statement. Doing so, I get the following error: There was an error parsing the query. [Token line number: 1,Token line offset: 45, 0,Token in error: Clustered,,]

I found a similar issue here (Using SQL keyword in title of table or column) but the solution does not seem to work with SQL CE (wrapping column name in back-ticks).

Any ideas how I can actually select data from keyword columns in SQL CE?

Community
  • 1
  • 1
Mike Baxter
  • 6,868
  • 17
  • 67
  • 115
  • You could also use my scriting API, then you do not have to write any SQL statements- http://exportsqlce.coeplex.com – ErikEJ Mar 13 '13 at 16:55

2 Answers2

2

That post is about doing this in MySQL. SQL Server (of which SQL CE is a derivative) uses square brackets as field identifiers, so surround the field(s) in square brackets [].

select
    Table_Name,
    Table_Schema,
    Index_Name,
    [Clustered],
    [Unique],
    Column_Name
from information_schema.indexes
squillman
  • 13,363
  • 3
  • 41
  • 60
1

Surround with square brackets:

select [Table_Name], [Table_Schema], [Index_Name], [Clustered], [Unique], [Column_Name] from [information_schema].[indexes]
dugas
  • 12,025
  • 3
  • 45
  • 51