What's the difference between single quote and double quote in sql query


#1

Must I use double quote in this query :create table awards(id integer primary key,
recipient text not null,
award_name text default “Grammy”);?


#2

Single quotes are used to indicate the beginning and end of a string in SQL. Double quotes generally aren’t used in SQL, but that can vary from database to database.

Stick to using single quotes.

That’s the primary use anyways. You can use single quotes for a column alias—where you want the column name you reference in your application code to be something other than what the column is actually called in the database. For example: PRODUCT.id would be more readable as product_id, so you use either of the following:

SELECT PRODUCT.id AS product_id
SELECT PRODUCT.id 'product_id’
Either works in Oracle, SQL Server, MySQL … but I know some have said that the TOAD IDE seems to give some grief when using the single quotes approach.

You do have to use single quotes when the column alias includes a space character, e.g., product id, but it’s not recommended practice for a column alias to be more than one word.

From StackOverflow


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.