1
0
Fork 0
mirror of https://github.com/treffynnon/sqlstyle.guide.git synced 2025-03-09 12:49:51 -05:00

Adding Translations

- Defining constraints
- Designs to avoid
- Appendix
This commit is contained in:
Unknown 2017-04-17 16:06:23 -03:00
parent 88491fedd0
commit 49822430ea

View file

@ -372,45 +372,47 @@ Tratam-se de atos de equilíbrio a serem efetuados na definição de um banco de
dados. Se os requisitos evoluírem no futuro, é possível fazer alterações nas dados. Se os requisitos evoluírem no futuro, é possível fazer alterações nas
definições para mantê-las atualizadas. definições para mantê-las atualizadas.
#### Defining constraints #### Definindo constraints
Once the keys are decided it is possible to define them in the system using Uma vez que as keys foram decididas, é possível definí-las no sistema
constraints along with field value validation. utilizando constraints juntamente com validação do valor do campo.
##### General ##### Geral
* Tables must have at least one key to be complete and useful. * Tabelas precisam ter pelo menos uma key para ser completa e utilizável.
* Constraints should be given a custom name excepting `UNIQUE`, `PRIMARY KEY` * Constraints devem ter um nome personalizado exceto `UNIQUE`, `PRIMARY KEY`
and `FOREIGN KEY` where the database vendor will generally supply sufficiently e `FOREIGN KEY`, onde o fornecedor do banco de dados comumente gera nomes
intelligible names automatically. iteligíveis automaticamente.
##### Layout and order ##### Layout e ordenação
* Specify the primary key first right after the `CREATE TABLE` statement. * Especifique a primary key primeiro, logo após a declaração `CREATE TABLE`.
* Constraints should be defined directly beneath the column they correspond to. * Constraints devem ser definidas diretamente abaixo da coluna correspondente.
Indent the constraint so that it aligns to the right of the column name. Indente a constraint alinhada à direita do nome da coluna.
* If it is a multi-column constraint then consider putting it as close to both * Se é uma constraint que se refere a múltiplas colunas, considere colocá-la
column definitions as possible and where this is difficult as a last resort o mais próximo possível a definição das colunas. Se for complicado fazer isso,
include them at the end of the `CREATE TABLE` definition. como último recurso as inclua no fim da declaração `CREATE TABLE`.
* If it is a table level constraint that applies to the entire table then it * Se for uma constraint que se aplica a toda a tabela, ela também deve aparecer
should also appear at the end. no fim.
* Use alphabetical order where `ON DELETE` comes before `ON UPDATE`. * Utilize ordem alfabética, onde `ON DELETE` vem antes de `ON UPDATE`.
* If it make senses to do so align each aspect of the query on the same character * Se fizer sentido, alinhe cada aspecto da query na mesma posição de caracteres.
position. For example all `NOT NULL` definitions could start at the same Por exemplo, todas as definições `NOT NULL` poderiam começar na mesma posição
character position. This is not hard and fast, but it certainly makes the code de caracteres. Isso não é difícil nem rápido, mas certamente torna o código
much easier to scan and read. muito mais fácil de se examinar e ler.
##### Validation ##### Validação
* Use `LIKE` and `SIMILAR TO` constraints to ensure the integrity of strings * Utilize as constraints `LIKE` e `SIMILAR TO` para garantir a integridade de
where the format is known. strings de formato é conhecido.
* Where the ultimate range of a numerical value is known it must be written as a * Onde a extensão final de um valor numérico é conhecido, é sabido que deve-se
range `CHECK()` to prevent incorrect values entering the database or the silent escrever como uma extensão `CHECK()` para evitar que valores incorretos entrem
truncation of data too large to fit the column definition. In the least it no banco de dados, ou que o truncamento silencioso dos dados seja muito grande
should check that the value is greater than zero in most cases. para ajustar-se ao tamanho definido na coluna. No mínimo, deve-se verificar
* `CHECK()` constraints should be kept in separate clauses to ease debugging. na maioria dos casos se o valor é maior que zero.
* Constraints `CHECK()` devem ser mantidas em cláusulas separadas para facilitar
o debugging.
##### Example ##### Exemplo
```sql ```sql
CREATE TABLE staff ( CREATE TABLE staff (
@ -423,27 +425,27 @@ CREATE TABLE staff (
); );
``` ```
### Designs to avoid ### Designs a se evitar
* Object oriented design principles do not effectively translate to relational * Princípios de design orientado a objetos não se traduzem efetivamente aos designs
database designs—avoid this pitfall. de bancos de dados relacionais—evite essa armadilha.
* Placing the value in one column and the units in another column. The column * Colocar o valor em uma coluna e suas unidades em outra coluna. A coluna deve
should make the units self evident to prevent the requirement to combine tornar as unidades evidentes para evitar a necessidade de se combinar colunas
columns again later in the application. Use `CHECK()` to ensure valid data is novamente mais tarde na aplicação. Utilize `CHECK()` para garantir que dados
inserted into the column. válidos sejam inseridos na coluna.
* [EAV (Entity Attribute Value)][eav] tables—use a specialist product intended for * Tabelas [EAV (Entity Attribute Value)][eav]—utilize um produto especializado
handling such schema-less data instead. em para manipular esses dados sem schema.
* Splitting up data that should be in one table across many because of arbitrary * Divisão de dados que devem estar em uma tabela em muitas, por preocupações
concerns such as time-based archiving or location in a multi-national arbritárias, como arquivamento baseado em tempo ou localização em uma orgnização
organisation. Later queries must then work across multiple tables with `UNION` multinacional. As consultas posteriores devem trabalhar com múltiplas tabelas
rather than just simply querying one table. utilizando `UNION` ao invés de simplesmente consultar uma única tabela.
## Apêndice
## Appendix ### Referência de palavras-chave reservadas
### Reserved keyword reference Uma lista de palavras-chave reservadas. ANSI SQL (92, 99 and 2003),
MySQL 3 até 5.x, PostgreSQL 8.1, MS SQL Server 2000, MS ODBC e Oracle 10.2.
A list of ANSI SQL (92, 99 and 2003), MySQL 3 to 5.x, PostgreSQL 8.1, MS SQL Server 2000, MS ODBC and Oracle 10.2 reserved keywords.
```sql ```sql
A A