1、USEmasterGO/*Object:DatabaseRGBScriptDate:06/18/201108:55:58*/CREATEDATABASERGBONPRIMARY(NAME=NRGB,FILENAME=NC:ProgramFilesMicrosoftSQLServerMSSQL10.MSSQLSERVERMSSQLDATARGB.mdf,SIZE=3072KB,MAXSIZE=UNLIMITED,FILEGROWTH=1024KB)LOGONRGB_logProgramFilesMicrosoftSQLServerMSSQL10.MSSQLSERVERMSSQLDATARGB_l
2、og.ldf,SIZE=1024KB,MAXSIZE=2048GB,FILEGROWTH=10%)ALTERDATABASERGBSETCOMPATIBILITY_LEVEL=100IF(1=FULLTEXTSERVICEPROPERTY(IsFullTextInstalled)beginEXECRGB.dbo.sp_fulltext_databaseaction=enableendALTERDATABASERGBSETANSI_NULL_DEFAULTOFFALTERDATABASERGBSETANSI_NULLSOFFALTERDATABASERGBSETANSI_PADDINGOFFAL
3、TERDATABASERGBSETANSI_WARNINGSOFFALTERDATABASERGBSETARITHABORTOFFALTERDATABASERGBSETAUTO_CLOSEOFFALTERDATABASERGBSETAUTO_CREATE_STATISTICSONALTERDATABASERGBSETAUTO_SHRINKOFFALTERDATABASERGBSETAUTO_UPDATE_STATISTICSONALTERDATABASERGBSETCURSOR_CLOSE_ON_COMMITOFFALTERDATABASERGBSETCURSOR_DEFAULTGLOBALA
4、LTERDATABASERGBSETCONCAT_NULL_YIELDS_NULLOFFALTERDATABASERGBSETNUMERIC_ROUNDABORTOFFALTERDATABASERGBSETQUOTED_IDENTIFIEROFFALTERDATABASERGBSETRECURSIVE_TRIGGERSOFFALTERDATABASERGBSETDISABLE_BROKERALTERDATABASERGBSETAUTO_UPDATE_STATISTICS_ASYNCOFFALTERDATABASERGBSETDATE_CORRELATION_OPTIMIZATIONOFFALT
5、ERDATABASERGBSETTRUSTWORTHYOFFALTERDATABASERGBSETALLOW_SNAPSHOT_ISOLATIONOFFALTERDATABASERGBSETPARAMETERIZATIONSIMPLEALTERDATABASERGBSETREAD_COMMITTED_SNAPSHOTOFFALTERDATABASERGBSETHONOR_BROKER_PRIORITYOFFALTERDATABASERGBSETREAD_WRITEALTERDATABASERGBSETRECOVERYFULLALTERDATABASERGBSETMULTI_USERALTERD
6、ATABASERGBSETPAGE_VERIFYCHECKSUMALTERDATABASERGBSETDB_CHAININGOFF2.2.用户除了数据库中自动创建的dbo用户之外,还要创建如下两个用户: RGBWinUser:该用户是Windows应用程序访问数据库所使用的账号,它的权限一般仅限于查看视图和执行存储过程。 RGBASPUser:该用户是Web应用程序访问数据库所使用的账号,它的权限和RGBWinUser用户类似,即仅限于查看视图和执行存储过程。1.USERGBUserRGBWinUserScriptDate:29:15*/CREATEUSERRGBWinUserFORLOGIN
7、WOWITHDEFAULT_SCHEMA=dbo2.USERGBUserRGBASPUserScriptDate:30:46*/CREATEUSERRGBASPUserFORLOGINniWITHDEFAULT_SCHEMA=dbo GO3.表3.1.表设计概述根据教学案例功能,数据库将以员工信息为中心存储相关数据,配合SQLServer数据库系统中提供的数据管理,实现员工考勤、请假、加班管理及系统设置等业务功能。数据库设计将以存储员工信息的员工表为基础,连接多张相关表实现对以下关系的支持: 员工与请假申请 员工与加班申请 员工与考勤记录 员工与部门 员工与部门经理 员工与绩效考核记录 员工与
8、工资此外数据库中还将记录教学案例应用中需要的全局配置信息和事件日志记录。数据库系统主要的实体关系如下图:(部门表中去掉部门经理编号,在数据删除时可能会出现死锁)3.2.表tblEmployee概述表tblEmployee用于记录员工基本信息,并作为基础表与其他表联接。该表通过DeptID和Title可以确定员工部门和职位信息。当Title的值为“经理”时可以确定此员工为该部门的部门经理。USERGBTabledbo.tblEmployeeScriptDate:06/20/201117:13:37*/SETANSI_NULLSONSETQUOTED_IDENTIFIERONSETANSI_PAD
9、DINGONCREATETABLEdbo.tblEmployee( EmployeeIDintNOTNULL, Namenvarchar(50)NOTNULL, LoginNamenvarchar(20)NOTNULL, Passwordbinary(20)NULL, Emailnvarchar(50)NOTNULL, DeptIDintNULL, BasicSalaryintNULL, Titlenvarchar(50)NULL, Telephonenvarchar(50)NULL, OnhoardDatedatetimeNOTNULL, Selfintronvarchar(200)NULL
10、, VacationRemainintNULL, EmployeeLevelintNULL, PhotoImageimageNULL,CONSTRAINTPK_tblEmployeePRIMARYKEYCLUSTERED( EmployeeIDASC)WITH(PAD_INDEX=OFF,STATISTICS_NORECOMPUTE=OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ONPRIMARY)ONPRIMARYTEXTIMAGE_ONPRIMARYSETANSI_PADDINGOFFALTERTABLEdbo.
11、tblEmployeeWITHCHECKADDCONSTRAINTFK_tblEmployee_tblDepartmentFOREIGNKEY(DeptID)REFERENCESdbo.tblDepartment(DeptID)ALTERTABLEdbo.tblEmployeeCHECKCONSTRAINTFK_tblEmployee_tblDepartmentALTERTABLEdbo.tblEmployeeWITHCHECKADDCONSTRAINTFK_tblEmployee_tblEmployeeLevelFOREIGNKEY(EmployeeLevel)REFERENCESdbo.t
12、blEmployeeLevel(EmployeeLevel)ALTERTABLEdbo.tblEmployeeCHECKCONSTRAINTFK_tblEmployee_tblEmployeeLevel表定义表tblEmployee定义如下:名称类型可否为空说明备注EmployeeIDint4否员工编号自动生成Namenvarchar50员工姓名LoginNamenvarchar20员工登录名建议为英文字符,且与姓名不同Passwordbinary20可员工登录密码Email员工电子邮件DeptID员工所属部门编号BasicSalary员工基本工资Title员工职位名称可取值为“普通员工”、“
13、部门经理”、“总裁”Telephone员工电话OnboardDatedatetime8员工报到日期SelfIntronvarchar200员工自我介绍初始为空,由员工自行输入VacationRemain员工剩余假期小时数EmployeeLevel员工的级别PhotoImageimage16员工照片主键表tblEmployee的主键是EmployeeID字段,类型为int,设置自动增量。IndexPK_tblEmployeeScriptDate:06/18/201109:00:53*/ALTERTABLEdbo.tblEmployeeADDCONSTRAINTPK_tblEmployeePRIM
14、ARYKEYCLUSTERED)WITH(PAD_INDEX=OFF,STATISTICS_NORECOMPUTE=OFF,SORT_IN_TEMPDB=OFF,IGNORE_DUP_KEY=OFF,ONLINE=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ONPRIMARY外键表tblEmployee的外键有DeptID,类型为int,用于与表tblDepartment中的DeptID字段关联。DeptID字段可以为空,在此情况下表示员工不在任何部门中。表tblEmployee的外键有EmployeeLevel,类型为int,用于与表tblEmplo
15、yeeLevel中的EmployeeLevel字段关联。约束表tblEmployee中的LoginName字段建议为4-8位小写英文字符,且不能与员工姓名相同也不可以为空字符串。索引主键字段EmployeeID具有自动创建的聚集索引。3.3.表tblDepartment表tblDepartment用于记录企业内部的部门信息。每个独立的部门在该表中都对应一条记录。该表通过与tblEmployee表关联可以确定员工所属的部门。Tabledbo.tblDepartmentScriptDate:12*/CREATETABLEdbo.tblDepartment( DeptIDintNOTNULL, De
16、ptNamechar(10)NULL, Descriptionchar(50)NULL,CONSTRAINTPK_tblDepartmentPRIMARYKEYCLUSTERED DeptIDASC)ONPRIMARY表tblDepartment定义如下:部门编号DeptNamechar10部门名称Desciptionchar50部门描述表tblDepartment的主键是DeptID字段,类型为int,设置自动增量。IndexPK_tblDepartmentScriptDate:03:ALTERTABLEdbo.tblDepartmentADDCONSTRAINTPK_tblDepartme
17、ntPRIMARYKEYCLUSTERED无无其他约束主键字段DeptID具有自动创建的聚集索引。3.4.表tblSalary表tblSalary用于记录员工每月的工资信息,包括工资发放日期、工资组成等。表tblSalary通过字段EmployeeID与表tblEmployee关联。Tabledbo.tblSalaryScriptDate:12:47*/CREATETABLEdbo.tblSalary( SalaryIDintNOTNULL, SalaryTimedatetimeNOTNULL, BasicLSalaryintNULL, OvertimeSalaryintNULL, Absen
18、seSalaryintNULL, OtherSalaryintNULL,CONSTRAINTPK_tblSalaryPRIMARYKEYCLUSTERED SalaryIDASCALTERTABLEdbo.tblSalaryWITHCHECKADDCONSTRAINTFK_tblSalary_tblEmployeeFOREIGNKEY(EmployeeID)REFERENCESdbo.tblEmployee(EmployeeID)ALTERTABLEdbo.tblSalaryCHECKCONSTRAINTFK_tblSalary_tblEmployee表tblSalary定义如下:Salary
19、ID工资编号SalaryTime工资发放时间OvertimeSalary加班工资AbsenseSalary缺勤扣除OtherSalary其他工资表tblSalary的主键是SalaryID字段,类型为int,设置自动增量。IndexPK_tblSalaryScriptDate:ALTERTABLEdbo.tblSalaryADDCONSTRAINTPK_tblSalaryPRIMARYKEYCLUSTERED表tblSalary的外键是EmployeeID,类型为int,用于与表tblEmployee中的EmployeeID字段关联。主键字段SalaryID具有自动创建的聚集索引。3.5.表tblAttendance表tblAttendance用于记录员工的考勤信息(上下班时间、记录者信息等),通过字段EmployeeID与表tblEmployee关联。Tabledbo.tblAttendanceScriptDate:11:44*/CREATETABLEdbo.tblAttendance( AttendIDintNOTNULL, BreachTimedatetimeNULL, RecorderIDintNULL,
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1