之前,学习编写机房收费系统的文档时,曾写过 机房收费系统数据库概念设计模型ER图 这篇文章,现在到了机房收费系统个人版重构阶段,需要再次进行数据库的设计。可以说,之前的数据库的概念设计给我现在的设计奠定了一定的基础,但是仍然发现自己的设计中有
之前,学习编写机房收费系统的文档时,曾写过 机房收费系统数据库概念设计模型——ER图 这篇文章,现在到了机房收费系统个人版重构阶段,需要再次进行数据库的设计。可以说,之前的数据库的概念设计给我现在的设计奠定了一定的基础,但是仍然发现自己的设计中有许多不合理并且需要改进的地方。
在这次的数据库设计当中,学习了一些数据库的命名规范,重温了经典的三范式(属性原子化,避免局部依赖,避免传递依赖)。但是发现,在需求面前,一些分属两张表的字段,为了方便,还是得放到一张表中,不得不破坏三范式。
现在将自己设计的数据库分享如下:(因为自己还没真正进行机房的重构,不知道在实际应用中,这些表是否合理,还请大家提宝贵意见。)
数据库名ComputerRoomChargeSystem
学生信息表(T_StudentInfo)
名称 |
意义 |
类型 |
studentID |
学号(主键) |
Char(10) |
studentName |
姓名 |
Char(10) |
sex |
性别 |
Char(2) |
department |
系别 |
Char(20) |
grade |
年级 |
Char(10) |
class |
班级 |
Char(10) |
用户信息表(T_UserInfo)
名称 |
意义 |
类型 |
UserID |
用户名(主键) |
Char(10) |
realName |
真实姓名 |
Char(10) |
userLevel |
用户级别 |
Char(8) |
userPassword |
用户密码 |
Char(10) |
accountHolder |
开户人 |
Char(10) |
卡信息(T_CardInfo)
名称 |
意义 |
类型 |
cardID |
卡号(主键) |
Char(10) |
studentID |
学号(外键) |
Char(10) |
account |
余额 |
Decimal(10,4) |
usageState |
使用状态 |
Char(6) |
cardType |
卡类型 |
Char(8) |
registrationDate |
注册日期 |
Date |
registrationTime |
注册时间 |
Time(0) |
UserID |
用户名 |
Char(10) |
checkStatus |
结账状态 |
Bit(1) |
账单(T_AccountSheet)
名称 |
意义 |
类型 |
checkID |
结账编号(主键) |
Decimal(18,0) |
lastCardMoney |
上期充值卡金额 |
Decimal(18,4) |
currentChargeMoney |
本期充值金额 |
Decimal(18,4) |
currentReturnMoney |
本期退卡金额 |
Decimal(18,4) |
currentConsumeMoney |
本期消费金额 |
Decimal(18,4) |
currentCardMoney |
本期充值卡金额 |
Decimal(18,4) |
checkDate |
结账日期 |
Date |
checkTime |
结账时间 |
Time(0) |
userID |
用户名 |
Char(10) |
账单,我为其设置了一个结账编号,作为主键,我想在真正建表时,可以按照结账编号从大到小排列,因为在打印账单或是日结账, 周结账都是结最近的账单吧。
本期充值卡金额=上期充值卡金额+本期充值金额-本期消费金额-本期退卡金额
充值记录表(T_ChargeRecord)
名称 |
意义 |
类型 |
cardID |
卡号(外键) |
Char(10) |
chargeDate |
充值日期 |
Date |
chargeTime |
充值时间 |
Time(0) |
chargeMoney |
充值金额 |
Decimal(10,4) |
checkStatus |
结账状态 |
Bit(1) |
userID |
用户名 |
Char(10) |
退卡记录表(T_ReturnRecord)
名称 |
意义 |
类型 |
cardID |
卡号(外键) |
Char(10) |
returnDate |
退卡日期 |
Date |
returnTime |
退卡时间 |
Time(0) |
account |
退卡金额 |
Decimal(10,4) |
checkStatus |
结账状态 |
Bit(1) |
userID |
用户名 |
Char(10) |
上下机记录表(T_OnOffLineRecord)
名称 |
意义 |
类型 |
cardID |
卡号(外键) |
Char(10) |
onDate |
上机日期 |
Date |
onTime |
上机时间 |
Time(0) |
offDate |
下机日期 |
Date |
offTime |
下机时间 |
Time(0) |
offWay |
下机方式 |
Char(8) |
consumeMoney |
消费金额 |
Decimal(10,4) |
userID |
用户名 |
Char(10) |
checkStatus |
结账状态 |
Char(6) |
onFlag |
正在上机标志 |
Bit(1) |
在这个表中,我增加了结账状态这个字段,因为想到结账时,除了会结购卡数,充值金额,退卡金额,还要结消费金额。
基本数据表(T_BasicData)
名称 |
意义 |
类型 |
fixedPerCharge |
固定每小时费用 |
Decimal(10,4) |
temporaryPerCharge |
临时每小时费用 |
Decimal(10,4) |
increasingUnitTime |
递增单位时间 |
SmallInt |
leastTime |
至少上机时间 |
SmallInt |
prepareTime |
准备时间 |
SmallInt |
minMoney |
最少金额 |
Decimal(10,4) |
操作员工作记录(T_WorkLog)
名称 |
意义 |
类型 |
UserID |
用户名(外键) |
Char(10) |
LoginDate |
登录日期 |
Date |
LoginTime |
登录时间 |
Time(0) |
ExitDate |
注销日期 |
Date |
ExitTime |
注销时间 |
Time(0) |
onFlag |
正在上机标志 |
Bit(1) |
computerID |
机器名 |
Varchar(10) |

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
