Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 16th, 2011, 11:24 AM
loripino21 loripino21 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 3 loripino21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 35 sec
Reputation Power: 0
One to one Relationship

Hi,
I am new to Firebird RDBMS and I want to use Firebird database in my VisualStudio projects, with the support of Microsoft Entity Framework.
Since in my projects, luckily due to the Entity Framework, I don't have to learn the syntax of the Firebird SQL Commands, I used Firebird Maestro to create my database.
Now I have a problem: I need to create a one-to-one relationship between two tables, but Firebird Maestro allows me to create only a Foreign Key, which sets up a one-to-many relationship.
What may I do? May someone give me at least some information about how to create a one to one relationship by SQL statements?
Thanks!!

Reply With Quote
  #2  
Old June 16th, 2011, 10:48 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Give the Foreign Key field a unique index.

Why do you want a one to one?

Reply With Quote
  #3  
Old June 17th, 2011, 03:29 PM
loripino21 loripino21 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 3 loripino21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 35 sec
Reputation Power: 0
Quote:
Originally Posted by clivew
Why do you want a one to one?


There are two tables, Bill Entries (which stores the entries of the bills, by which you can also buy a cupon) and Cupons.
When I have a Bill Entry which is related to the purchase of a cupon, I need to bind that entry with a single entry of the table Cupons. I need to keep the two tables separated.

Quote:
Originally Posted by clivew
Give the Foreign Key field a unique index.

May you kindly explain me better? When I set up a Foreign Key, I may set the following fields: Foreign Colum (in the referencing table), Foreign Table, Foreign Table Columns, Update and Delete rule.

Reply With Quote
  #4  
Old June 18th, 2011, 03:56 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
I did not mean to confuse you.
Set up a unique index on the same field as the foreign key.
The unique index will prevent the database ffrom accepting duplicate values.

However, unless there is some strong reason to do otherwise, I would suggest making that field the Primary Key in both tables and then add the foreign key constraint.
That would be a superior design.

Clive

Reply With Quote
  #5  
Old June 18th, 2011, 04:51 PM
loripino21 loripino21 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 3 loripino21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 35 sec
Reputation Power: 0
Quote:
Originally Posted by clivew
However, unless there is some strong reason to do otherwise, I would suggest making that field the Primary Key in both tables and then add the foreign key constraint.
That would be a superior design.
Clive


In my case it's impossible, since the Bill Entries Table has as primary key the ID of the entry, it wouldn't make sense to set the "CuponId" as Primery Key.
Thanks for help, I will give a try tomorrow.

Reply With Quote
  #6  
Old June 18th, 2011, 09:15 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Quote:
Originally Posted by loripino21
In my case it's impossible, since the Bill Entries Table has as primary key the ID of the entry, it wouldn't make sense to set the "CuponId" as Primery Key.
Thanks for help, I will give a try tomorrow.

For the record. I did not say make CouponId the PK in both tables
Make the bill entry PK the PK of the coupons table (and drop the couponId field from the bill entries table).

Of course, you know your situation better than me. I am talking about a better technical schema design.

Clive

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > One to one Relationship

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap