微软数据库命名规范11.docx

上传人:b****6 文档编号:7768677 上传时间:2023-01-26 格式:DOCX 页数:10 大小:27.97KB
下载 相关 举报
微软数据库命名规范11.docx_第1页
第1页 / 共10页
微软数据库命名规范11.docx_第2页
第2页 / 共10页
微软数据库命名规范11.docx_第3页
第3页 / 共10页
微软数据库命名规范11.docx_第4页
第4页 / 共10页
微软数据库命名规范11.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

微软数据库命名规范11.docx

《微软数据库命名规范11.docx》由会员分享,可在线阅读,更多相关《微软数据库命名规范11.docx(10页珍藏版)》请在冰豆网上搜索。

微软数据库命名规范11.docx

微软数据库命名规范11

DatabaseNamingConventionsVersion1.1

数据库命名协议版本1.1

野人翻译2008年3月16日

LastRevisedMay13,2004byJasonMauss

JasonMauss2004年5月13日修订版

Themaingoalofadoptinganamingconventionfordatabaseobjectsissothatyouandotherscaneasilyidentifythetypeandpurposeofallobjectscontainedinthedatabase.为数据库对象编写命名协议的目的,就是能够轻松的定义数据库中全部对象。

Theinformationpresentedhereservesasaguideforyoutofollowwhennamingyourdatabaseobjects.这里提到的内容可以作为数据库对象命名的指导。

Whenreadingtheserulesandguidelinesrememberthat consistent naming canbe themostimportantruletofollow.当阅读此文涉及的规范和原则时,请牢记始终规范的命名方法是数据库设计的最重要原则。

Keepinmindthatfollowing theguidelinesasoutlinedinthisdocument canstill producelongandcryptic names, ultimately,youruniquesituationwilldictatethereasonabilityofyournamingconvention. 请注意根据此协议的原则做出的数据库对象的命名相对较长并具有相关的意义,具体命名需要依照你个人及开发环境的情况。

Thegoalofthisparticularnamingconventionistoproducepractical,legible,concise,unambiguousandconsistentnamesforyourdatabaseobjects.此命名协议的制定目的,是提供较为形象、易读、简单、明确和原则性一致的数据库命名方法。

Whilemostdatabasescontainmoretypesofobjectsthanthosediscussedhere(UserDefinedTypes,Functions,Queries,etc.),the7typesofobjectsmentionedherearecommonamongallmajordatabasesystems.ThinkofthisasagenericDBMS-neutralguidefornamingyourobjects.当然,数据库涉及到的对象比这里讨论的更多(例如用户自定义的、函数、查询等),这里提到的7种对象涵盖了大多数数据库系统的内容。

所以请将此协议作为“中性数据库”的命名指导。

Thefollowingtypesofdatabaseobjectsarediscussedhere:

这里讨论下列数据库对象:

1.Tables表

2.Columns(incl.Primary,ForeignandCompositeKeys)列(包括主键、外键和复合键)

3.Indexes索引

4.Constraints参数

5.Views视图

6.StoredProcedures存储过程

7.Triggers触发器

ALLDATABASEOBJECTS

全部数据库对象命名的统一规则

∙Limitthenameto30characters(shorterisbetter)限制名称在30个字母以内(越短越好)

∙Useonlylettersorunderscores(trytoavoidnumbers)仅仅使用字母和下划线(尽量避免数字命名)

∙Trytouseunderscorecharactersaslittleaspossible.尽量减少使用下划线PascalCasenotationachievesthesamewordseparationwithoutthem.PascalCase标记法可以做到在不使用下划线的情况下分割单词

∙Usealetterasthefirstcharacterofthename.(don'tstartnameswithunderscores)不要以下划线作为名称的字母

∙Avoidabbreviations(canleadtomisinterpretationofnames)避免使用所写(可能引起误解)

∙Avoidacronyms(someacronymshavemorethanonemeaningeg."ASP")避免使用缩写(因为一些缩写例如ASP,有特定意义和用途)

∙Makesthenamereadable(theyshouldn'tsoundfunnywhenreadaloud)确保名称可朗读

∙Avoidusingspacesinnamesevenifthesystemallowsit.无论是否系统允许都避免使用空格

1

1.TABLES表

Whennamingyourdatabasetables,giveconsiderationtootherstepsinthedevelopmentprocess.当为你的表命名时,请同时考虑到后续开发的各个环节。

Keepinmindyouwillmostlikelyhaveto utilizethenamesyougiveyourtablesseveraltimesaspartofotherobjects,forexample,procedures,triggersorviewsmayallcontainreferencestothetablename.请记住你很有可能在后续开发其他对象,如存储过程、触发器或者视图时多次用到你所命名的表的名称,并作为相关参数使用。

Youwanttokeepthenameassimpleandshortaspossible.所以尽量使用简单短小的单词。

Somesystemsenforcecharacterlimitsonobjectnamesalso.甚至一些系统强制限制对象名称的单词长度。

Forexample,inOracleyouarelimitedtoabout30charactersperobject.例如Oracle限制名称长度为30字母以内。

Rule1a(PluralNames复数原则)-Tablenamesshouldbeplural,forexample,"Customers"insteadof"Customer".表的名称应该为复数。

This ruleisapplicable becausetablesarelogicalcollectionsofoneormoreentitiesasrecords-justlikecollectionclassesarelogicalcollectionsofoneormoreobjects.因为表包含了很多数量的实体记录。

IfyouweretofirstdrawanabstractdatamodellikeaNIAM/ORMmodel,youmighthavesingularentitynameslike"Customer"or"User"but,theyshouldbechangedto thepluralform whenbuildingtheactualtables.尽管当你在建立数据库NIAM/ORM模型时,可能使用单数形式表示实例,但是当建立具象事物表时,要使用复数名称。

Fortablenameswithmultiplewords,onlythelastwordshouldbeplural,forexample,"UserRoles"and"UserRoleSettings".当由词组命名时,将最后一个单词变为复数。

[译者按:

复数命名法一般情况下不可取,在长度,表述方面不佳,作者本身也承认使用复数命名的情况较少]

Rule1b(Prefixes前缀)-Usedcorrectly,tableprefixescanhelpyouorganizeyourtablesintorelatedgroupsordistinguishthemfromotherunrelatedtables.正确的使用前缀能够帮助你识别表所处的分组或者和其他的表容易区分。

Usedpoorly,theycancauseyoutohavetotypealotofunnecessarycharacters.使用前缀是避免使用复杂修饰、限制性词汇辅助命名的好方法。

We'lldiscusswhatnottodofirst.首先我们讨论被禁止的做法。

Donotgiveyourtablenamesprefixeslike"tbl"or"TBL_"asthesearejustredundantandunnecessary.不要使用"tbl”或者"TBL",因为这种方法多余且不必须。

ItwillbeobviouswhichnamesarethetablenamesinSQLstatementsbecausetheywillalwaysbeproceededbytheFROMclauseoftheSELECTstatement.因为在选择查询语句中表名紧跟在FROM的后面。

Notallprefixesarebad.不是所有的前缀都不可取。

Insomecases,yourtablesmightbesharingaschema/databasewithothertablesthatarenotrelatedinanyway.在某些情况下,表可能被一些数据库共享引用,但是此表与其它的表没有任何关系。

Inthiscase,itissometimesagoodideatoprefixyourtablenameswithsomecharactersthatgroupyourtablestogether.这时,前缀可以将同类的表分组。

Forexample,forahealthcareapplicationyoumightgiveyourtablesan"Hc"prefixsothatallofthetablesforthatapplicationwouldappearinalphabetizedliststogether.例如,对于医疗保健方面的应用程序,可以用Hc开头,好处是能够系统能够将相同的HC开头的表排列在一起,做到分组查看。

Notethatevenfortheprefix,usePascalCase.注意前缀也是PascalCase命名法。

ThisisdiscussedinRule1c.Donotuseunderscoresinyourprefixes,whichisdiscussedinmoredepthinRule1d.同样根据Rule1c原则,不要使用下划线。

Thelastkindofprefixthatisacceptableisonethatallowsyoutogrouplogicalunitsoftables.最后一种能够使用前缀的条件是分组逻辑表单元。

Aplausibleexamplecouldentailalargeapplication(30to40+tables)thathandledbothPayrollandBenefitsdata.例如涉及到30到40个以上表的应用程序,其中包括例如支出和盈利2大部分数据。

Youcouldprefixthetablesdealingwithpayrollwitha"Pay"or"Prl"prefixandgivethetablesdealingwithbenefitsdataa"Ben"or"Bfts"prefix.这时可以以"Pay"或者"Prl"作为支出类表的前缀,"Ben"或者"Bfts"作为盈利类表的前缀。

Thegoalofboththisprefixandtheaforementionedsharedschema/databaseprefixistoallowyoutogroupspecifictablestogetheralphabeticallyinlistsanddistinguishthemfromunrelatedtables.当然这些前缀的使用目的都是要使系统能够自动分组同类表的位置。

Lastly,thesharedschema/databaseprefixisahighergroupinglevelandcomesfirstinthename,forexample,"HcPayClients"not"PayHcClients".最后,当使用符合前缀时,需要将表示大类的前缀排在前,小类前缀续后,如“医疗保健支出联系人”而不是“支出医疗保健联系人”。

Rule1c(Notation表示法)-Forallpartsofthetablename,includingprefixes,usePascalCase.所有的表名,包括前缀,都使用PascalCase拼写法。

UsingthisnotationwilldistinguishyourtablenamesfromSQLkeywords(allcapitalletters).这种方法能够使表名和SQL语句全部大写的关键字区分开。

Forexample,"SELECTCustomerId_Pk,CustomerNameFROMMyAppGroupTableWHERECustomerName='%S'"showsthenotationforthetablenamedistinguishingitfromtheSQLkeywordsusedinthequery.例如此语句的区分比较明晰。

PascalCasealsoreducestheneedforunderscorestovisuallyseparatewordsinnames.同时这种表示法减少了下划线的使用。

Rule1d(SpecialCharacters特殊字)-Fortablenames,underscoresshouldnotbeused.表名不能在下划线。

Theunderscorecharacterhasaplaceinother objectnamesbut,notfortables.下划线有其它的用法,但是不能在表命名里出现。

UsingPascalCaseforyourtablenameallowsfortheupper-caselettertodenotethefirstletterofanewwordorname.表命名应该以PascalCase作为命名方法,即首字母大写表示下一个单词的起始。

Thusthereisnoneedtodosowithanunderscorecharacter.所以就没有必要再用下划线表示单词起始了。

Donotusenumbersinyourtablenameseither.同时不能用数字作为表名。

Thisusuallypointstoapoorlydesigneddatamodelorirregularlypartitionedtables.数字表名一般特指失败的数据设计模型或者非常规表。

Donotusespacesinyourtablenameseither.同时不能使用空格作为表名。

Whilemostdatabasesystemscanhandlenamesthatincludespaces,somesystemsrequireyoutoaddmorecharactersaroundthenamewhenreferencingit(like[tablename]forexample)whichgoesagainsttheruleofkeepingthingsasshortandsimpleaspossible.当然大部分的数据库系统允许表名空格的存在,但是至少空格会增加名称长度,不符合简短命名原则。

Ifyouaredevelopinginanon-englishlanguage,donotuseanyofthatlanguage'sspecialcharacters.如果使用非英语命名,不要使用非英语字符。

Rule1e(Abbreviations缩写)-Avoidusingabbreviationsifpossible.尽量避免缩写Use"Accounts"insteadof"Accts"and"Hours"insteadof"Hrs".使用全拼不用缩写单词。

Noteveryonewillalwaysagreewithyouonwhatyourabbrevationsstandfor-and-thismakesitsimpletoreadandunderstandforbothdevelopersandnon-developers.对于同开发小组其他成员和用户来讲,缩写并非容易读懂和认同。

Thisrulecanberelaxedforjunctiontablenames(SeeRule1f).此原则同样在Rule1f原则出现,涉及到交叉表名。

Donotuseacronyms.同时避免任何形式的缩写前缀单词。

Rule1f(Junctiona.k.aIntersectionTables交叉表)-Junctiontables,whichhandlemanytomanyrelationships,shouldbenamedbyconcatenatingthenamesofthetablesthathaveaonetomanyrelationshipwiththejunctiontable.交叉表应当以其表述的连锁意义来命名。

Forexample,youmighthave"Doctors"and"Patients"tables.例如有“医生”和“病人”2个表。

Sincedoctorscanhavemanypatientsandpatientscanhavemanydoctors(specialists)youneedatabletoholdthedataforthoserelationshipsinajunctiontable.Thistableshouldbenamed DoctorsPatients".因为医生可能有很多病人,同时每个病人有不同科目的医生,所以交叉表名应该为“医生病人”。

Sincethisconventioncanresultinlengthytablenames,abbreviationssometimesmaybeusedatyourdiscretion.考虑到交叉表名的长度,可以谨慎考虑缩写。

 

2.COLUMNS列-(incl.PRIMARY,FOREIGN,ANDCOMPOSITEKEYS包括主键,外键和复合键)

Whennamingyourcolumns,keepinmindthattheyaremembersofthetable,sotheydonotneedtheanymentionofthetablenameinthename.列是表的组成部分,所以不要在其中涉及表名。

Theprimarykeyfieldistypicallytheonlyexceptiontothisrulewhereincludingthetablenameisjustifiedsothatyoucanhaveamoredescriptivefieldnamethanjust"Id".主键是唯一可以包括表名的,具备表的描述性。

"CustomerId" isacceptablebutnotrequired.主键包括表名单词并非必要。

 Justlikewithnamingtables,avoidusingabbreviations,acronymsorspecialcharacters.就像表名需要避免缩写,全前缀缩写或者特殊字符。

AllcolumnnamesshouldusePascalCasetodistinguishthemfromSQLkeywords(alluppercase).所以列明要求使用PascaCase表示法区分SQL语句的全大写表示法。

Rule2a(IdentityPrimaryKeyFields主键标识列)-Forfieldsthataretheprimarykeyforatableanduniquelyidentifyeachrecordinthetable,thenameshouldsimpl

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > 交规考试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1