Db Naming Conventions
Basic Rules
-
General principle: All name parts are formed using PascalCase (the first letter of each word is capitalized, written contiguously). (Id included)
-
Segmented structure: Object names consist of segments separated by
_(underscore). Each segment must be PascalCase.- Template:
[Prefix]_[Rn | RnPj]_[ModuleCode]_[ObjectName] - Example:
Tb_Rn_Inventory_Items,Sp_RnPj_Production_CreateBomCost
- Template:
-
Expressed in English: English is used in names.
-
Temporary structures: Temporary table/view names start with the relevant
Tmpprefix. -
No Turkish characters: The characters
Ç, Ğ, İ, Ö, Ş, Üand spaces are not used in names; ASCII characters are preferred. -
Plural names: Table names are plural:
Items,Orders. -
Primary keys: In the form
[SingularTableName]Id(e.g.,ItemId,OrderId). -
Text fields: The 'NVARCHAR' type is used. (e.g., NVARCHAR(50), NVARCHAR(100), NVARCHAR(250), and NVARCHAR(MAX) when necessary). All Unicode constants must be written in the form N'...'
-
Date/time fields: The suffixes
Date,DateTime,UtcDateTimeare used (e.g.,AddDate,UpdateDate,UpdateDateTime). Datetime is preferred. The smalldatetime type should be avoided. -
Logical fields: Start with
Is*and are of bit type (e.g.,IsActive,IsFinished). The 'Tinyint' type should be avoided. -
Numeric Fields: The 'int' type is used for integers, and the 'decimal(18,6)' type for decimal numbers. The 'Tinyint' type should be avoided.
-
Term selection (type/kind/group): Among expressions that may have the same meaning,
tip(English equivalent:Type) is preferred. Words such as "kind", "group", "class", "category" are not used in naming.- Correct:
ItemTypeId, PriceTypeId, OperationTypeId - Incorrect:
ItemTurId, PriceGroupId, OperationClassId
- Correct:
-
Fixed/standard abbreviations: Their use is discouraged. However, when necessary, they are limited to a widely known and consistent list across the project:
- Allowed (examples):
Id,No(number),Qty(quantity),Avg,Min,Max,Net,Gross,Ref,Code,Desc(if necessary). - To be avoided: ...
- Unit/symbol abbreviations: Technical/international standards are used as is (
Kg,Mm,Cm,Usd,Eur). - Abbreviation principle: Clear name > abbreviation. Abbreviation is used only if the name is very long, if it is a recurring pattern, or if there is a space constraint in the field.
- Consistency: Once chosen, an abbreviation must be used with the same meaning throughout the entire schema.
- Examples:
- Line Number: LineNumber
- Description: Notes
- UserId: @sssip (in SPs)
- BypassTrig: If a table has an Update trigger, a field named 'BypassTrig' is created.
- Allowed (examples):
Object Types
- Table
- View
- Stored Procedure
- Function
- Trigger
- Index
- Foreign Key (FK)
- Default Constraint
- Sequence
General Template
[Prefix]_[Rn | RnPj]_[ModuleCode]_[ObjectName]
Prefixes
| Prefix | Type | Note |
|---|---|---|
| Tables | ||
| Tb | Table | Used for permanent tables |
| Tmp | Temporary Table | Session/temporary content |
| View | ||
| Pv | View | Primary (operational) view |
| Sv | Selection (Lookup) View | Not used for now |
| Cv | Report Catalog View | Not used for now |
| TmpPv | Temporary View | View that looks at temporary tables |
| Stored Procedure | ||
| Sp | Stored Procedure | Business rule/process |
| Function | ||
| Fn | Function | Scalar/table-valued |
Module Codes
| Prefix | Module | Example |
|---|---|---|
| Main Modules | ||
| Sales | Order | Tb_Rn_Sales_Order |
| Planning | Planning | Tb_Rn_Planning_WorkOrder |
| Inventory | Stock & Bill of Materials | Tb_Rn_Inventory_Item |
| Production | Production | Tb_Rn_Production_Bom |
| Purchase | Purchasing | Tb_Rn_Purchase_Order |
| System | System | Tb_Rn_System_User |
Name Templates for Other Objects
| Name | Syntax | Example |
|---|---|---|
| Trigger | [TableName]_[Function] | Tb_Rn_Sales_Order_UpdateAudit |
| Index | Ix_[TableName]_[Column1]_[Column2]... | Ix_Tb_Rn_Sales_Order_OrderCode |
| Unique Index | Uix_[TableName]_[Column1]_[Column2]... | Uix_Tb_Rn_System_User_UserName |
| Foreign Key | Fk_[TableName]_[RefTableName]_[FieldName] | Fk_Tb_Rn_Sales_Order_Tb_Rn_Inventory_Item_ItemId |
| Default Constraint | Df_[TableName]_[ColumnName] | Df_Tb_Rn_System_User_IsActive |
| Sequence | S_[TableName]_[FieldName] | S_Tb_Rn_Sales_Order_OrderNo |
Note: All of the
TableName,RefTableName, andFieldNamesegments must be PascalCase.
Examples
- Table:
Tb_Rn_Inventory_Item - View:
Pv_Rn_Production_BomTree - SP:
Sp_Rn_Purchase_CreateOrder - FN:
Fn_Rn_System_DivideByZero - Trigger:
Tb_Rn_Quality_SsTransactionItems_UpdateLock - Index:
Ix_Tb_Rn_Inventory_Item_ItemCode - FK:
Fk_Tb_Rn_Production_Bom_Tb_Rn_Inventory_Item_ItemId - DF:
Df_Tb_Rn_System_User_AddDate - Sequence:
S_Tb_Rn_Finance_ExchangeRate_RateNo
Style Checklist (Quick Check)
- Are segments separated by
_? - Is each segment PascalCase?
- Are there no Turkish characters?
- Are entity names singular?
- Do the PK/FK, date, and bit field names comply with the rules?
- Are the prefix and module code correct?
Snippet
Redgate Sql Prompt
Write Sql quickly and consistently with snippets. To write Sql code that is 100% compliant with the naming conventions, use the ready-made templates in this repo: ReniumYazilim / SQL-DEV / SQL-PROMPT / Snippets
Quick Pick: Scenario → Snippet
| Scenario | Snippet to Use |
|---|---|
| Creating a table | snp_CreateTable-a27c8d44-5ecc-475a-90a1-caf7b22dbe24.json |
| Creating an SP | snp_CreateSp-0c85b39e-3122-44db-9de0-603b18f4bec6.json |
| TvFn / Fn | xxx / Function_TvFn_Template.sql |
| Trigger | xxx |
| Index / Unique Index | xxx |
How do I use snippets in editors (Ssms / Visual Studio)?
- Clone the repo or download it as a ZIP.
- Open the snippet file in the editor and edit it with your own table/object name.
- Review the field names according to our naming checklist.
- Keep the source as a "template"; copy and fill it directly for new objects.
Renium users. You can access faster SQL snippets that comply with naming standards from the ...\OneDrive - RENIUM\Belgeler - Proje\General\GitHub\SQL-DEV\SQL-PROMPT\Snippets folder:::