《数据库设计文档模板31389(20页).doc》由会员分享,可在线阅读,更多相关《数据库设计文档模板31389(20页).doc(20页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-数据库设计文档模板31389文档编号2011-6-14版本A1密级商密A项目名称时代集团产品跟踪平台项目来源时代集团DR-RD-020(V1.1)数据库设计说明书(内部资料 请勿外传)编 写:日 期:检 查:日 期:审 核:日 期:批 准:日 期:版权所有 不得复制时代集团产品跟踪平台1数据库设计说明书11引言2编写目的2术语表2参考资料32数据库环境说明33数据库的命名规则34逻辑设计35物理设计4表汇总4表X:XXX表4视图的设计6存储过程、函数及触发器的设计66安全性设计6防止用户直接操作数据库的方法6用户帐号密码的加密方法7角色与权限77优化78数据库管理与维护说明71 引言1.1
2、编写目的本文档是时代集团产品跟踪平台概要设计文档的组成部分,编写数据库设计文档的目的是:明确数据库的表名、字段名等数据信息,用来指导后期的数据库脚本的开发,本文档遵循SQL数据库设计和开发规范。本文档的读者对象是需求人员、系统设计人员、开发人员、测试人员。1.2 术语表序号术语或缩略语说明性定义1ESIDEnterStorageId入库编号2ProIdProductId产品编号3PMIDProductManagerId产品管理员编号1.3 参考资料资料名称作者文件编号、版本资料存放地点2 数据库环境说明数据库实例数据库系统数据库部署环境数据库设计工具数据库存放位置说明3 数据库的命名规则数据库
3、名称:时代集团的英文名称time-group表名:英文(表的用途)+下划线+英文字段名:相关属性的英文名4 逻辑设计提示:数据库设计人员根据需求文档,创建与数据库相关的那部分实体关系图(ERD)。如果采用面向对象方法(OOAD),这里实体相当于类(class)。5 物理设计提示:(1)主要是设计表结构。一般地,实体对应于表,实体的属性对应于表的列,实体之间的关系成为表的约束。逻辑设计中的实体大部分可以转换成物理设计中的表,但是它们并不一定是一一对应的。(2)对表结构进行规范化处理(第三范式)。5.1 表汇总表名功能说明Enter_storage产品入库(新产品的登记、修改、查询)Exit_st
4、orage产品出库(登记产品出库信息)Seller_info销售商信息维护表(对销售商信息的添加、修改和查询)Product_info产品信息表(对新产品的发布,修改,查询等维护)Repair_info维修表(对已出售产品的维修进行登记,修改)L管理员表(包含五种身份,销售人员,库存管理人员,售后服务人员,产品信息管理人员,系统管理员)5.2 表:表的索引: 索引是否建立要根据具体的业务需求来确定。允许为空:不填的表示为“是”。唯一:不填的表示为“是”。表的记录数和增长量:根据具体的业务需求确定。增长量应确定单位时间如果量大可以按每天,如果不大可以按每月。表字段的区别度:主要是考虑到将来在此字
5、段上建立索引类型选择时作为参考,当字段值唯一时可以不考虑,当字段值不唯一时,估算一个区别度,近似即可。例如:如果一个表的NAME字段有共2000个值,其中有1999个不同值,1999/2000=0.99 越接近1区别度越高,反之区别度越低。表的并发:根据具体的业务需求预测表的并发。1表名Enter_storage数据库用户库存管理人员主键ESID 入库产品编号其他排序字段Product,date,num,storageManagerId索引字段序号字段名称数据类型(精度范围)允许为空Y/N唯一Y/N区别度默认值约束条件/说明1ESIDintNY2ProductVarchar(50)NN3dat
6、eSmallDateTimeNN4numVarchar(50)NN5storageManagerIdVarchar(50)NYMysql脚本CREATE TABLE dbo.Enter_storage(ESID int IDENTITY(1,1) NOT NULL,product varchar(50) NOT NULL,date smalldatetime NOT NULL,num varchar(6) NOT NULL,storageManagerId nvarchar(50) NOT NULL, CONSTRAINT PK_addStorage PRIMARY KEY CLUSTERED
7、 (ESID ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY) ON PRIMARYGOSET ANSI_PADDING OFFGO记录数增长量表的并发补充说明2.表名Exit_storage数据库用户库存管理人员主键ExitStorageId 出库产品编号其他排序字段Product,date,num,storageManagerId索引字段序号字段名称数据类型(精度范围)允
8、许为空Y/N唯一Y/N区别度默认值约束条件/说明1ExitStorageIdintNY2ProductVarchar(50)NN3dateSmallDateTimeNN4numVarchar(50)NN5storageManagerIdVarchar(50)NYMysql脚本CREATE TABLE dbo.Exit_storage(ExitStorageId int IDENTITY(1,1) NOT NULL,product varchar(50) NOT NULL,date smalldatetime NOT NULL,num varchar(6) NOT NULL, CONSTRAIN
9、T PK_subStorage PRIMARY KEY CLUSTERED (ExitStorageId ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY) ON PRIMARYGOSET ANSI_PADDING OFFGO/* Object: Table dbo.Enter_storage Script Date: 01/17/2011 16:00:59 */SET ANS
10、I_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGO记录数增长量表的并发补充说明3.表名Seller_info数据库用户销售商管理员主键name 其他排序字段telephone,address,product, stockNum,stockDate,stockPrice索引字段序号字段名称数据类型(精度范围)允许为空Y/N唯一Y/N区别度默认值约束条件/说明1nameVarchar(50)NY2telephoneVarchar(50)NN3addressSmallDateTimeNN4productVarchar(50)NN5s
11、tockNumVarchar(50)NN6stockDateSmallDateTimeNN7stockPriceVarchar(50)NNMysql脚本CREATE TABLE dbo.Seller_info(name varchar(50) NOT NULL,telephone varchar(20) NOT NULL,address varchar(50) NOT NULL,product varchar(50) NOT NULL,stockNum varchar(6) NOT NULL,stockDate smalldatetime NOT NULL,stockPrice varchar
12、(10) NOT NULL, CONSTRAINT PK_maketer_Info PRIMARY KEY CLUSTERED (name ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY) ON PRIMARYGOSET ANSI_PADDING OFFGO/* Object: Table dbo.Repair_info Script Date: 12/16/2010 09:
13、59:13 */SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGO记录数增长量表的并发补充说明4. 表名Product_info数据库用户产品信息管理人员主键proId其他排序字段name,price,proDate, storage索引字段序号字段名称数据类型(精度范围)允许为空Y/N唯一Y/N区别度默认值约束条件/说明1proIdintNY2nameVarchar(50)NN3priceVarchar(50)NN4proDateSmallDateTime NN5storageVarchar(50)NYMysq
14、l脚本CREATE TABLE dbo.Product_info(proId int IDENTITY(1,1) NOT NULL,name varchar(50) NOT NULL,price varchar(6) NOT NULL,proDate smalldatetime NOT NULL,storage varchar(4) NOT NULL, CONSTRAINT PK_product_Info PRIMARY KEY CLUSTERED (proId ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DU
15、P_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY) ON PRIMARYGOSET ANSI_PADDING OFFGO/* Object: Table dbo.Login Script Date: 01/17/2011 16:00:59 */SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGO记录数增长量表的并发补充说明5.表名Repair_info数据库用户售后服务人员主键repairId 产品维修编号其他排序字段repai
16、rName,repairtel,product, customer,date,customertel索引字段序号字段名称数据类型(精度范围)允许为空Y/N唯一Y/N区别度默认值约束条件/说明1repairIdintNY2repairNameVarchar(50)NN3repairtelSmallDateTimeNN4productVarchar(50)NN5customerVarchar(50)NNdateSmallDateTimeNNcustomertelVarchar(50)NNMysql脚本CREATE TABLE dbo.Repair_info(repairId int IDENTIT
17、Y(1,1) NOT NULL,repairName nchar(10) NULL,repairtel nchar(10) NULL,product varchar(50) NOT NULL,customer varchar(20) NOT NULL,date smalldatetime NOT NULL,customertel nchar(10) NULL, CONSTRAINT PK_Table_1 PRIMARY KEY CLUSTERED (repairId ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_
18、DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY) ON PRIMARYGOSET ANSI_PADDING OFFGO/* Object: Table dbo.Product_info Script Date: 01/17/2011 16:00:59 */SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGO记录数增长量表的并发补充说明6.表名Login数据库用户管理人员主键userId 用户编号其他排序字段password
19、,userName,tel, birthday,registerTime,type索引字段序号字段名称数据类型(精度范围)允许为空Y/N唯一Y/N区别度默认值约束条件/说明1userIdintNY2passwordVarchar(50)NN3userNameSmallDateTimeNN4telVarchar(50)NN5birthdayVarchar(50)NN6registerTimeSmallDateTimeNN7typeVarchar(50)NNMysql脚本CREATE TABLE dbo.Login(userId varchar(10) NOT NULL,password varc
20、har(16) NOT NULL,userName varchar(20) NOT NULL,tel varchar(20) NOT NULL,birthday smalldatetime NOT NULL,registerTime smalldatetime NOT NULL,type nvarchar(50) NOT NULL, CONSTRAINT PK_manager_Info PRIMARY KEY CLUSTERED (userId ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = O
21、FF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY) ON PRIMARYGOSET ANSI_PADDING OFFGO记录数增长量表的并发补充说明5.3 视图的设计根据XXX产品的概要设计文档来确定。视图的命名按照xx数据库设计规范中关于视图的命名规范命名。视图的设计应注意以下几点:1 尽量减少列中使用的公式。2 去掉所有不必要的列。3 不要使同一个文档属于多个分类。4 避免使用表单公式。5.4 存储过程、函数及触发器的设计存储过程及触发器的命名按照xx数据库设计规范中关于存储过程及触发器的命名规范命名。存储过程:根据具体
22、得业务逻辑确定输入参数个数,类型,确定对哪几个表进行何种作。 在定义存储过程时,要使用其完成单一、相对集中的任务,不要定义已由其他提供功能的过程。例如:不要定义强制数据完整性的过程(使用完整性约束)。函数 :函数与存储过程非常相似,它也是存储在数据库中的对象。但是可以在SQL命令中使用函数。就好像建立自己的substr函数一样触发器 :触发器是存储在数据库中的程序,它在某一特定事件发生时执行。这些程序可以用PL/SQL和java语言编写,也可以用作c语言的调用,数据库允许用户定义这些程序,然后在相关的表,视图或者数据库动作执行insert,update或delete语句时执行。1.存储过程:C
23、REATE PROCEDURE Enter_storage_GetMaxIdASDECLARE TempID intSELECT TempID = max(ESID)+1 FROM Enter_storageIF TempID IS NULLRETURN 1ELSERETURN TempIDCREATE PROCEDURE Enter_storage_ExistsESID intASDECLARE TempID intSELECT TempID = count(1) FROM Enter_storage WHERE ESID=ESID IF TempID = 0RETURN 0ELSERETU
24、RN 1CREATE PROCEDURE Enter_storage_ADDESID int output,product varchar(50),date smalldatetime,num varchar(6),storageManagerId nvarchar(50) AS INSERT INTO Enter_storage(product,date,num,storageManagerId)VALUES(product,date,num,storageManagerIdSET ESID = IDENTITYCREATE PROCEDURE Enter_storage_UpdateESI
25、D int,product varchar(50),date smalldatetime,num varchar(6),storageManagerId nvarchar(50) AS UPDATE Enter_storage SET product = product,date = date,num = num,storageManagerId = storageManagerIdWHERE ESID=ESID CREATE PROCEDURE Enter_storage_DeleteESID int AS DELETE Enter_storageWHERE ESID=ESID CREATE
26、 PROCEDURE Enter_storage_GetModelESID int AS SELECT ESID,product,date,num,storageManagerIdFROM Enter_storageWHERE ESID=ESID CREATE PROCEDURE Enter_storage_GetList AS SELECT ESID,product,date,num,storageManagerIdFROM Enter_storageCREATE PROCEDURE Exit_storage_GetMaxIdASDECLARE TempID intSELECT TempID
27、 = max(ExitStorageId)+1 FROM Exit_storageIF TempID IS NULLRETURN 1ELSERETURN TempIDCREATE PROCEDURE Exit_storage_ExistsExitStorageId intASDECLARE TempID intSELECT TempID = count(1) FROM Exit_storage WHERE ExitStorageId=ExitStorageId IF TempID = 0RETURN 0ELSERETURN 1CREATE PROCEDURE Exit_storage_ADDE
28、xitStorageId int output,product varchar(50),date smalldatetime,num varchar(6),storageManagerId nvarchar(50) AS INSERT INTO Exit_storage(product,date,num,storageManagerId)VALUES(product,date,num,storageManagerIdSET ExitStorageId = IDENTITYCREATE PROCEDURE Exit_storage_UpdateExitStorageId int,product
29、varchar(50),date smalldatetime,num varchar(6),storageManagerId nvarchar(50) AS UPDATE Exit_storage SET product = product,date = date,num = num,storageManagerId = storageManagerIdWHERE ExitStorageId=ExitStorageId CREATE PROCEDURE Exit_storage_DeleteExitStorageId int AS DELETE Exit_storageWHERE ExitSt
30、orageId=ExitStorageId CREATE PROCEDURE Exit_storage_GetModelExitStorageId int AS SELECT ExitStorageId,product,date,num,storageManagerIdFROM Exit_storageWHERE ExitStorageId=ExitStorageId CREATE PROCEDURE Exit_storage_GetList AS SELECT ExitStorageId,product,date,num,storageManagerIdFROM Exit_storageCR
31、EATE PROCEDURE Login_ExistsuserId varchar(10)ASDECLARE TempID intSELECT TempID = count(1) FROM Login WHERE userId=userId IF TempID = 0RETURN 0ELSERETURN 1CREATE PROCEDURE Login_ADDuserId varchar(10),password varchar(16),userName varchar(20),tel varchar(20),birthday smalldatetime,registerTime smallda
32、tetime,type nvarchar(50) AS INSERT INTO Login(userId,password,userName,tel,birthday,registerTime,type)VALUES(userId,password,userName,tel,birthday,registerTime,typeCREATE PROCEDURE Login_UpdateuserId varchar(10),password varchar(16),userName varchar(20),tel varchar(20),birthday smalldatetime,registe
33、rTime smalldatetime,type nvarchar(50) AS UPDATE Login SET password = password,userName = userName,tel = tel,birthday = birthday,registerTime = registerTime,type = typeWHERE userId=userId CREATE PROCEDURE Login_DeleteuserId varchar(10) AS DELETE LoginWHERE userId=userId CREATE PROCEDURE Login_GetMode
34、luserId varchar(10) AS SELECT userId,password,userName,tel,birthday,registerTime,typeFROM LoginWHERE userId=userId CREATE PROCEDURE Login_GetList AS SELECT userId,password,userName,tel,birthday,registerTime,typeFROM LoginCREATE PROCEDURE Product_info_GetMaxIdASDECLARE TempID intSELECT TempID = max(p
35、roId)+1 FROM Product_infoIF TempID IS NULLRETURN 1ELSERETURN TempIDCREATE PROCEDURE Product_info_ExistsproId intASDECLARE TempID intSELECT TempID = count(1) FROM Product_info WHERE proId=proId IF TempID = 0RETURN 0ELSERETURN 1CREATE PROCEDURE Product_info_ADDproId int output,name varchar(50),price v
36、archar(6),proDate smalldatetime,storage varchar(4) AS INSERT INTO Product_info(name,price,proDate,storage)VALUES(name,price,proDate,storageSET proId = IDENTITYCREATE PROCEDURE Product_info_UpdateproId int,name varchar(50),price varchar(6),proDate smalldatetime,storage varchar(4) AS UPDATE Product_in
37、fo SET name = name,price = price,proDate = proDate,storage = storageWHERE proId=proId CREATE PROCEDURE Product_info_DeleteproId int AS DELETE Product_infoWHERE proId=proId CREATE PROCEDURE Product_info_GetModelproId int AS SELECT proId,name,price,proDate,storageFROM Product_infoWHERE proId=proId CRE
38、ATE PROCEDURE Product_info_GetList AS SELECT proId,name,price,proDate,storageFROM Product_infoCREATE PROCEDURE Repair_info_GetMaxIdASDECLARE TempID intSELECT TempID = max(repairId)+1 FROM Repair_infoIF TempID IS NULLRETURN 1ELSERETURN TempIDCREATE PROCEDURE Repair_info_ExistsrepairId intASDECLARE Te
39、mpID intSELECT TempID = count(1) FROM Repair_info WHERE repairId=repairId IF TempID = 0RETURN 0ELSERETURN 1CREATE PROCEDURE Repair_info_ADDrepairId int output,repairName nchar(10),repairtel nchar(10),product varchar(50),customer varchar(20),date smalldatetime,customertel nchar(10) AS INSERT INTO Rep
40、air_info(repairName,repairtel,product,customer,date,customertel)VALUES(repairName,repairtel,product,customer,date,customertelSET repairId = IDENTITYCREATE PROCEDURE Repair_info_UpdaterepairId int,repairName nchar(10),repairtel nchar(10),product varchar(50),customer varchar(20),date smalldatetime,customertel nchar(10) AS UPDATE Repair_info SET repairName = repairName,repairtel = repairtel,product = produ