• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

How to achieve One to One mapping between two tables  RSS feed

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • 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 .
 
author & internet detective
Marshal
Posts: 38684
677
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Although carName isn't the ideal key because it could change.
 
Greenhorn
Posts: 15
  • 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.
 
Ranch Hand
Posts: 2874
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!