Problem with foreign key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • booker
    New Member
    • Jun 2007
    • 3

    Problem with foreign key

    Hello,
    I have a problem with foreign key. What I want to do is , have one foreign key referencing in two different tables! I have created three tables:

    create table University(
    UniversityID int not null,
    Name nvarchar(50),
    .....
    .....
    .....
    primary key(UniversityI D )
    );

    create table Person(
    PersonID int not null,
    Name nvarchar(50),
    .....
    .....
    .....
    primary key(PersonID )
    );

    create table Borrower(
    BorrowerID int not null,
    Name nvarchar(50),
    MemberName int,
    .....
    .....
    .....
    primary key(BorrowerID )
    foreign key(MemberName) reference University,
    foreign key(MemberName) reference Person,

    );

    So I want to have one column (in my example MemeberName) which referencing in two different tables. How can I do that??
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    I am not entirely sure what you are trying to accomplish, could you please reword you question a little?

    Comment

    • booker
      New Member
      • Jun 2007
      • 3

      #3
      Originally posted by Motoma
      I am not entirely sure what you are trying to accomplish, could you please reword you question a little?

      Ok, Sorry for that. Well, I have created three tables University, Person and Borrower. What I want to do is to have one column in table Borrower (lets say with name MemberId) which will be foreign key referencing together in the other two tables.
      For example I gave the below syntax in SQL Server but it does not work:

      create table Borrower(
      BorrowerID .............,
      ............... ......,
      ............... ........,
      ............... ..........,

      foreign key (MemberID) references University,
      foreign key (MemberID) references Person

      );

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        So you want the key to exist in either one of the tables? I'm not quite sure of the interaction you are looking for.

        Comment

        • booker
          New Member
          • Jun 2007
          • 3

          #5
          Originally posted by Motoma
          So you want the key to exist in either one of the tables? I'm not quite sure of the interaction you are looking for.
          ok I see. I will try to find another way. thanks

          Comment

          Working...