Kelvin Barsana
Kelvin Barsana

Reputation: 864

Table column name is 'default'

I'm having a hard time querying a table which has a column name 'default', it shows an error, I can't rename it because I'm using an old system and it might affect our previous systems.

e.g.

select * from table_name where default = 1

tried this

select * from table_name where 'default' = 1

and it didn't work.

Is there a workaround on this?

Upvotes: 7

Views: 7173

Answers (2)

Xin
Xin

Reputation: 36490

For SQL Server, (Not sure if you are using other db) U can use this way:

select * 
from table_name 
where [default] = 1
or [index] = 'another example'

You can [] for any column which is build-in keyword for database.

Hope this helps u.

Upvotes: 4

Mathlight
Mathlight

Reputation: 6653

You should use backtips:

select * from table_name where `default` = 1

Upvotes: 14

Related Questions