Files
Masterarbeit/QuellCode/CentronERP/docs/guides/database/database-conventions.md
T
Christoph Schwörer f045b99a25 Codebasis als Dateien ins Arbeitsrepo statt als Gitlink
QuellCode/CentronERP war nur als Gitlink (Submodul-Referenz auf 79c1142)
getrackt, ohne .gitmodules und ohne erreichbares Remote. Der
Untersuchungsgegenstand der Versuchsreihe war damit nicht reproduzierbar
gesichert: Ein Klon haette ein leeres Verzeichnis erhalten, und die Belege
der 3.287 Anforderungen waeren nicht ueberpruefbar gewesen.

Umstellung:
- Historie nach c:\DEV\CentronERP_git_snapshot_79c1142 ausgelagert
  (vollstaendig lesbar, enthaelt 79c1142 und Vorgaenger 89ccfd6)
- Gitlink aus dem Index entfernt
- Dateiinhalt aufgenommen: 24.557 Dateien, rund 333 MB

Die verschachtelte .gitignore der Codebasis gilt weiter, Build-Artefakte
bleiben ausgeschlossen. Details in Versuche/Versuch_01/_Codebasis-Nachweis.md
2026-08-26 07:43:51 +02:00

4.5 KiB

Centron SQL Server Database Conventions

This document outlines the standardized conventions for SQL Server database tables in the Centron system. These conventions ensure consistency across the database schema and enable efficient data management.

1. Table Structure

Schema Convention

  • All database objects must be created in the dbo schema
  • Always reference tables and other objects using the [dbo] schema prefix
  • Example: [dbo].[TableName]

Primary Key Convention

Every table must include:

  • A primary key column named I3D (ID 3develop)
  • Defined as int IDENTITY(1,1) NOT NULL
  • Configured as a clustered primary key index

Example:

CREATE TABLE [dbo].[TableName](
    [I3D] [int] IDENTITY(1,1) NOT NULL,
    -- other columns
    CONSTRAINT [PK_TableName] PRIMARY KEY CLUSTERED 
    (
        [I3D] ASC
    )
)

Foreign Key Convention

  • Foreign key columns must end with the suffix I3D
  • The prefix before I3D identifies the referenced table
  • Example: AccountI3D references the Account table's I3D column

2. Standard Tracking Columns

Creation Tracking

Include in all tables:

  • CreatedByI3D [int] NOT NULL - References the Personal.I3D of the user who created the record
  • CreatedDate [datetime2(2)] NOT NULL - Timestamp when the record was created

Modification Tracking

Include in all tables:

  • ChangedByI3D [int] NOT NULL - References the Personal.I3D of the user who last modified the record
  • ChangedDate [datetime2(2)] NOT NULL - Timestamp when the record was last modified

Deletion Tracking

Implement soft delete pattern with:

  • IsDeleted [bit] NOT NULL - Flag indicating if the record is deleted (true) or active (false)
  • DeletedByI3D [int] NULL - References the Personal.I3D of the user who deleted the record
  • DeletedDate [datetime2(2)] NULL - Timestamp when the record was deleted

3. Data Types

Text Fields

  • Use nvarchar instead of varchar to support Unicode characters
  • Specify appropriate length limits:
    • Short names/codes: nvarchar(60) to nvarchar(256)
    • Medium text: nvarchar(512) to nvarchar(2000)
    • Long text/descriptions: nvarchar(max)

Date and Time

  • Use datetime2(2) for standard date/time fields
  • Use datetime2(0) for date/time fields without milliseconds

Boolean Values

  • Use bit data type for boolean values

4. Naming Conventions

Language Considerations

  • Historical tables and columns may use German names
  • All new tables and columns must use English names
  • Do not rename existing German table/column names to maintain compatibility

Table Naming

  • Use PascalCase for table names
  • Use plural form for entity collection tables (e.g., Accounts, Employees)
  • Use singular form for lookup tables (e.g., Status, Category)

Parent-Child Relationships

  • Name child tables to reflect their relationship to the parent
  • Example: AccountDevices and AccountDeviceUris

5. Indexing Guidelines

Clustered Indexes

  • Each table must have exactly one clustered index on the primary key (I3D)

Non-Clustered Indexes

  • Create non-clustered indexes on foreign key columns and frequently queried columns
  • Follow naming pattern: IX_TableName_Column1_Column2
  • Example:
    CREATE NONCLUSTERED INDEX [IX_AccountDevices_AccountI3D] ON [dbo].[AccountDevices]([AccountI3D] ASC)
    

6. Example Tables

Parent Table Example

CREATE TABLE [dbo].[AccountDevices](
    [I3D] [int] IDENTITY(1,1) NOT NULL,
    [AccountI3D] [int] NOT NULL,
    [ShortName] [nvarchar](256) NOT NULL,
    [DescriptionRTF] [nvarchar](max) NULL,
    [Description] [nvarchar](max) NOT NULL,
    [DeviceId] [nvarchar](256) NULL,
    [WarrantyExpiryDate] [datetime2](0) NULL,
    [CreatedDate] [datetime2](2) NOT NULL,
    [CreatedByI3D] [int] NOT NULL,
    [ChangedDate] [datetime2](2) NOT NULL,
    [ChangedByI3D] [int] NOT NULL,
    [SerialNumber] [nvarchar](60) NULL,
    [Model] [nvarchar](512) NOT NULL,
    [Manufacturer] [nvarchar](255) NOT NULL,
    [Location] [nvarchar](255) NOT NULL,
    [IsDeleted] [bit] NOT NULL,
    [DeletedDate] [datetime2](2) NULL,
    [DeletedByI3D] [int] NULL,
    [OriginKind] [int] NOT NULL,
    [BranchI3D] [int] NOT NULL,
 CONSTRAINT [PK_AccountDevices] PRIMARY KEY CLUSTERED 
(
    [I3D] ASC
)
)

Child Table Example

CREATE TABLE [dbo].[AccountDeviceUris](
    [I3D] [int] IDENTITY(1,1) NOT NULL,
    [AccountDeviceI3D] [int] NOT NULL,
    [Kind] [int] NOT NULL,
    [Uri] [nvarchar](2000) NOT NULL,
 CONSTRAINT [PK_AccountDeviceUris] PRIMARY KEY CLUSTERED 
(
    [I3D] ASC
)
)