Database Object Naming Rules

数据库对象命名规范
本文介绍了数据库对象的命名规则,包括表、视图、存储过程等的命名方式,并提供了实例。涵盖了前缀、后缀、大小写约定等内容。

Database Object Naming Rules

Summary:

 

Casing

Prefix

Suffix

Alpha Numeric Characters

Notes

Tables

Pascal

 

 

x

Use singular form: Eg User, not Users

Linking Tables

Pascal

 

Link

x

Formed from the Tables they are linking, eg: A Table joining User and Group would be UserGroupLink

Table Columns

Pascal

 

 

x

 

Primary Key

Pascal

PK_

 

x

 

Clustered Index

Pascal

IXC_

 

x

 

Unique Clustered Index

Pascal

IXCU_

 

x

 

Unique Index

Pascal

IXU_

 

x

 

Index

Pascal

IX_

 

x

 

XML Index

Pascal

XML_IX_

 

x

 

XML Columns

Pascal

 

 

x

Use .net Pascal casing, no underscores

Constraints

Pascal

CK_

 

x

 

Default Value

Pascal

DF_

 

x

 

Foreign Keys

Pascal

FK_

 

x

 

Views

Pascal

VW_

 

x

 

Functions

Pascal

FN_

 

x

 

Stored Procedures

Pascal

none

 

x

 

Triggers (after)

Pascal

TRGA_

 

x

 

Triggers (instead)

Pascal

TRGI_

 

x

 

Schemas

  • Use lowercase for schema names.
  • Always alias database objects using the schema name, even if this is the default [dbo] schema
  • This applies to both CREATE statements and when referencing objects in FROM, INSERT or UPDATE statements etc.

Table Names

  • Pascal Case
  • Alpha-numeric
  • Avoid underscore
  • No Prefix
  • Use the Singular Form eg: User, not Users

Linking Table Names

  • Linking Tables should be the name of the two tables it is joining, suffixed with Link. Eg a joining table on User and Group would be UserGroupLink

Column Names

  • Pascal Case
  • Alpha-numeric
  • Avoid underscore
  • No Prefix
  • Format: <TableName(for PK only)><Qualifier><Name>

use the following components in the order below;

    • Table Name: Primary keys only; Tables names are used to prefix all columns in dotted format, so this is not necessarily. The exception is the primary key since this is used in foreign keys.
    • Qualifier: Optional; Description, to clarify the meaning of the field. For example, if a product has two images, this would clarify the field, eg. FrontImage and RearImage
    • Name: Required; This is a database independent “datatype” descriptor which is used to classify the type of data. Below is a common list of standard classifiers. The exception to this is a Boolean. This should be Prefixed with “Is” as this more positively represents the meaning o the value. Flag suffix is considered optional “Flag” or Eg. IsEnabled or IsEnabledFlag

 

Classifier

Description

Suggested SQL Data Type

Address

Street or mailing address data

nvarchar

Age

Chronological age in years

int

Average

Average; consider a computed column

numeric

Amount

Currency amount

money

Code

Non Database Identifier

 

Count

 

 

Data

A field containing extensible data

xml

Date

Calendar date

smalldatetime

Datetime

Date including time

datetime

Day

Day of month (1 - 31)

tinyint

Description

Brief narrative description

nvarchar(MAX)

Duration

Length of time, eg minutes

int

ID

Unique identifier for something

int

Image

A graphic image, such as a bitmap

varbinary(MAX)

Flag

Not Required: Flag indicates a boolean indicator, where the Qualifier verb does not make it clear it is a verb. Examples of a Qualifier are: Is, Has, Uses. Eg IsEnabled

bit

Month

Month of year

 

Name

Formal name

nvarchar

Number

 

 

Percent

Number expressed as a percent

 

Quantity

A number of things

any numerical

Rate

Number expressed as a rate

any numerical

Ratio

A proportion, or expression of relationship in quantity, size, amount, etc. between two things

any numerical

Sequence

A numeric order field

int

Text

Freeform textual information

nvarchar(MAX)

Time

Time of day

smalldatetime

Title

Formal name of something

nvarchar

Version

Timestamp

timestamp

Weight

Weight measurement

any numerical

XML

A field containing xml data

xml

Year

Calendar year or julian year number

 

Stored Procedure Names

·         Use PascalCase

  • Naming Format: use the following components in the order below;
    • Object: Required; usually the table or combinations of tables it is affecting, followed by underscore.
    • Action: Required; eg Save, Load, Get, Set, SetSingle, Search, Delete
    • Qualifier: Optional; additional descriptive words which help to clarify the specific meaning of the stored procedure
    • Return Type: Optional; Indicates the type of data return
  • Example Stored Procedure Names:
    • AuthorSave
    • AuthorLoad
    • AuthorLoadByAuthorID
    • AuthorLoadByName
  • Do not:
    • Use special characters.
    • Use stored procedure group numbers (e.g. myProc;1).
    • prefix names with “sp_” as those are reserved for procedures shipped by SQL Server.

User Defined Functions (UDF) Names

·         Use PascalCase

  • Naming Format: use the following components in the order below;
    • Prefix: Required; “FN_”
    • Object: Required; usually the table or combinations of tables it is affecting, followed by underscore.
    • Action: Required; eg Get, Set, SetSingle, Search, Delete
    • Qualifier: Optional; additional descriptive words which help to clarify the specific meaning of the stored procedure
    • Return Type: Optional; Indicates the type of data return
  • Example Function Names:
    • FN_AuthorGetID
  • Often stored procedures will replicate (wrap) a user defined function. In this case the names should be identical with the exception of the additional prefix on a UDF.
  • Note, udfs cannot have any “effects” so cannot modify data.

Parameters - Stored Procedure/UDFs

  • Use PascalCase
  • Eg: @PageID

Variables - Stored Procedure/UDFs

  • Use camelCase
  • Eg: @pageID

Cursor Names

·         Use PascalCase, except for prefix

  • Naming Format: use the following components in the order below;
    • Prefix: Required; prefix with “CURSOR_”
    • Object: Required; usually the table being iterated over.
  • Note: Avoid the use of cursors where possible. Instead use a while loop

Updatable View Names

For Views which are updatable, act as if they are a table.

This holds true for Updatable Partitioned Views.

 

·         Use PascalCase, except for prefix

  • Naming Format: use the following components in the order below;
    • Prefix: Required; prefix with “VW_”
    • Object: Required; usually related to the table(s) affected by the view
    • Qualifier: Optional; additional descriptive words which help to clarify the purpose of the view.

Non Updatable View Names

 

For Views which provide a view on the data which makes them read only.

 

·         Use PascalCase, except for prefix

  • Naming Format: use the following components in the order below;
    • Prefix: Required; prefix with “VW_”
    • Object: Required; usually the concatenation of tables in the view
    • Qualifier: Optional; additional descriptive words which help to clarify the purpose of the view.

Trigger Names

·         Use PascalCase, except for prefix

  • Naming Format: use the following components in the order below;
    • Prefix: Required; prefix with “TRG”
    • Type: Required; depending on type of trigger, after or instead of. prefix with “A_” or “I_”
    • Object: Required; usually the table being iterated over.
    • Actions covered: Required; composite key of actions, “Upd”, “Ins”, “Del”

·         Example Trigger Names:

o    TRGA_CustomerInsUpdDe

o    TRGA_ProductDel

o    TRGI_AuthorUpd

Index Names

Index names are unique within a table so it isn’t necessary to include the tablename in the index. When looking at execution plans it is helpful to have a hint about the columns being indexed

  • Naming Format: use the following components in the order below;
    • Prefix: Required; prefix with “IX”
    • Clustered: Required; if Clustered Index include “C”
    • Unique: Required; if Unique Index include “U”
    • Column Names: Required; Include the list of columns indexed, using underscores between the column names. For an index that covers all columns in the table, use the word All.

·         Example Index Names:

o    IXCU_AuthorID   (clustered unique)

o    IXU_AuthorID (unique)

o    IX_AuthorID_AuthorName (composite index)

o    IXC_AuthorID  (clustered not unique)

Primary Key Names

  • Naming Format: use the following components in the order below;
    • Prefix: Required; prefix primary key with “PK_”
    • TableName: Required; Table name of table being keyed
  • Examples:

o    PK_Customer

Foreign Key Names

  • Naming Format: use the following components in the order below;
    • Prefix: Required; prefix foreign key with “FK_”
    • Reference Table Name(s): Required; Table name of table in the join, for which a unique index is on column(s) being linked. Where both have a unique index, such as linking key, order is optional
    • Foreign Table Name(s): Required; Table name of table in the join, for there is not a unique index on the column(s) being linked.
  • Example foreign key names:
    • FK_Country_Customer
    • FK_Customer_Sales

Default Value Constraint Names

  • Naming Format: use the following components in the order below;
    • Prefix: Required; prefix default value constraint with “DF_”
    • TableName: Required; Table name
    • ColumnName: Required; Column name
  • Example foreign key names:
    • DF_Author_Gender

Check Constraint Names

  • Naming Format: use the following components in the order below;
    • Prefix: Required; prefix check constraint with “CK_”
    • TableName: Required; Table name
    • Integer: Required; Where the integer id is used to distinguish the check constraint from other check constraints on the same table.
    •  
  • Example foreign key names:
    • CK_Author1

Abbreviation Standards

Avoid abbreviations, unless absolutely necessary, due to length restrictions

Database Collation

  • For new databases use: Latin1_General_CI_AS
  • For migrated databases, keep with the same collation as specified in the source database – often this will be: SQL_Latin1_General_Cp1_CI_AS as this is the default for a database migrated from SQL 7.0 to SQL2000
  • Ensure all columns use this option. They will if they are created in the database using, the correct collation.
一、数据采集层:多源人脸数据获取 该层负责从不同设备 / 渠道采集人脸原始数据,为后续模型训练与识别提供基础样本,核心功能包括: 1. 多设备适配采集 实时摄像头采集: 调用计算机内置摄像头(或外接 USB 摄像头),通过OpenCV的VideoCapture接口实时捕获视频流,支持手动触发 “拍照”(按指定快捷键如Space)或自动定时采集(如每 2 秒采集 1 张),采集时自动框选人脸区域(通过Haar级联分类器初步定位),确保样本聚焦人脸。 支持采集参数配置:可设置采集分辨率(如 640×480、1280×720)、图像格式(JPG/PNG)、单用户采集数量(如默认采集 20 张,确保样本多样性),采集过程中实时显示 “已采集数量 / 目标数量”,避免样本不足。 本地图像 / 视频导入: 支持批量导入本地人脸图像文件(支持 JPG、PNG、BMP 格式),自动过滤非图像文件;导入视频文件(MP4、AVI 格式)时,可按 “固定帧间隔”(如每 10 帧提取 1 张图像)或 “手动选择帧” 提取人脸样本,适用于无实时摄像头场景。 数据集对接: 支持接入公开人脸数据集(如 LFW、ORL),通过预设脚本自动读取数据集目录结构(按 “用户 ID - 样本图像” 分类),快速构建训练样本库,无需手动采集,降低系统开发与测试成本。 2. 采集过程辅助功能 人脸有效性校验:采集时通过OpenCV的Haar级联分类器(或MTCNN轻量级模型)实时检测图像中是否包含人脸,若未检测到人脸(如遮挡、侧脸角度过大),则弹窗提示 “未识别到人脸,请调整姿态”,避免无效样本存入。 样本标签管理:采集时需为每个样本绑定 “用户标签”(如姓名、ID 号),支持手动输入标签或从 Excel 名单批量导入标签(按 “标签 - 采集数量” 对应),采集完成后自动按 “标签 - 序号” 命名文件(如 “张三
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值