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:16] – joerg.hampel | kb:bestpractices:codingconventions:database [2026/10/06 13:28] (current) – joerg.hampel | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== 08 Databases ====== | ====== 08 Databases ====== | ||
| + | ===== Architecture ===== | ||
| + | * Wrap each query in a separate SubVI for reuse and documentation. | ||
| + | * Where useful, convert query results into typedef' | ||
| + | * Database connections are shared resources and should not be used in parallel. | ||
| + | * Use one DB connection instance per consumer to avoid blocking. | ||
| + | |||
| + | ===== Design ===== | ||
| + | |||
| + | ==== Naming ==== | ||
| + | |||
| + | * Use lowercase '' | ||
| + | * Use singular nouns for table names. | ||
| + | * Use descriptive names and avoid prefixes such as '' | ||
| + | * Do not repeat the table name in field names. | ||
| + | * Avoid SQL and DBMS reserved words. | ||
| + | |||
| + | ==== 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 '' | ||
| + | * 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.1791292589.txt.gz · Last modified: 2026/10/06 13:16 by joerg.hampel