tags:

views:

76

answers:

3

This question is based on this answer.

What does the following sentence mean?

Finally, don't use mixed case identifiers. Do everything lowercase, so you don't have to quote them.

Does it mean that I should change the commands such as CREATE TABLE, USER_ID and NOT NULL to lowercase? - It cannot because it would be against common naming conventions.

+2  A: 

No, I think the gentleman referred to using all lowercase identifiers, e.g. table, column etc. names. This should have no impact on the commands like CREATE TABLE etc. that you use.

Marc

marc_s
+1  A: 

I have no idea why he said that. In SQL Server, at least, the case of an identifier doesn't matter. Maybe it does in other DBMS systems?

John Saunders
Some RDBMS **are** case-sensitive. MySQL MyISAM table names are case-sensitive if the underlying filesystem of the OS on which the server is running is case-sensitive. This is because there is a one-to-one mapping between the table name and the file that stores its contents on disk. This can lead to the weird situation where MySQL table names are case-sensitive on Unix systems but not on Windows systems!
Ken Keenan
@Ken: Thank you for your comment!
Masi
Thanks, Ken, that clarifies it.
John Saunders
Case sensitivity in MS SQL Server depends on collation. I have never worked with a database that had a case sensitive collation, but according to the documentation, the identifiers would be case sensitive if the collation for the database is case sensitive. Another example, in Oracle unquoted identifiers are forced to upper case, quoted identifiers are matched as is, and are case sensitive.
Shannon Severance
Can you post where it says that in the documentation? I find it hard to believe identifiers case sensitivity changes based on collation.
John Saunders
+3  A: 

In PostgreSQL, an unquoted identifier is converted into lowercase:

CREATE TABLE "MYTABLE" (id INT NOT NULL);

CREATE TABLE "mytable" (id INT NOT NULL);

INSERT
INTO    "MYTABLE"
VALUES  (1);

INSERT
INTO    "mytable"
VALUES  (2);

SELECT  *
FROM    mytable;

---
  2

SELECT  *
FROM    MYTABLE;

---
  2

Both queries will return 2, since they are issued against "mytable", not "MYTABLE".

To return 1 (i. e. issue a query against "MYTABLE", not "mytable"), you need to quote it:

SELECT  *
FROM    "MYTABLE";

---
  1

CREATE TABLE etc. are not identifiers, they are reserved words.

You can use them in any case you like.

Quassnoi