SQL Server命名开发规范.docx
- 文档编号:17691844
- 上传时间:2023-08-03
- 格式:DOCX
- 页数:16
- 大小:23.35KB
SQL Server命名开发规范.docx
《SQL Server命名开发规范.docx》由会员分享,可在线阅读,更多相关《SQL Server命名开发规范.docx(16页珍藏版)》请在冰点文库上搜索。
SQLServer命名开发规范
ForSQLServer
DBDevelopment-Namingspecification
2012/01/01
Author(作者):
XXXX
Date:
Checkedby(审核):
Date:
ChangeHistory(变更历史)
Date
Version
Author
Descriptionofchange
2012-6-12
1.0
JetLee
新起草;
2012-6-15
1.1
JetLee
文档拆分成两个;
Content
1Introduction(引言)6
1.1Purpose(规范的目的)6
1.2Readers(阅读的人员)6
1.3Glossary(术语)6
1.4Reference(参考资料)6
2UnifiedcriterionforNaming(统一的命名规范)6
2.1OverallPrinciple(整体性原则)6
2.2Table(表)6
2.2.1TableName(表名称)6
2.2.2TableIndex(表索引)7
2.2.3TableField(表字段)7
2.3View(视图)7
2.4Storedprocedure(存储过程)7
2.5Function(函数)7
2.6Variant(变量)7
2.7Synonym(同义词)7
2.8Job(作业任务)8
2.9SSIS(SSIS包)8
2.10Userdefineddatatype(用户自定义数据类型)8
2.11Userdefinedtabletype(用户定义表类型)8
3UnifiedcriterionforDevelopment(统一的开发规范)8
3.1Statement(语句)8
3.1.1Overallprinciple(一般性原则)8
3.1.2NestingStatement(嵌套语句的使用)9
3.2Comments(备注)9
3.2.1Field(字段)9
3.2.2Objectschema(对象概述)9
3.2.3Parameter(参数)9
3.2.4Function(函数)10
3.2.5Procedure(过程)10
3.2.6View(视图)10
3.2.7KeyArithmetic(关键算法)10
3.3CreateTable(表创建)11
3.3.1TableIndex(索引)11
3.3.2ParadigmRequirement(范式要求)11
3.4View(视图)11
3.5Function(函数)11
3.6Procedure(过程)12
3.7Trigger(触发器)13
3.8IsolationLevel(隔离集使用)13
4Attachment(附件)13
4.1TableNormalForm13
4.2IsolationLevel13
4.3Exceptioneventsreconciliation14
1Introduction(引言)
1.1Purpose(规范的目的)
GuidethedeveloperhowtonametheDBobjects(Tables,views,storedprocedure,etc)
(指引开发人员如何去规范对DB中对象进行命名);
1.2Readers(阅读的人员)
Developer,themembersofthereviewboard,DevelopmentManager;
(开发人员;Reviewboard成员;开发经理);
1.3Glossary(术语)
TableNormalform:
Refertheattachment;
(表的范式:
参考附件;)
IsolationLevel:
Refertheattachment;
(隔离级:
参考附件;)
1.4Reference(参考资料)
None
2UnifiedcriterionforNaming(统一的命名规范)
2.1OverallPrinciple(整体性原则)
∙Thecharactersrangeforallnames:
A-Z,a-z,0-9,_(Underscore).Notallowedtouseothercharactersasthename.(所有名称的字符范围为:
A-Z,a-z,0-9和_(下划线)。
不允许使用其他字符作为名称).
∙PleaseuseEnglishwordsorEnglishphrases(includingabbreviations)asname,butcannotbeusedasthenameofmeaninglesscharactersorChinesePinyin.(采用英文单词或英文短语(包括缩写)作为名称,不能使用无意义的字符或汉语拼音。
)
∙Nameshouldbeclarity,theabilitytoaccuratelyexpressthemeaningofthings,andreadable.Pleasefollowtheprincipleof"seetoknowthemeaning".(名称应该清晰明了,能够准确表达事物的含义,最好可读,遵循“见名知意”的原则。
)
∙Databaseobjectsneedtoaddthenecessarycomments,suchasTables,procedures,functions,etc.Expressthecontentsofthecommentsinyourmotherlanguage.(数据库对象需要添加必要的注释,如表、存储过程、函数等,注释使用你的母语;)
2.2Table(表)
2.2.1TableName(表名称)
∙Usenotmorethanthreewordstoconstructthetablename.Whenthelengthofasinglewordismorethaneight,notmorethan4letterscanbechosentorepresentthewholeword’smeaning.Inthecombinationname,thefirstletterofeverywordshouldbecapitalized.Exceptthesinglewordforthetablename,allthewordscannotbepluralinthecombinationname.(请使用不多于三个单词的组合构建一个表的名称。
当某个单词字母较多(超过8个字母时),请选择其中四个关键字作为它的代表含义;组合的单词中,每个单词首字母需要大写,表示另一个含义的开始;组合单词不使用复数,但单个单词则可以。
)
Sample:
DeliverCstmOrder(递交客户订单)
Orders(订单表)
2.2.2TableIndex(表索引)
∙Usethesystemdefaultnamingruleforthetableindex.Don’tchangeit.(在定义表的索引时(PrimaryKey,Unique,etc),请使用系统默认的命名,无须去改动它。
)
2.2.3TableField(表字段)
∙Usenotmorethanthreewordstoconstructthetablename.Whenthelengthofasinglewordismorethaneight,notmorethan4letterscanbechosentorepresentthewholeword’smeaning.Inthecombinationname,everywordshouldbespacedbytheunderline.Allthelettersinthecombinationnameshouldbelowercase.(请使用不多于三个单词的组合构建一个字段的名称。
当某个单词字母较多时(超过8个字母),请选择其中不多于四个关键字作为它的代表含义;组合的单词中,每个单词之间以下划线间隔开;全部单词都要小写。
)
Sample:
scan_date:
扫描日期
cstm_order_id:
客户订单ID
2.3View(视图)
∙Referthenamingruleofthetable.Weshouldaddthecapitalized“V_”todifferentiatethetablename.(命名规则请参考“TableName”,为了与之相区别,在此前面加大写V_进行区分)
Sample:
V_Orders(订单)
V_ShopScan(车间扫描)
2.4Storedprocedure(存储过程)
∙Referthenamingruleofthetable.Weshouldaddthecapitalized“P_”todifferentiatethetablename.(命名规则请参考“TableName”,为了与之相区别,在此前面加大写P_进行区分。
)
Sample:
P_GetShopScan(@Order_Numvarchar(20))(获取车间扫描数据)
P_SendMail()(发送邮件通知)
2.5Function(函数)
∙Referthenamingruleofthetable.Weshouldaddthecapitalized“F_”todifferentiatethetablename.(命名规则请参考“TableName”,为了与之相区别,在此前面加大写F_进行区分。
)
Sample:
F_CheckCoa(COA检查)
F_ViewFieldName(显示字段名)
2.6Variant(变量)
∙Referthenamingruleofthetable.(变量或参数命名规则请参考“TableName”)
Sample:
@OrderNumber订单编号;
2.7Synonym(同义词)
∙Refertherespectiveruleoftherelatedobject.Addtheprefix“Rmt_”tothename.(参考相应各自的相应的对象命名规则,在名称前添加前缀“Rmt”);
Sample:
Rmt_P_GetOrders为过程P_GetOrder建立同义词;
Rmt_Orders为表Orders建立同义词
2.8Job(作业任务)
∙Meettheprincipleof"seetoknowthemeaning".Notmorethan8words.Theshortennameisnotavailable.Thefirstlettershouldbecapitalized.Thejobexecutingfrequencyshouldbeaddedtothename.(符合见名知意的原则,不多于8个单词组合的名称,不使用缩写;单词的首写字母需要大写;在名称后面加入该JOB的执行频率);
Sample:
ImportCustomerOrder[5Min]
2.9SSIS(SSIS包)
∙Meettheprincipleof"seetoknowthemeaning".Notmorethan8words.Theshortennameisnotavailable.Thefirstlettershouldbecapitalized.(符合见名知意的原则,不多于8个单词组合的名称,不使用缩写;单词的首写字母需要大写);
Sample:
ImportCustomerOrder
2.10Userdefineddatatype(用户自定义数据类型)
∙Followthetablenamingrule.Addtheprefix“Udt_”tothename.(Follow表的命名规则,前面加“Udt_”);
Sample:
Udt_PhoneNumber(自定义一个电话号码的数据类型);
2.11Userdefinedtabletype(用户定义表类型)
∙Followthetablenamingrule.Addtheprefix“Tvp_”tothename.(Follow表的命名规则,前面加“Tvp_”(Tablevalueparameter));
Sample:
Tvp_GetUserLocation(定义获取用户场所的表类型);
3UnifiedcriterionforDevelopment(统一的开发规范)
3.1Statement(语句)
3.1.1Overallprinciple(一般性原则)
∙Intheprogramming,allthekeywordsoftheDBsystemsshouldbelowercase.Alltherelatedtotheobjects(Table,view,etc)shouldreferthenamingruleaccordingly.(在编程过程中,对于语句中的关键字全部使用小写;语句涉及到的数据库对象(Table,View,Procedure,Function,Schema)等等,请应用这些对象的相应命名规范)
Sample:
selectfield_name,field_typefromTableListwhere…
updateTableListsetfield_name=’xxx’where…
execP_LoadMachineList(…)
3.1.2NestingStatement(嵌套语句的使用)
∙AgainsttotheDB2,wedon’tencouragethenestingtobeusedinSQLServer.Tryyoubesttousethesimplestatements.(在SQL中,与DB2相反,不鼓励使用查询的嵌套语句,请尽量使用简单的语句。
)
selectx,yinto#TempOnefromTableListwhere…
selectj,kinto#TempTwofrom#TempOnewhere…
select*from#TempTwoa,AllObjectsbwhere…
Inprinciple,theabovestatementsarebetterthanthebelownestingstatementinSQLqueryoptimizer:
(在SQLServer查询优化器中,理论上要优于):
select*from(selectfiled_name,field_typefrom(select…fromTableList)t)a,AllObjectsbwhere…
3.2Comments(备注)
3.2.1Field(字段)
∙Makecommentsforthefieldaspossibleasyoucan.Astothesimplifiedwordsincludedinthefieldname,youmustthegiveclearexplanationforit.(请尽量对表中所有字段进行备注;对于使用了简化单词组合成的字段,请必须说明。
)
Sample:
file_name:
文件名(这个简单明了,不一定要备注上去).
cstm_name_convert:
客户名称转换(这个必须要备注,其中有cstm是使用了简化单词的,请解释明白。
3.2.2Objectschema(对象概述)
∙Usethedefaultschema“dbo”only.NoothersschemacanbedefinedinSQLServer;(就使用数据库本身默认的dbo的schema就可以了。
不能再定义其它的schema。
)
3.2.3Parameter(参数)
∙Tothefunctionorprocedure,weshouldaddthecommentsfortheentryparameters.(对于函数或存储过程,在它们的过程体前面添加对各个入口参数的解释.)
Sample:
P_LoadMachineScan(@OrderNumbervarchar(20),@InputDateTimedatetime)
/*ProcedureName:
P_LoadMachineScan.
此过程用于载入某个批次所有主机的扫描记录;
ParameterList:
@OrderNumber用户输入的工单号;
@InputDateTime用户选择的扫描时间范围;
*/
3.2.4Function(函数)
∙Associatewiththeparameters;addthecommentsintheheadofthefunction.(请连同参数一起,在过程体前面添加对该函数的作用进行解释).
Sample:
F_ShowFieldName(@TableNamevarchar(50))
/*FunctionName:
F_ShowFieldName.
此函数用于显示指定表的所有字段名称;
ParameterList:
@TableName用户输入的表名字;
*/
3.2.5Procedure(过程)
∙Referthefunction.(请参考”函数”);
Sample:
P_LoadMachineScan(@OrderNumbervarchar(20),@InputDateTimedatetime)
/*ProcedureName:
P_LoadMachineScan.
此过程用于载入某个批次所有主机的扫描记录;
ParameterList:
@OrderNumber用户输入的工单号;
@InputDateTime用户选择的扫描时间范围;
*/
3.2.6View(视图)
∙Addthenecessaryexplanationtotheview:
Therelatedthetableandotherviewname,andfunctionname.(请在语句体前面加入对该视图的必要说明:
该视图所涉及的表,或其它视图的名称,所引用的函数名称等等);
Sample:
CreateViewV_Ordersas
/*ViewName:
V_Orders
此视图主要用于计算内部客户订购公司产品的联合价格;
该视图引用:
Orders(订单表)
InnerCstm(内部客户表)
F_CombineOutput(计算联合价格函数)
*/
selecta.order_number,b.cstm_id,dbo.F_CombineOutput(a.price,b.quantity)ascombine_outputfromOrdersa,InnerCstmbwherea.order_number=b.order_numer
3.2.7KeyArithmetic(关键算法)
∙Astothestoredprocedureorfunction,addthenecessaryremarktothecomplexexpressionstatement.(对于存储过程,还是函数,如果在语句表达较复杂的,请在该语句上面添加备注);
…
…
/*根据订单表与内部客户表联合,通过函数F_CombineOutput计算得到联合价格更新到订单表的价格*/
updateaseta.price=dbo.F_CombineOutput(a.price,b.quantity)fromOrdersa,InnerCstmbwherea.order_number=b.order_numer.
…
…
3.3CreateTable(表创建)
3.3.1TableIndex(索引)
∙Notmorethan3fieldscanbecombinedtotheprimarykey.Astothefieldwhosewidthislongerthan20characters,itcannotbesetastheprimarykey.(PrimaryKey的索引组合不要超过三个字段;字段长度超过20字符的,不能应用于PrimaryKey的组合);
∙Theindexshouldbecreatedforthefiledthatisusedfrequently.(对于频繁使用某个字段进行检索该表的,应当在该字段上创建索引);
∙Notmorethan3indexesexistinasingletable(Inadditiontotheprimarykey).(一个表(除了Primarykey)索引数量不应当超过三个);
3.3.2ParadigmRequirement(范式要求)
∙(Exceptforthedatawarehousebuilding,allthetablecreatingshouldmeettheDB1NFrequirement.)除非进行数据仓库的建设,否则所有任何表至少需要符合第一范式;
3.4View(视图)
∙Forsavingtheworkload,nestingviewsis
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- SQL Server命名开发规范 Server 命名 开发 规范