For database abstraction, should I use column names in uppercase or lowercase?

1

I'm developing an application that will need to connect to any database. I'm using Laravel for this.

The Laravel ORM maps the fields of the database and automatically assigns my class as an attribute, but if the column is uppercase, Laravel will create the property in uppercase as well:

$ User-> name; = > $ User-> NAME;

To avoid problems with a different database, which standard should I use to name not only the columns, but also the tables in my database.

Important: I should not rely on settings in the database, as this is a setting that the application can not depend on.

    
asked by anonymous 22.07.2014 / 12:26

2 answers

0

It all depends on the taste of the team and whether or not there is a pattern in the company. Since there is no standard 100% I will give you the tips of the rules I follow, after a few years of tinkering with the database, and especially because you say you want to program for multibank.

Let's go, first of all, Oracle does not have Lower Case , it's all Upper Case . So starting this way I use the rules for all banks:

  • Tables - All in Upper Case
  • Use CamelCase
  • I do not use compound PK
  • Name of tables all in Portuguese or English, nothing to mix
  • Standard for PK, FK, CK, UK and related use:
    • Name of the XXyy table, where the XX is the type and yy a sequential number. So it's much easier to find the problem, and also if you search the benchmark constraints they come in order and organized
  • Always use single PK, even on N x N tables. This allows for a lot of simplification of FK and also the use of ORM. In addition, the joins are much easier
  • In the query, I always use select, from, and similar commands in lower case, tables in Upper Case and fields in CamelCase, making visual queries easy to understand querys

With these rules you can select this way:

select
  UsuarioID, Nome, Login
from
  USUARIO
order by
  Login

Example with join

select
  a.UsuarioID, a.Nome, a.Login, a.EmpresaID
from
  USUARIO a
  inner join EMPRESA b on b.EmpresaID = a.EmpresaID
order by
  a.Login

I hope I have helped.

    
22.07.2014 / 14:47
0

Use Upper Camel Case (or capitalizedWords) for table names and Lower Camel Case for field names.

Other approaches using underline may please you, but adopt a pattern and disclose it. See more about CamelCase .

    
22.07.2014 / 14:17