You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/guide-sql.asciidoc
+36-48Lines changed: 36 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,22 +10,20 @@ For general guides on dealing or avoiding SQL, preventing SQL-injection, etc. yo
10
10
Here we define naming conventions that you should follow whenever you write SQL files:
11
11
12
12
* All SQL-Keywords in UPPER CASE
13
-
* Table names in upper CamelCase (e.g. `RestaurantOrder`)
14
-
* Column names in CamelCase (e.g. `drinkState`)
15
13
* Indentation should be 2 spaces as suggested by devonfw for every format.
16
14
17
15
=== DDL
18
-
For DDLs follow these additional guidelines:
16
+
The naming conventions for database constructs (tables, columns, triggers, constraints, etc.) should be aligned with your database product and their operators.
17
+
However, when you have the freedom of choice and a modern case-sensitive database, you can simply use your code conventions also for database constructs to avoid explicitly mapping each and every property (e.g. `RestaurantTable` vs. `RESTAURANT_TABLE`).
19
18
20
-
* ID column names without underscore (e.g. `tableId`)
21
19
* Define columns and constraints inline in the statement to create the table
22
20
* Indent column types so they all start in the same text column
23
21
* Constraints should be named explicitly (to get a reasonable hint error messages) with:
24
22
** `+PK_{table}+` for primary key (name optional here as PK constraint are fundamental)
25
23
** `+FK_{table}_{property}+` for foreign keys (`+{table}+` and `+{property}+` are both on the source where the foreign key is defined)
26
24
** `+UC_{table}_{property}[_{propertyN}]*+` for unique constraints
27
25
** `+CK_{table}_{check}+` for check constraints (`+{check}+` describes the check, if it is defined on a single property it should start with the property).
28
-
* Databases have hard limitations for names (e.g. 30 characters). If you have to shorten names try to define common abbreviations in your project for according (business) terms. Especially do not just truncate the names at the limit.
26
+
* Old RDBMS had hard limitations for names (e.g. 30 characters). Please note that recent databases have overcome this very low length limitations. However, keep your names short but precise and try to define common abbreviations in your project for according (business) terms. Especially do not just truncate the names at the limit.
29
27
* If possible add comments on table and columns to help DBAs understanding your schema. This is also honored by many tools (not only DBA-tools).
30
28
31
29
Here is a brief example of a DDL:
@@ -34,62 +32,52 @@ Here is a brief example of a DDL:
34
32
CREATE SEQUENCE HIBERNATE_SEQUENCE START WITH 1000000;
* List columns with fixed length values (boolean, number, enums, etc.) before columns with free text to support alignment of multiple insert statements
72
-
* Pro Tip: Get familiar with column mode of `+notepad+++` when editing large blocks of similar insert statements.
73
-
//Updated with current example from the application
0 commit comments