So, I’m into Day 4 of my C# project. I’m working on doing a C# project/task manager. I went off on a tangent creating my SQL database. But, I didn’t do it correct so everything was just failing. What did I do wrong? I didn’t setup my relationships correctly. I was tieing the unique ID of the child table to the unique ID of the parent table. When, what I should have done was create a separate row on the child table and make it the foreign key to the parent table’s unique primary key.So, for instance, say I have a table with the following rows:
Now, I have a child table with the following rows:
Now, to tie that to the parent table, I would add the following row to the second table: CompanyID and i would create a relationship between CompanyID in the first table and CompanyID in the second table. This is considered the “”First Normal Form” and “Second Normal Form” of Relational Databases.
The First Normal Form is “Remove repeating columns by creating a new table, moving the columns into the new table, and linking back to the old table in a one to many relationship”
The Second Normal Form is “Move repeating fields into a new table that contains a primary key, and relate it back to the old table using a foreign key”
The benefit of this is that repeating data is taken out of the first table and put into the second table. Since the idea is that you’ll have a One to Many relationship between Companies and Projects.