kb:bestpractices:codingconventions:database
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| kb:bestpractices:codingconventions:database [2026/10/06 13:20] – joerg.hampel | kb:bestpractices:codingconventions:database [2026/10/06 13:28] (current) – joerg.hampel | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| ===== Architecture ===== | ===== Architecture ===== | ||
| - | * Wrap each query in a separate SubVI | + | * Wrap each query in a separate SubVI for reuse and documentation. |
| - | * this allows | + | * Where useful, |
| - | * add documentation | + | * Database connections are shared |
| - | * optional: | + | * Use one DB connection instance per consumer to avoid blocking. |
| - | + | ||
| - | * A DB connection is like a shared | + | |
| - | * use one db connection instance per consumer to avoid blocking | + | |
| ===== Design ===== | ===== Design ===== | ||
| - | | + | ==== Naming ==== |
| - | * id | + | |
| - | * created_on | + | |
| - | * created_by | + | * Use singular nouns for table names. |
| - | * changed_on | + | * Use descriptive names and avoid prefixes such as '' |
| - | | + | * Do not repeat the table name in field names. |
| - | | + | * Avoid SQL and DBMS reserved words. |
| - | * 0 .. disabled | + | |
| - | * 1 .. active | + | ==== Keys and Relations ==== |
| + | |||
| + | * Use '' | ||
| + | * Name foreign keys ''< | ||
| + | * Define foreign-key constraints wherever possible. | ||
| + | * Name many-to-many relationship tables after the related entities. | ||
| + | |||
| + | ==== Standard Fields ==== | ||
| + | |||
| + | Default fields where applicable: | ||
| + | |||
| + | ^ Field ^ Description ^ | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | |||
| + | Only add standard fields where they serve a purpose. | ||
| + | |||
| + | ==== Data ==== | ||
| + | |||
| + | | ||
| + | * Use appropriate native datatypes instead of formatted strings. | ||
| + | * Include units in field names where otherwise ambiguous. | ||
| + | * Use descriptive positive names for boolean fields, e.g. '' | ||
| + | * Store timestamps in a consistent timezone; prefer UTC for distributed systems. | ||
| + | * Use database constraints such as '' | ||
| + | |||
| + | ==== Queries ==== | ||
| + | |||
| + | * Always use parameterized queries for external values. | ||
| + | * Never construct SQL by concatenating external input. | ||
| + | * Explicitly select required fields instead of using '' | ||
| + | * Add indexes according to actual query and relationship requirements. | ||
| + | ==== Schema Changes ==== | ||
| + | * Keep schema changes reproducible and version controlled. | ||
| + | * Define and track the database schema version where databases can evolve after deployment. | ||
| + | * Test migrations against representative existing databases before deployment. | ||
kb/bestpractices/codingconventions/database.1791292841.txt.gz · Last modified: 2026/10/06 13:20 by joerg.hampel