![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
When I use a single table I can easily use constraints to enforce my business logic, but what do I do when I normalize a single table into multiple tables. For example, imagine that my initial table has the columns ID, Name, Salary with the constraint that Salary is not NULL. Now imagine that I break this into two tables, one with ID and Name and another with ID and Salary. I would like to have a constraint that prevents the creation of a row with (ID,Name) in the first table unless a corresponding row in the second table is also created. I can enforce this logic with triggers, but it looks ugly and is fairly brittle. Is there a better way or is this the dark side of normalization? |
#3
| ||||
| ||||
|
|
When I use a single table I use constraints to enforce my business logic, but what do I do when I normalize a single table into multip can easilyle tables. |
|
For example, imagine that my initial table has the columns ID, Name, Salary with the constraint that Salary is not NULL. |
|
Now imagine that I break this into two tables, one with ID and Name and another with ID and Salary. |
|
I would like to have a constraint that prevents the creation of a row with (ID,Name) in the first table unless a corresponding row in the second table is also created. |
#4
| |||
| |||
|
|
For example, imagine that my initial table has the columns ID, Name, Salary with the constraint that Salary is not NULL. Your data element names are all wrong. There is no such magical creature as a Universal ID; this is OO or file system record numbers. Name of what? Employee, maybe? Salary_type? Salary_amt? In fact, we have no ideas what the name of this table is!! |
#5
| |||
| |||
|
|
Emin's question was apparently of a generic nature, and his table was just an example. |
|
There is no reason to call it CheeseID, AppleID, or WhateverID; that would only distract attention from what the example is intended to discuss. |
|
-- Erland Sommarskog, SQL Server MVP, esq... (AT) sommarskog (DOT) se Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books... Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx |
#6
| |||
| |||
|
|
Dear Experts, When I use a single table I can easily use constraints to enforce my business logic, but what do I do when I normalize a single table into multiple tables. For example, imagine that my initial table has the columns ID, Name, Salary with the constraint that Salary is not NULL. Now imagine that I break this into two tables, one with ID and Name and another with ID and Salary. I would like to have a constraint that prevents the creation of a row with (ID,Name) in the first table unless a corresponding row in the second table is also created. I can enforce this logic with triggers, but it looks ugly and is fairly brittle. Is there a better way or is this the dark side of normalization? Thanks. |
#7
| |||
| |||
|
|
Emin's question was apparently of a generic nature, and his table was just an example. Because good specs are important; because there is no such thing as a "generic table"; because we need to know if the FDs would allow that table to be split like he was trying to do. There is no reason to call it CheeseID, AppleID, or WhateverID; that would only distract attention from what the example is intended to discuss. So, how do you find the FDs and make a rational decision about this nameless table? If he had given us real-world names, then we could guess. What we had was (id -> name; id -> salary) or (id -> name; name -> salary) or ((name,salary)-> id) or etc. If we keep giving these newbies kludges instead of showing them that their questions are not properly formed, then they are going think what they are doing is just fine and never learn RDBMS. |

![]() |
| Thread Tools | |
| Display Modes | |
| |