OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

HELP failing with relationships

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base
View previous topic :: View next topic  
Author Message
el_tonio
Newbie
Newbie


Joined: 04 Dec 2011
Posts: 1

PostPosted: Sun Dec 04, 2011 7:00 am    Post subject: HELP failing with relationships Reply with quote

Hey,
I'm trying to link 2 tables and failing, every set of fields I try to link returns:

Quote:
Primary or unique constraint required on main table: "y" in statement [ALTER TABLE "x" ADD FOREIGN KEY ("Surname") REFERENCES "y" (Surname")]


So I looked on the Internet for some tutorials but non that help me with the issue.
Help would be much appreciated
Back to top
View user's profile Send private message
mgroenescheij
Super User
Super User


Joined: 20 Apr 2011
Posts: 870
Location: Australia

PostPosted: Tue Dec 06, 2011 3:47 am    Post subject: Reply with quote

Hi,

Edit the table and add a Primary Key to the tables.

BTW it is useful if you give some information on the OS, OpenOffice version and Database you use.

Martin
_________________
If your problem has been solved please add "[Solved]" to the beginning of your first post title (edit button).
Back to top
View user's profile Send private message
hollyneal
Newbie
Newbie


Joined: 19 Jan 2012
Posts: 3

PostPosted: Thu Jan 19, 2012 4:33 pm    Post subject: Failing at relationships Reply with quote

I saw another thread on this but it didn't answer my question. I'm getting a Primary and Unique Constraint message.

I've got two tables:

Table 1
Name and SSN.

Table 2
Bname and Birthday

I want to relate Name and Bname. I'm confused as to why I wouldn't be able to do this.

I'm using OpenOffice version 3.3.0.

Any help will be much appreciated. Thanks.
Back to top
View user's profile Send private message
mgroenescheij
Super User
Super User


Joined: 20 Apr 2011
Posts: 870
Location: Australia

PostPosted: Thu Jan 19, 2012 10:51 pm    Post subject: Reply with quote

Hi,

The Primary and Unique Constraint message tells you that you don't have a Primary Key.
This Key should be Unique.
In both Tables you have to add a Primary Key.
In Table 2 you need to Replace the Name with the corresponding Primary Key from Table 1.
Make sure you assign Field Type Integer to the Keys.

Martin
_________________
If your problem has been solved please add "[Solved]" to the beginning of your first post title (edit button).
Back to top
View user's profile Send private message
hollyneal
Newbie
Newbie


Joined: 19 Jan 2012
Posts: 3

PostPosted: Fri Jan 20, 2012 3:47 pm    Post subject: Reply with quote

Ok. I now have tables with an auto-enter ID field as the primary key.

How do I set up foreign keys?
Back to top
View user's profile Send private message
mgroenescheij
Super User
Super User


Joined: 20 Apr 2011
Posts: 870
Location: Australia

PostPosted: Fri Jan 20, 2012 6:31 pm    Post subject: Reply with quote

Hi,

Assume your tables are something like:
Quote:
Table 1
ID Integer AutoValue Primary Key
Name VARCHAR(50)
SSN VARCHAR(50)

Table 2
ID Integer AutoValue Primary Key
Name Integer
Bname VARCHAR(50)
Birthday DATE


Now select Tools --> Relationships add the two tables and select ID from Table 1 and drag it to Name in Table 2

That's all.

Martin
_________________
If your problem has been solved please add "[Solved]" to the beginning of your first post title (edit button).
Back to top
View user's profile Send private message
hollyneal
Newbie
Newbie


Joined: 19 Jan 2012
Posts: 3

PostPosted: Sat Jan 21, 2012 6:34 am    Post subject: More on relationships Reply with quote

Thank you Martin. I really appreciate your help.

Now what I'm trying to do is have one record in tblSSN to match multiple records in a different table, say tblPetOwnership. I have multiple pets and I want each record in tblSSN to be related to multiple records in t/lPetOwnership. The only data those records have in common is the name.

I've got multiple tables and they all have the name field in common. Suppose I want to look at everything that has my name on it? I know I can do that with a query but that limits it to coding the name I'm looking for in the query itself. Is there a way to make the query dynamic? So when I run it, it asks me what name I'm looking for? That might solve my problem if it would work...

Thanks again,

Holly
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group