Ian Ringrose
Ian Ringrose

Reputation: 51897

How do I quote a reserved word in SQL so it works across all the common database systems?

Say I have a table call ‘users’ with a column ‘order’ and I wish my application code to work across all the database systems out there.

Assume that it is impractical to change the database schema. Even if the schema was change, one of the main database engine will come up with yet another reserved word, so stopping the app working when a database engine is updated.

I would rather not have to process the SQL strings to convert them into the correct form for each database.

'How to find if a column name is a reserved keyword across various databases' partly overlaps with this question.

('Syntax error due to using a reserved word as a table or column name in MySQL' is the reference question for MySQL. )

Upvotes: 0

Views: 602

Answers (1)

Ben
Ben

Reputation: 35613

You have to test on everything you are going to support, so "all the database systems out there" is not in realty an option.

To be more realistic, you can decide which DBMS you want to support, and write a subset of SQL which they are all happy with, and test them with automated tests.

For example, you might consider:

  • MySQL
  • Postgres
  • MS SQL Server
  • Oracle

I believe these all support ANSI double-quotes for quoting names, so if you quote all names all the time then you have one less thing to worry about.

Upvotes: 3

Related Questions