This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to achieve One to One mapping between two tables

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have taken two tables Car and Registration I want to have One to One mapping between these two tables such that each car can have only One Registration .


so i had made Unique On the fORIGN KEY . Is this way correct to achive One to One on the mapping .

create table Car (
CarName Varchar2(20) primary key,
CarModel Varchar2(20)
)


create table Registration (
RegNumber Varchar2(20) primary key,
CarName Varchar2(20),
FOREIGN KEY (CarName)
REFERENCES Car(CarName)
UNIQUE(car_name))


)

Please help .
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Although carName isn't the ideal key because it could change.
 
cow clarke
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would believe that it depends on the database system product you are using, which is not job of java program.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a compliment to Jeanne's post. 'carName' doesn't even sound unique. If you just came up with this to show your idea, then its okay arguably. Otherwise, introducing a surrogate key, if there are no candidates found, is a good idea. Folks prefer surrogate keys over natural, but again it depends upon case to case. Surrogate key is the only solution, in case you have no natural candidates.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic