Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why underline is usually used in the sql table names rather than camel case [closed]

In all the applications/examples I have already seen(eg. wordpress). The column table names use underline rather than camel case. I'd like to know if there are some technical incompatibility problems or it's a convention? Is it dependent of the system platform(Linux/Windows) or the sql dialect(Mysql, postgreSQL, DB2, Oracle, ...). For example in the following table I have used camel case and I haven't already had any problems/warnings about it! If I should/must refactor my table, why should/must I do it?

Is SQL case insensitive about the table/column names? What about the dialects?

CREATE TABLE `testuser` (
  `id` bigint(20) NOT NULL,
  `user_type` varchar(8) NOT NULL,
  `username` varchar(30) DEFAULT NULL,
  `password` varchar(128) DEFAULT NULL,
  `regDate` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
like image 298
Johnny Avatar asked Jan 14 '13 11:01

Johnny


1 Answers

A bit of background information:

The (ANSI) SQL standard requires that non-quoted identifiers are stored in all uppercase in the system catalogs and that non-quoted identifiers are case-insensitive.

According to the standard the following non-quoted identifiers reference the same object (e.g. a table): FOOBAR, foobar, FooBar (and all would have been stored as FOOBAR in the system catalogs).

The following quoted identifiers reference 3 different objects: "FOOBAR", "foobar", "FooBar".

Nearly all DBMS comply at least with the requirement that non-quoted identifiers are case insensitive. Except for MySQL and SQL Server as far as I know - both can be configured to be case-sensitive even for non-quoted identifiers. I'm not sure what the default behaviour of SQL Server is though (as Damien pointed out in his comment, this depends on the collation being used for SQL Server).

MySQL is even more confusing as its behaviour depends on the combination of several configuration settings, the storage engine and the filesystem. All other DBMS I know are consistent regarding their behaviour across all platforms and installations.

PostgreSQL complies with the case-sensitivity but it folds everything to lowercase.

So given these rules, I think that the "traditional" naming convention using underscores stems from the fact that object names are stored in uppercase. The only way to get "readable" names is to separate important parts of the name with underscores.

SQL Server is even more non-standard as it is case-preserving (similar to the way NTFS under Windows works) so it does not fold the names to anything. So it does not change the case of the name when it's stored in the system catalog (but it is by default case insensitive). For that reason you will find people working in a Microsoft environment using CamelCase more often then e.g. in an Oracle environment.

like image 131
a_horse_with_no_name Avatar answered Sep 20 '22 20:09

a_horse_with_no_name