database-design

How to best represent an attribute that appears in both master and detail records?

匆匆过客 提交于 2019-12-25 18:41:40
问题 I have a simple master-detail relation in which both entities share an attribute (which happens to be a timestamp, and is not part of the key.) The detail records are ranked (by some other attribute) from top to bottom. The business rule is: (a) If there are detail records, apply the timestamp of the top one to the master; (b) otherwise, the master must have a timestamp regardless; and (c) (rarely) permit the master to have a timestamp that differs from the that of the top detail records. The

Rails database setup Polymorphism

我只是一个虾纸丫 提交于 2019-12-25 18:28:39
问题 We have to create a request system which will have roughly 10 different types of requests. All of these requests will belong to the 'accounting' aspect of our application. Therefore we've called them "Accounting requests". All requests share maybe only a few columns and each has up to 20 columns individually. We started to wonder if having separate tables for each request type would be practical in terms of speed when we start to have to do very complicated joins or queries, for example,

Single attribute primary key and second normal form (2NF)

回眸只為那壹抹淺笑 提交于 2019-12-25 18:20:18
问题 I am not sure if this statement is true or false: "A table with a single attribute primary key is automatically in at least second normal form (2NF)." I think it is TRUE but I cannot justify why. 回答1: For a table to be in first normal form,an attribute of a table cannot have multiple values For example , id mobile_number age ------------------------------ 1 9xxx5xxxxx 25 9xxx6xxxxx 2 8xxxx5xxxx 26 7xxxx5xxxx This can be normalized to 1NF as follows, id mobile_number age ----------------------

Why does the m: n relationship in the DB design have to create a new relation?

梦想的初衷 提交于 2019-12-25 17:45:26
问题 I recently learned about DB design. However, in the m: n relation, we need to create a new relation. I do not understand this reason well. I also wonder why I place a foreign key in n relations instead of 1 when I have a 1: n relationship. 回答1: Originally, Chen's method for mapping the entity-relationship model to the relational model prescribed that every relationship map to a separate relation (table). However, it's become common practice to denormalize one-to-one and one-to-many

Creating an entity relationship diagram

别说谁变了你拦得住时间么 提交于 2019-12-25 14:40:14
问题 I've created this ERD: But now I want to add some more information to my diagram, but I do not how I should do that. I want to modify my previous ERD, I need to register what recipe was made by what chef in each program. Also, I want to identify what ingredient and tool were used in each step of the recipe. 回答1: I think implementing your Entity Relationship Diagram into Microsoft Access can be a good start. You've clearly defined the relations between each entity and have declared attributes

Entity and Relationship Set

北慕城南 提交于 2019-12-25 14:05:07
问题 I am confused about "entity set" and "relationship set". I am aware of "entity" and "relationship". Is there any clear example for entity set and relationship set which shows the real use cases of these terms? ___________ /\ ___________ | | / \ | | | Teacher |-------- /Tea \--------| Student | |___________| \che / |___________| \s / \/ In the above diagram Teacher and Student are entities and Teaches is a relationship. 回答1: Originally in Entity-Relationship Modeling: An entity is an

EAV - in an ecommerce case, is it really an anti-pattern?

点点圈 提交于 2019-12-25 13:18:00
问题 I'm in the process of building a new system which will require an extendable data model. It's quite complex, but the part of the system which requires this structure is very relatable to the product part of an ecommerce system, so I'll use that as a case. Imagine a set of companies. Each company has a range of products, which has some basic attributes such as name , sku , description , price etc. Alongside these basic attributes, the company should be able to create n custom product

Normalize a table with a two-column primary key and one other column

一曲冷凌霜 提交于 2019-12-25 12:04:23
问题 My DataTable has 3 columns: A, B and C. None are guaranteed to have unique entries, in non-trivial cases every column will have non-unique entries. The combination of {A, B} is guaranteed to be unique. Because ADO.NET DataTable allows using multiple columns as the primary key, I use A and B as my primary key. A vs B represents a matrix with 0 as the default value, so it's possible for me to guarantee that entries of B will come from a finite pool and for each entry of A, every possible {A, B}

Normalize a table with a two-column primary key and one other column

那年仲夏 提交于 2019-12-25 12:04:20
问题 My DataTable has 3 columns: A, B and C. None are guaranteed to have unique entries, in non-trivial cases every column will have non-unique entries. The combination of {A, B} is guaranteed to be unique. Because ADO.NET DataTable allows using multiple columns as the primary key, I use A and B as my primary key. A vs B represents a matrix with 0 as the default value, so it's possible for me to guarantee that entries of B will come from a finite pool and for each entry of A, every possible {A, B}

Database modeling, stock and product variant

我怕爱的太早我们不能终老 提交于 2019-12-25 09:37:23
问题 These are requirements. Multiple sellers are selling product variants. Multiple sellers can sell single product variant at the same time. (This requirement can be relaxed if it makes db modeling much simpler.) The following modeling satisfies the above two requirements. ProductVariant * id Stock * id * product_variant * seller * quantity * prices There's another requirement Multiple variants might need to share quantity among them. For instance, a teacher(seller) list his/her product as the