[英]Database schema design for MySQL, suggestions?
So, have the chance to do my first "real" database, just thinking to myself what I should think about... any suggestions? 因此,有机会建立我的第一个“真实”数据库,只是对自己进行思考,我应该考虑...任何建议?
Which leads me to my main question, how do I know if the database is a success at fit enough? 这就引出了我的主要问题,我如何知道数据库是否足够成功?
As you are listing general questions that need to be answered in order to go from idea to working system I'll propose that it is very important to organize them into 当您列出从构思到工作系统需要回答的一般问题时,我建议将它们组织成
1) logical design (get a clean model that represents the problem space you are trying to model) 1)逻辑设计(获取代表您要建模的问题空间的干净模型)
2) physical design (which RDBMS and storage engine, exact data types, other practical and performance related decisions) 2)物理设计(哪些RDBMS和存储引擎,确切的数据类型,其他与性能和性能有关的决策)
You are doing too much of mixing between the two. 您在两者之间做得太多了。 When you get a clean logical model and know the relationships between the entities you are modelling then the physical modelling will not be hard. 当您获得干净的逻辑模型并知道要建模的实体之间的关系时,物理建模就不会困难了。
EDIT: There are many books that deal with the steps of logical data design, but normally you would try to: 编辑:有很多书籍涉及逻辑数据设计的步骤,但是通常您会尝试:
A few of these steps need to go back and forth as you consider different ways of accomplishing certain tasks. 当您考虑完成某些任务的不同方法时,需要反复执行其中一些步骤。 For example including new attributes might make you go and analyze a new use case. 例如,包含新属性可能使您去分析新的用例。 Or a discovery of contradicting requirement might lead to a discovery of a whole new entity. 或者发现矛盾的需求可能会导致发现一个全新的实体。 Or discovering a redundancy might lead you to a discovery of undocumented process that exists (and justifies, or rather, explains percieved redundancy by redefining a seemingly duplicate attribute). 否则,发现冗余可能会导致您发现存在的未记录过程(并通过重新定义看似重复的属性来证明或确切地解释了冗余)。 Etc... 等等...
Model your data and normalise it before defining your columns. 在定义列之前,对数据建模并对其进行规范化。 This needs to be your first task even before selecting a database and table tiypes as it will allow you to get clarity about the task you are modeling. 即使在选择数据库和表类型之前,这也应该是您的第一项任务,因为这将使您对正在建模的任务更加清楚。
Select DB engine based on needs (using MySQL, know MyISAM vs InnoDB) The trade off is "query performance" v "transactions". 根据需要选择数据库引擎(使用MySQL,了解MyISAM与InnoDB)。需要权衡的是“查询性能”与“事务”。 In most cases innoDB performance is good enough and the benefits of transactions outweigh any downside. 在大多数情况下,innoDB性能足够好,事务的好处胜过任何弊端。
Create table documentation is available on the MySQL website. 创建表文档可在MySQL网站上找到。
As Unreason says "When you get a clean logical model and know the relationships between the entities you are modelling then the physical modelling will not be hard". 正如Unreason所说:“当您获得一个干净的逻辑模型并知道要建模的实体之间的关系时,物理建模就不会困难了”。
Success can be measured in various ways. 成功可以通过多种方式来衡量。 Money in your pocket, good performance on low priced hardware. 口袋里的钱,在低价硬件上的良好性能。 Lots of happy comments from users ... Like Stackoverflow:) 来自用户的许多快乐评论……例如Stackoverflow :)
1.
Selecting a RDBMS is largely a matter of preference. 1.
选择RDBMS主要是一个优先事项。 You seem to be leaning towards MySQL already. 您似乎已经倾向于MySQL。 That's okay, because MySQL is cheap and popular. 没关系,因为MySQL很便宜而且很流行。 However, you are left with not having an engine that can do transactions and full-text search at the same time (between MyISAM and InnoDB). 但是,您没有一个可以同时进行事务和全文本搜索的引擎(在MyISAM和InnoDB之间)。 Fulltext Search with InnoDB 使用InnoDB进行全文搜索
2.
(and 4) MyISAM vs InnoDB and datatypes 2.
(和4) MyISAM与InnoDB和数据类型
3.
CREATE TABLE
? 3.
CREATE TABLE
? I prefer to use a database IDE, like Toad for MySQL 我更喜欢使用数据库IDE,例如MySQL的Toad
5.
(and 6) Review of DB normalization/PKs/FKs (You'll need to use InnoDB for FKs.) 5.
(和6) 查看数据库规范化/ PK / FK (您需要将InnoDB用于FK。)
7.
You forgot indexes! 7.
您忘记了索引! Very important factor in a database. 数据库中非常重要的因素。
Yes MySQL is a good fit if you have the above requirements. 是的,如果您具有上述要求,那么MySQL非常适合。
However, as I said, with MySQL/MyISAM/InnoDB, you don't have an engine that can do full-text search AND transactions/FKs. 但是,就像我说的那样,对于MySQL / MyISAM / InnoDB,您没有能够执行全文本搜索和事务/ FK的引擎。 A simple option is to have a 2nd copy (in MyISAM) of the InnoDB tables that need full-text search capability. 一个简单的选择是拥有需要全文搜索功能的InnoDB表的第二个副本(在MyISAM中)。 You can do this because you can mix the 2 engines in the same database. 您可以执行此操作,因为您可以将两个引擎混合在同一数据库中。 Or, maybe you don't even need full-text search because LIKE
is sufficient for your application. 或者,也许您甚至不需要全文本搜索,因为LIKE
足以满足您的应用需求。
On the other hand, with SQL Server, you can have all the features, including full-text, transactions, and FKs all in one engine. 另一方面,使用SQL Server,您可以在一个引擎中拥有所有功能,包括全文本,事务和FK。
Yet another option, is to use a separate technology for indexed full-text searches. 另一种选择是使用单独的技术进行索引全文搜索。 There's a plugin for MySQL: 有一个MySQL插件:
Example: 例:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.