I know how to create one to one relationship only problem is that it demands rows in both tables e.g. i have a table
emp_table => key1, key2, name, description
emp_address_table => key1, key2, address
system do not put mandatory constraints on address so an emp may exist without having his/her address, OR emp may have maximum one address not more that that so it seems
1:1(0) relationship
please let me know how can i do that in sql server 2008
You can’t have a constraint that enforces the existence of a child row because you can’t insert the two rows at the same time. I.e. whether you insert your employee, or employee address row first, you would have an invalid constraint at this point.
So all constraints in SQL are ‘0 or more’ and never ‘1 or more’ or ‘exactly 1’.
You can enforce a ‘0 or 1’ constraint by adding a
UNIQUEconstraint to the foreign key column in theemp_addresstable. This will ensure there can be at most oneemp_addressrow that refers to a given employee.