E/R diagram: better multiple entities or single entity with many rows with null values? - entity-relationship

I'm designing an e/r diagram for a web application and I'm having a doubt on which alternative is better between the 2 following:
3 different entities connected to 3 other entities that are basically the same, with 1 to N relations;
3 different entities connectes to 1 other entity, with 1 to N relation for each connection;
My thought is that in first option I'll have 3 tables with completely full rows, while in second option I'll have only one table but with at least 2 null attributes per row (2 of the 3 foreign keys).
I made an explicative drawing here:
example of e/r diagram

Related

SSRS One to Many Join/Lookup DataSet

In SSRS I am trying to create a table or matrix using two datasets that have a one-to-many relationship. The table/matrix needs to be tied to the one relationship and join to the many.
I initially tried to do a lookup function, but that is a one-to-one relationship and just returned one value. I'm looking to return all values and each one on a separate row. Here is an example of two datasets, I want to join on the CustomerID column and return the CountriesOfBusiness column. Is there a different function in SSRS that will do this?
Try this expression in table/matrix: (set Dataset name to be: DataSet1)
=Join(LookupSet(Fields!CustomerID.Value, Fields!CustomerID.Value, Fields!Countries.Value, "DataSet2"), VbCrlf)

Why does `has_one` in rails require a foreign key?

Consider two tables Foo and Bar and consider models based on them. Now consider a one-to-one relationship between them.
Foo contains has_one :bar in it's declaration so that we're able to access Bar from Foo's objects. But then what I don't understand is why Bar needs a foreign key referencing Foo?
Shouldn't it be easier if they just compare both the ids to get the result?
I'm assuming that there will be problems with comparing both ids and I want to know what the problems are.
The problem with ids is that they store auto-incremented values. Let's consider 2 tables students and projects.
Let's assume a student can have at most 1 project. Which means he can either have a project or not.
Now consider 2 students A & B.
students table
id name
1 A
2 B
now projects table
id name
1 P1
2 NULL
in this case A has a project named as P1 but B doesn't and we're creating a null entry just to maintain and match the id of records present in projects with the students but this is not feasible in the long term. If in a school there are 1000 students then we'll have may be 500 empty rows for 500 students who are not working on a project.
That's why adding a column in projects table is a feasible solution to reduce the size of the table and maintain relationships as well and also if you're going to delete a record then the new id won't be same as the previous one as id's are auto-incremented.
now projects table
id name student_id
1 P1 1
is more feasible and flexible as well. You can make it has_many as well because a student can work on multiple projects as well.
I hope this helps you.
You can't assume that the DB engine will add the same IDs to rows in different tables. You can (I would not recommend) make an app with such behavior and implement it with triggers and constraints, but this would be a very creative (in a negative sense) approach to relational databases.

Entity Framework Database First - Not relating models

I'm trying to create an MVC project using Datbase First Modelling in Entity Framework. The issue I have is when I have selected the tables I wish to use, the models are created but relationships are not generated. I have read somewhere that EF does not work well with composite keys which unfortunately a number of my tables are made up of.
I tried adding the associations myself through the designer but because my table has a composite key and its mapping to a table on the first portion of the composite key to a column on another table I get an error. This is because it insists on having a mapping for the second item of the composite key
e.g.
Table 1 Table 2
D_ID A_ID
FC SomeField
Description SomeField
etc... D_ID
I need to map Table 1 and 2 based on D_ID but Table 1 is made up of a composite Key of D_ID & FC
Using database first how do I get around this?
Thanks

Core Data Model Design: use a single complex Entity or group homogeneous attributes in other entities?

I am dealing with a very complex Entity which has several homogeneous attributes that could be grouped in some kind of "macro categories".
To extremely simplify lets’ think about an Entity, myCar, with only two macro categories: “financial attributes” and “physical attributes”:
Financial attributes: cost, resale value, annual expenses.
Physical attributes: height, width, weight, color.
I have two options to model it:
Option 1: Store all the attributes in a single Entity:
Single Entity: MyCar with the following attributes:
cost
resale value
annual expenses
height
width
weight
color
Option 2: Use three entities and two relationships to model it:
Entity 1: MyCar
1 to 1 relationship 1: Financials
1 to 1 relationship 2: Physicals
Entity 2: Financials
cost
resale value
annual expenses
1 to 1 relationship: myCar
Entity 3: Physicals
Height
Width
Weight
Color
1 to 1 relationship: myCar
Up to now I always used Option 1 but thinking about how the data should be displayed on a Pad, inside an UISplitViewController with “Financials” and “Physicals” options in the master side on the left and related attributes in the detail side on the right, I thought about option 2.
Which is the better approach to model this complex Entity with Core Data? Why?
The choice should be about which data you need at any time. If you always need all of the data then using multiple entities offers little value. If however you have a master view which lists only a subset of the data and a detail view which lists all data then it is very beneficial to separate the data into different entities based around that usage. This limits the amount of data that will be faulted as you scroll through the master list and improves performance.
That doesn't mean that you shouldn't also set the fetch request batch quantity which is also a massive factor in how effective and smooth your scrolling will be...

What do I miss in understanding 1NF

I have a nooby question regarding 1NF.
As I read from different sources a table is in the 1NF if it contains no repeating groups.
I understand this with the examples given online (usually with customers and contact names etc) but when it comes to my specific data I face difficulties.
I have the following fields:
ID TOW RECEIVER Phi01_L1 Phi01_L2 Phi01_L3
1 4353 gpo1 0.007 0.006 0.4
2 4353 gpo1 0.9 0.34 0.3
So, this table here is not in 1NF? How should it be in order to become?
What is Fist normal form (1NF)?
1NF- Disallows:
composite attributes
multivalued attributes
and nested relations; attributes whose values for an individual tuple are non-atomic
How to convert a relation into 1NF?
Two ways to convert into 1 NF:
Expand relation:
Increase number of colons in relation (as you did)
Increase rows and change Primary key value. (PK will include non-atomic attribute)
Hence your relation looks in 1-NF in present relation-state. and solution you made is expansion.
Break Relation:
Break relation into two relations -e.g. remove non-atomic col from base relation and create a new relation and add to new with PK.
Normal forms are best explain in Elmasri/Navath book

Resources