184

I was thinking the other day on normalization, and it occurred to me, I cannot think of a time where there should be a 1:1 relationship in a database.

  • Name:SSN? I'd have them in the same table.
  • PersonID:AddressID? Again, same table.

I can come up with a zillion examples of 1:many or many:many (with appropriate intermediate tables), but never a 1:1.

Am I missing something obvious?

Ghost4Man
  • 1,040
  • 1
  • 12
  • 19
Pulsehead
  • 5,050
  • 9
  • 33
  • 37
  • It's easier to split the database into multiple physical devices when it's separated like this. – Pacerier Jul 06 '12 at 11:46
  • And a followup question, if it does make sense, **how** to do it? Considered [here](http://stackoverflow.com/a/10292454/1175496) and [here](https://www.mssqltips.com/sqlservertip/2380/sql-server-database-design-with-a-one-to-one-relationship/) -- My question is how to choose which of the 2 tables has the Foreign Key constraint? I guess it depends on what use-case you're trying to address... – Nate Anderson Aug 03 '16 at 15:42

26 Answers26

183

A 1:1 relationship typically indicates that you have partitioned a larger entity for some reason. Often it is because of performance reasons in the physical schema, but it can happen in the logic side as well if a large chunk of the data is expected to be "unknown" at the same time (in which case you have a 1:0 or 1:1, but no more).

As an example of a logical partition: you have data about an employee, but there is a larger set of data that needs to be collected, if and only if they select to have health coverage. I would keep the demographic data regarding health coverage in a different table to both give easier security partitioning and to avoid hauling that data around in queries unrelated to insurance.

An example of a physical partition would be the same data being hosted on multiple servers. I may keep the health coverage demographic data in another state (where the HR office is, for example) and the primary database may only link to it via a linked server... avoiding replicating sensitive data to other locations, yet making it available for (assuming here rare) queries that need it.

Physical partitioning can be useful whenever you have queries that need consistent subsets of a larger entity.

Godeke
  • 16,131
  • 4
  • 62
  • 86
  • 44
    A perfect example of this might be a table that contains files. You may (for obvious reasons) want to have one table that contains only the file's meta data (file name, mime type, etc) and another table, mapped 1:1, that contains the actual blob data. This would reduce overhead in querying/sorting the files in some instances. – Kevin Peno Oct 30 '09 at 22:53
  • 2
    Yes. It depends on the database (modern designs are storing blobs in the filesystem just by using the correct type) and even with such support one has to be careful to exclude the columns (in SQL explicit column lists are normal, but some ORMs want to drag the entire record). The trick is to know your use pattern: if most of the time the actual data is ignored I would use a 1:1 blob table. If most accesses are downloads of the data I would use the native storage mechanism. – Godeke Oct 30 '09 at 23:19
  • @Ochado While I agree that you have many naturally occurring (non-physical) reasons for 1:1, the cavate "if you don't have historical information" makes those cases that I probably wouldn't use a 1:1 relationship to enforce. – Godeke Jan 11 '16 at 20:55
  • 1
    @Ochado I do think that the IS-A relationship is a good example, however. I try to avoid trying to force object oriented concepts on my tables (instead, using an ORM as a data library), but I have seen cases where I was tempted. Performance of such systems at scale killed those experiments though. Still, that is probably the best example of a non-performance related example. – Godeke Jan 11 '16 at 20:57
  • Actually, the IS-A and also the matching reservations scenarios would likely remain 1:1, even if historical data is stored. – Tripartio Jan 12 '16 at 00:19
  • Yes! It's easy to forget how 1:0 can play an important role when thinking of 1:1 relationships. A 1:0-1:1 relationship is very different to a 1:1 one. – Chuck Le Butt Jan 20 '21 at 16:01
132

One reason is database efficiency. Having a 1:1 relationship allows you to split up the fields which will be affected during a row/table lock. If table A has a ton of updates and table b has a ton of reads (or has a ton of updates from another application), then table A's locking won't affect what's going on in table B.

Others bring up a good point. Security can also be a good reason depending on how applications etc. are hitting the system. I would tend to take a different approach, but it can be an easy way of restricting access to certain data. It's really easy to just deny access to a certain table in a pinch.

My blog entry about it.

kemiller2002
  • 113,795
  • 27
  • 197
  • 251
52

Sparseness. The data relationship may be technically 1:1, but corresponding rows don't have to exist for every row. So if you have twenty million rows and there's some set of values that only exists for 0.5% of them, the space savings are vast if you push those columns out into a table that can be sparsely populated.

chaos
  • 122,029
  • 33
  • 303
  • 309
  • 10
    "but corresponding rows don't have to exist for every row" Then that's not 1:1. You're talking about 1:0,1. –  Feb 05 '09 at 23:10
  • 1
    Yeah. Dunno if the OP draws the distinction. – chaos Feb 05 '09 at 23:12
  • 2
    Well, I'd assume they did because 1:0,1 has lots of uses, including yours but 1:1 has far fewer. And they were struggling to find uses, so I'd say the OP was drawing the distinction. –  Feb 06 '09 at 17:32
  • 14
    My working assumption was the opposite because he enumerated 1:1, 1:many, and many:many without mentioning 1:0,1. – chaos Feb 06 '09 at 18:44
29

Most of the highly-ranked answers give very useful database tuning and optimization reasons for 1:1 relationships, but I want to focus on nothing but "in the wild" examples where 1:1 relationships naturally occur.

Please note one important characteristic of the database implementation of most of these examples: no historical information is retained about the 1:1 relationship. That is, these relationships are 1:1 at any given point in time. If the database designer wants to record changes in the relationship participants over time, then the relationships become 1:M or M:M; they lose their 1:1 nature. With that understood, here goes:

  • "Is-A" or supertype/subtype or inheritance/classification relationships: This category is when one entity is a specific type of another entity. For example, there could be an Employee entity with attributes that apply to all employees, and then different entities to indicate specific types of employee with attributes unique to that employee type, e.g. Doctor, Accountant, Pilot, etc. This design avoids multiple nulls since many employees would not have the specialized attributes of a specific subtype. Other examples in this category could be Product as supertype, and ManufacturingProduct and MaintenanceSupply as subtypes; Animal as supertype and Dog and Cat as subtypes; etc. Note that whenever you try to map an object-oriented inheritance hierarchy into a relational database (such as in an object-relational model), this is the kind of relationship that represents such scenarios.

  • "Boss" relationships, such as manager, chairperson, president, etc., where an organizational unit can have only one boss, and one person can be boss of only one organizational unit. If those rules apply, then you have a 1:1 relationship, such as one manager of a department, one CEO of a company, etc. "Boss" relationships don't only apply to people. The same kind of relationship occurs if there is only one store as the headquarters of a company, or if only one city is the capital of a country, for example.

  • Some kinds of scarce resource allocation, e.g. one employee can be assigned only one company car at a time (e.g. one truck per trucker, one taxi per cab driver, etc.). A colleague gave me this example recently.

  • Marriage (at least in legal jurisdictions where polygamy is illegal): one person can be married to only one other person at a time. I got this example from a textbook that used this as an example of a 1:1 unary relationship when a company records marriages between its employees.

  • Matching reservations: when a unique reservation is made and then fulfilled as two separate entities. For example, a car rental system might record a reservation in one entity, and then an actual rental in a separate entity. Although such a situation could alternatively be designed as one entity, it might make sense to separate the entities since not all reservations are fulfilled, and not all rentals require reservations, and both situations are very common.

I repeat the caveat I made earlier that most of these are 1:1 relationships only if no historical information is recorded. So, if an employee changes their role in an organization, or a manager takes responsibility of a different department, or an employee is reassigned a vehicle, or someone is widowed and remarries, then the relationship participants can change. If the database does not store any previous history about these 1:1 relationships, then they remain legitimate 1:1 relationships. But if the database records historical information (such as adding start and end dates for each relationship), then they pretty much all turn into M:M relationships.

There are two notable exceptions to the historical note: First, some relationships change so rarely that historical information would normally not be stored. For example, most IS-A relationships (e.g. product type) are immutable; that is, they can never change. Thus, the historical record point is moot; these would always be implemented as natural 1:1 relationships. Second, the reservation-rental relationship store dates separately, since the reservation and the rental are independent events, each with their own dates. Since the entities have their own dates, rather than the 1:1 relationship itself having a start date, these would remain as 1:1 relationships even though historical information is stored.

Tripartio
  • 1,955
  • 1
  • 24
  • 29
  • 2
    I really like how you stuck to the original question spirit about when such a relation is correct and not when it is useful because of earthly reasons like the physical nature of computers. – user1852503 Apr 29 '15 at 05:59
23

Your question can be interpreted in several ways, because of the way you worded it. The responses show this.

There can definitely be 1:1 relationships between data items in the real world. No question about it. The "is a" relationship is generally one to one. A car is a vehicle. One car is one vehicle. One vehicle might be one car. Some vehicles are trucks, in which case one vehicle is not a car. Several answers address this interpretation.

But I think what you really are asking is... when 1:1 relationships exist, should tables ever be split? In other words, should you ever have two tables that contain exactly the same keys? In practice, most of us analyze only primary keys, and not other candidate keys, but that question is slightly diferent.

Normalization rules for 1NF, 2NF, and 3NF never require decomposing (splitting) a table into two tables with the same primary key. I haven't worked out whether putting a schema in BCNF, 4NF, or 5NF can ever result in two tables with the same keys. Off the top of my head, I'm going to guess that the answer is no.

There is a level of normalization called 6NF. The normalization rule for 6NF can definitely result in two tables with the same primary key. 6NF has the advantage over 5NF that NULLS can be completely avoided. This is important to some, but not all, database designers. I've never bothered to put a schema into 6NF.

In 6NF missing data can be represent by an omitted row, instead of a row with a NULL in some column.

There are reasons other than normalization for splitting tables. Sometimes split tables result in better performance. With some database engines, you can get the same performance benefits by partitioning the table instead of actually splitting it. This can have the advantage of keeping the logical design easy to understand, while giving the database engine the tools needed to speed things up.

Walter Mitty
  • 18,205
  • 2
  • 28
  • 58
20

I use them primarily for a few reasons. One is significant difference in rate of data change. Some of my tables may have audit trails where I track previous versions of records, if I only care to track previous versions of 5 out of 10 columns splitting those 5 columns onto a separate table with an audit trail mechanism on it is more efficient. Also, I may have records (say for an accounting app) that are write only. You can not change the dollar amounts, or the account they were for, if you made a mistake then you need to make a corresponding record to write adjust off the incorrect record, then create a correction entry. I have constraints on the table enforcing the fact that they cannot be updated or deleted, but I may have a couple of attributes for that object that are malleable, those are kept in a separate table without the restriction on modification. Another time I do this is in medical record applications. There is data related to a visit that cannot be changed once it is signed off on, and other data related to a visit that can be changed after signoff. In that case I will split the data and put a trigger on the locked table rejecting updates to the locked table when signed off, but allowing updates to the data the doctor is not signing off on.

Another poster commented on 1:1 not being normalized, I would disagree with that in some situations, especially subtyping. Say I have an employee table and the primary key is their SSN (it's an example, let's save the debate on whether this is a good key or not for another thread). The employees can be of different types, say temporary or permanent and if they are permanent they have more fields to be filled out, like office phone number, which should only be not null if the type = 'Permanent'. In a 3rd normal form database the column should depend only on the key, meaning the employee, but it actually depends on employee and type, so a 1:1 relationship is perfectly normal, and desirable in this case. It also prevents overly sparse tables, if I have 10 columns that are normally filled, but 20 additional columns only for certain types.

Shane Delmore
  • 1,575
  • 2
  • 13
  • 19
14

The most common scenario I can think of is when you have BLOB's. Let's say you want to store large images in a database (typically, not the best way to store them, but sometimes the constraints make it more convenient). You would typically want the blob to be in a separate table to improve lookups of the non-blob data.

Tom H
  • 46,766
  • 14
  • 87
  • 128
Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
  • Seriously? Typically not the best way? The single largest online music vendor stores it's, ahem, MP3's, in a database. –  Feb 05 '09 at 23:11
  • 1
    @Mark, there are a few questions dealing with the best way to store images, either in a database or out, and the consensus seems be to that for the most part the file system is faster. I imagine if that is in fact true, then the same would be hold true for MP3s. – James McMahon Apr 14 '09 at 19:13
  • 1
    "You would typically want the BLOB in a separate table" - Usually BLOB's are not stored inline (if they exceed a certain db-specific row-length). BLOBs if not inline, are usually stored as a 'pointer' to their physical location in the DB-pages. – blispr Jul 18 '09 at 22:18
  • 1
    It is arguable whether it makes sense to store large data (files) in a database, some are for some are against all have valid reasons, but +1 for the example of a 1:1. – Kevin Peno Oct 30 '09 at 22:57
  • This should really be its own question that I would like to see. With input from smart people who measure the time/prestanda for different harddrives/OS/RDBMS. There SHOULD be an definitive answer to this question, it should not be arguable, if measured correctly. Have'nt anyonw done it allready? – Stefan Jul 06 '10 at 20:57
9

In terms of pure science, yes, they are useless.

In real databases it's sometimes useful to keep a rarely used field in a separate table: to speed up queries using this and only this field; to avoid locks, etc.

Quassnoi
  • 413,100
  • 91
  • 616
  • 614
  • 3
    @Mark Brady: no, it doesn't, as there are Na2SO4 and KCl. When making a universe database, you should create t_atom (id INT, protons INT, neutrons INT), t_molecule (id INT, atom_id INT) and make joins. It's a one-to-many relationship. – Quassnoi Feb 06 '09 at 08:35
  • 2
    On a second thought, INT might not suffice here, as there are 10^78 atoms in the universe. Even two GUID's glued together can hold only 1/10th of the atoms. We'll need a RAW(40) primary key — just in case our database will grow too fast. Dark matter, you know, of something. – Quassnoi Feb 06 '09 at 12:03
  • 1
    Oh, so only relational theory is pure science. Didn't realize that chemistry wasn't a pure science unless we built a database for it. –  Feb 06 '09 at 17:35
  • 1
    @Mark Brady: couldn't you please just say what is that you don't agree with? I don't get your sarcasm, really :) – Quassnoi Feb 06 '09 at 17:49
  • Quassnoi (and Mark Brady) You get an upvote for the LOL you just gave me. – Pulsehead Feb 06 '09 at 18:23
  • @Mark Brady: Actually, NaCl is better described as a cubic crystal of alternating Na and Cl atoms. The NaCl formula is a handy abbreviation, and works on chemical equations, but it's not actually the true stuff. I don't think that anyone has actually seen a distinct NaCl molecule. – Adriano Varoli Piazza Aug 03 '09 at 17:05
  • @Adriano: not a problem, it will just take a `CONNECT BY` query. – Quassnoi Aug 03 '09 at 17:10
  • Well if you really really really meant pure science, then a proper quantum mechanical characterization of the Na and Cl atoms would be sufficient to specify the structure of the NaCL molecule as well as it's chemical constituents. This may be a very small set of numbers... so your database would perhaps not grow too fast. – Eric M Sep 08 '09 at 22:41
  • By "pure science" do you mean "a pure relational model that is fully normalized"? Also, 1:1 can often mean 1:0..1, which makes perfect sense in relational database theory. – Merlyn Morgan-Graham Apr 18 '12 at 07:53
  • @MerlynMorgan-Graham No, by "pure science" he means in a world where storage is unlimited, latency is 0, bandwidth is unlimited, CPU is infinitely fast, and devices never spoil. Better put: "a *theoretical* world". – Pacerier Jul 06 '12 at 11:51
  • I assume that by "pure science" he means that other than database efficiency reasons, they are useless. if that is what is meant here, then it is patently wrong. There are numerous real world 1:1 relationships, as many of the other answers show, e.g. @Walter Mitty – Tripartio Feb 04 '15 at 03:20
9

Rather than using views to restrict access to fields, it sometimes makes sense to keep restricted fields in a separate table to which only certain users have access.

eleven81
  • 6,301
  • 11
  • 37
  • 48
8

I can also think of situations where you have an OO model in which you use inheritance, and the inheritance tree has to be persisted to the DB.

For instance, you have a class Bird and Fish which both inherit from Animal. In your DB you could have an 'Animal' table, which contains the common fields of the Animal class, and the Animal table has a one-to-one relationship with the Bird table, and a one-to-one relationship with the Fish table.

In this case, you don't have to have one Animal table which contains a lot of nullable columns to hold the Bird and Fish-properties, where all columns that contain Fish-data are set to NULL when the record represents a bird.

Instead, you have a record in the Birds-table that has a one-to-one relationship with the record in the Animal table.

Frederik Gheysels
  • 56,135
  • 11
  • 101
  • 154
8

1-1 relationships are also necessary if you have too much information. There is a record size limitation on each record in the table. Sometimes tables are split in two (with the most commonly queried information in the main table) just so that the record size will not be too large. Databases are also more efficient in querying if the tables are narrow.

HLGEM
  • 94,695
  • 15
  • 113
  • 186
7

In SQL it is impossible to enforce a 1:1 relationship between two tables that is mandatory on both sides (unless the tables are read-only). For most practical purposes a "1:1" relationship in SQL really means 1:0|1.

The inability to support mandatory cardinality in referential constraints is one of SQL's serious limitations. "Deferrable" constraints don't really count because they are just a way of saying the constraint is not enforced some of the time.

nvogel
  • 24,981
  • 1
  • 44
  • 82
6

It's also a way to extend a table which is already in production with less (perceived) risk than a "real" database change. Seeing a 1:1 relationship in a legacy system is often a good indicator that fields were added after the initial design.

J.T. Grimes
  • 4,222
  • 1
  • 28
  • 32
  • Why equivocate? Do you think that a brand spankin new table has as much risk as altering an existing table. Please list the things that break when new tables are added. The only thing I can think of is code that operates over metadata i.e. SELECT * From USER_TABLES loop end loop. –  Feb 05 '09 at 23:24
  • 1
    It's less that things will break than that it often takes more work to add a 1:1 table properly than to add an extra field. Now a new record means updating two tables instead of just one. Deleting a record? Two queries as well. Now we're maintaining more code instead of changing it once. – J.T. Grimes Feb 07 '09 at 05:43
  • @Mark Brady, strongly typed datasets can be a hell to manage when adding a couple of fileds in the database. If a tableadapter in the dataset has many querys and so on, its much more easy to just drag in the new table and then its done. – Stefan Jul 06 '10 at 21:05
  • @Stefan: There's no Cascade insert. – J.T. Grimes Jul 07 '10 at 21:19
  • @Boofus, well.. sometimes we do have to use the keyboard and program a little for the money we earn. ;) – Stefan Jul 08 '10 at 03:08
  • One good reason to extend by adding a second table, as suggested here, is backwards compatibility with existing objects. If you're running multiple versions of your code (as we often do) and you want to add a required field with no sensible default and keep the old code running, adding a second table is often the way to go. – Software Engineer Dec 15 '15 at 02:15
5

Most of the time, designs are thought to be 1:1 until someone asks "well, why can't it be 1:many"? Divorcing the concepts from one another prematurely is done in anticipation of this common scenario. Person and Address don't bind so tightly. A lot of people have multiple addresses. And so on...

Usually two separate object spaces imply that one or both can be multiplied (x:many). If two objects were truly, truly 1:1, even philosophically, then it's more of an is-relationship. These two "objects" are actually parts of one whole object.

Tom H
  • 46,766
  • 14
  • 87
  • 128
Mark Canlas
  • 9,385
  • 5
  • 41
  • 63
4

If you're using the data with one of the popular ORMs, you might want to break up a table into multiple tables to match your Object Hierarchy.

Restore the Data Dumps
  • 38,967
  • 12
  • 96
  • 122
  • 3
    Sad, sad reason. If an ORM can't handle a divergence between the object model and the physical storage then.... just sad. –  Feb 05 '09 at 23:16
  • Actually, if I understand correctly, this means implementing classification heirarchies in the relational database. This is a perfectly legitimate and natural case of 1:1 relationships; there is nothing "sad" about it. – Tripartio Oct 13 '15 at 15:57
4

I have found that when I do a 1:1 relationship its totally for a systemic reason, not a relational reason.

For instance, I've found that putting the reserved aspects of a user in 1 table and putting the user editable fields of the user in a different table allows logically writing those rules about permissions on those fields much much easier.

But you are correct, in theory, 1:1 relationships are completely contrived, and are almost a phenomenon. However logically it allows the programs and optimizations abstracting the database easier.

DevelopingChris
  • 39,797
  • 30
  • 87
  • 118
  • phenomenon: is any fact or event of scientific interest that is susceptible of being scientifically described and/or explained. I do not think you meant to use that word. –  Feb 05 '09 at 23:20
  • 1
    I did mean to use it, in its connotation, of being a rare thing. Typically phenomenon is used to describe outliers, even though its definition, defines your very need to correct every word in my post. – DevelopingChris Feb 09 '09 at 20:04
  • @DevelopingChris I agree that 1:1's are a phenomomenon. Except for school theory there are very few real world situations that exist. – Michael Riley - AKA Gunny Oct 31 '09 at 01:20
3

extended information that is only needed in certain scenarios. in legacy applications and programming languages (such as RPG) where the programs are compiled over the tables (so if the table changes you have to recompile the program(s)). Tag along files can also be useful in cases where you have to worry about table size.

Ryan Guill
  • 13,558
  • 4
  • 37
  • 48
2

The best reason I can see for a 1:1 relationship is a SuperType SubType of database design. I created a Real Estate MLS data structure based on this model. There were five different data feeds; Residential, Commercial, MultiFamily, Hotels & Land.

I created a SuperType called property that contained data that was common to each of the five separate data feeds. This allowed for very fast "simple" searches across all datatypes.

I create five separate SubTypes that stored the unique data elements for each of the five data feeds. Each SuperType record had a 1:1 relationship to the appropriate SubType record.

If a customer wanted a detailed search they had to select a Super-Sub type for example PropertyResidential.

2

Most frequently it is more of a physical than logical construction. It is commonly used to vertically partition a table to take advantage of splitting I/O across physical devices or other query optimizations associated with segregating less frequently accessed data or data that needs to be kept more secure than the rest of the attributes on the same object (SSN, Salary, etc).

The only logical consideration that prescribes a 1-1 relationship is when certain attributes only apply to some of the entities. However, in most cases there is a better/more normalized way to model the data through entity extraction.

JohnFx
  • 34,542
  • 18
  • 104
  • 162
1

In my opinion a 1:1 relationship maps a class Inheritance on a RDBMS. There is a table A that contains the common attributes, i.e. the partent class status Each inherited class status is mapped on the RDBMS with a table B with a 1:1 relationship to A table, containing the specialized attributes. The table namend A contain also a "type" field that represents the "casting" functionality

Bye Mario

1

You can create a one to one relationship table if there is any significant performance benefit. You can put the rarely used fields into separate table.

kta
  • 19,412
  • 7
  • 65
  • 47
0

Possibly if you have some kind of typed objects in your database.

Say in a table, T1, you have the columns C1, C2, C3… with a one to one relation. It's OK, it's in normalized form. Now say in a table T2, you have columns C1, C2, C3, … (the names may differ, but say the types and the role is the same) with a one to one relation too. It's OK for T2 for the same reasons as with T1.

In this case however, I see a fit for a separate table T3, holding C1, C2, C3… and a one to one relation from T1 to T3 and from T2 to T3. I even more see a fit if there exist another table, with which there already exist a one to multiple C1, C2, C3… say from table A to multiple rows in table B. Then, instead of T3, you use B, and have a one to one relation from T1 to B, the same for from T2 to B, and still the same one to multiple relation from A to B.

I believe normalization do not agree with this, and that may be an idea outside of it: identifying object types and move objects of a same type to their own storage pool, using a one to one relation from some tables, and a one to multiple relation from some other tables.

Hibou57
  • 6,870
  • 6
  • 52
  • 56
0

It is unnecessary great for security purposes but there better ways to perform security checks. Imagine, you create a key that can only open one door. If the key can open any other door, you should ring the alarm. In essence, you can have "CitizenTable" and "VotingTable". Citizen One vote for Candidate One which is stored in the Voting Table. If citizen one appear in the voting table again, then their should be an alarm. Be advice, this is a one to one relationship because we not refering to the candidate field, we are refering to the voting table and the citizen table.

Example:

 Citizen Table
 id = 1, citizen_name = "EvryBod"
 id = 2, citizen_name = "Lesly"
 id = 3, citizen_name = "Wasserman"

 Candidate Table
 id = 1, citizen_id = 1, candidate_name = "Bern Nie"
 id = 2, citizen_id = 2, candidate_name = "Bern Nie"
 id = 3, citizen_id = 3, candidate_name = "Hill Arry"

Then, if we see the voting table as so:

 Voting Table
 id = 1, citizen_id = 1, candidate_name = "Bern Nie"
 id = 2, citizen_id = 2, candidate_name = "Bern Nie"
 id = 3, citizen_id = 3, candidate_name = "Hill Arry"
 id = 4, citizen_id = 3, candidate_name = "Hill Arry"
 id = 5, citizen_id = 3, candidate_name = "Hill Arry"

We could say that citizen number 3 is a liar pants on fire who cheated Bern Nie. Just an example.

Lesly Revenge
  • 894
  • 10
  • 16
0

1:1 relationships don't really make sense if you're into normalization as anything that would be 1:1 would be kept in the same table.

In the real world though, it's often different. You may want to break your data up to match your applications interface.

Eppz
  • 3,178
  • 2
  • 19
  • 26
  • I disagree with the one table theory. There are times when a SuperType SubType relationship is best expressed with 1:1 relationships. – Michael Riley - AKA Gunny Oct 31 '09 at 01:12
  • 1
    Actually, if you went for extreme normalization then you would have a lot more 1:1 relationships. Early forms of normalization proposed by Date included the rule that no column should allow NULL. That meant that if a column might be NULL for a table then it should be in its own table and a row added only when it was valued. This rule has been mostly discarded, including by Codd. – Tom H Jul 06 '10 at 20:25
0

When you are dealing with a database from a third party product, then you probably don't want to alter their database as to prevent tight coupling. but you may have data that corresponds 1:1 with their data

symbiont
  • 1,428
  • 3
  • 21
  • 27
-4

Anywhere were two entirely independent entities share a one-to-one relationship. There must be lots of examples:

person <-> dentist (its 1:N, so its wrong!)

person <-> doctor (its 1:N, so it's also wrong!)

person <-> spouse (its 1:0|1, so its mostly wrong!)

EDIT: Yes, those were pretty bad examples, particularly if I was always looking for a 1:1, not a 0 or 1 on either side. I guess my brain was mis-firing :-)

So, I'll try again. It turns out, after a bit of thought, that the only way you can have two separate entities that must (as far as the software goes) be together all of the time is for them to exist together in higher categorization. Then, if and only if you fall into a lower decomposition, the things are and should be separate, but at the higher level they can't live without each other. Context, then is the key.

For a medical database you may want to store different information about specific regions of the body, keeping them as a separate entity. In that case, a patient has just one head, and they need to have it, or they are not a patient. (They also have one heart, and a number of other necessary single organs). If you're interested in tracking surgeries for example, then each region should be a unique separate entity.

In a production/inventory system, if you're tracking the assembly of vehicles, then you certainly want to watch the engine progress differently from the car body, yet there is a one to one relationship. A care must have an engine, and only one (or it wouldn't be a 'car' anymore). An engine belongs to only one car.

In each case you could produce the separate entities as one big record, but given the level of decomposition, that would be wrong. They are, in these specific contexts, truly independent entities, although they might not appear so at a higher level.

Paul.

Paul W Homer
  • 2,728
  • 1
  • 19
  • 25
  • A dentist on has one patient? A doctor has only one patient? Person to spouse in only 1:1 if you put 1 spouse in one table and the other spouse in another (I was about to say men in one and women in the other. oh well) –  Feb 05 '09 at 23:33
  • Mark, you could just do a "Couples" table where rows always comes in pairs. But otherwise I agree with your, ehm... rant. :P – JohannesH Feb 06 '09 at 10:54
  • Yea, I agree with Mark too. :-) (I'm I allowed to dis my own stupid answer?) – Paul W Homer Feb 06 '09 at 16:32
  • Yeh, owning up to the "dumbness" proves how smart you are. The real cowards delete their dumb answers... good thing they aren't doctors, erasing medical records. Actually, it's a good thing we aren't either; reboot would be a bad medical treatment. –  Feb 06 '09 at 17:29
  • Duh, I could have deleted it? :-) – Paul W Homer Feb 06 '09 at 17:52
  • 3
    I've always figured that even the world's smartest person (whoever that may be at this time) still has their moments of udder stupidity. It's a human curse :-) Whereas my computer has its moments of near intelligence. – Paul W Homer Feb 06 '09 at 17:55