dbTalk Databases Forums  

SQL - Foreign key with references of multiple tables with same primary key field

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss SQL - Foreign key with references of multiple tables with same primary key field in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chirag
 
Posts: n/a

Default SQL - Foreign key with references of multiple tables with same primary key field - 04-08-2007 , 11:48 PM






I want to create a table with

member id(primary key for Students,faculty and staff [Tables])

and now i want to create issues[Tables] with foreign key as member id
but in references i could not able to pass on reference as or
condition for students, faculty and staff.

Thank You,
Chirag


Reply With Quote
  #2  
Old   
Ed Murphy
 
Posts: n/a

Default Re: SQL - Foreign key with references of multiple tables with sameprimary key field - 04-09-2007 , 01:30 AM






Chirag wrote:

Quote:
I want to create a table with

member id(primary key for Students,faculty and staff [Tables])

and now i want to create issues[Tables] with foreign key as member id
but in references i could not able to pass on reference as or
condition for students, faculty and staff.
Create a Members table, then have all the other tables reference it.


Reply With Quote
  #3  
Old   
M A Srinivas
 
Posts: n/a

Default Re: SQL - Foreign key with references of multiple tables with same primary key field - 04-09-2007 , 01:34 AM



On Apr 9, 9:48 am, "Chirag" <chirag.dpa... (AT) gmail (DOT) com> wrote:
Quote:
I want to create a table with

member id(primary key for Students,faculty and staff [Tables])

and now i want to create issues[Tables] with foreign key as member id
but in references i could not able to pass on reference as or
condition for students, faculty and staff.

Thank You,
Chirag
Two options

1. Create multiple member tables
member_student,member_faculty,member_staff and
issues_student,issues_faculty,issues_staff

2. Create a new column called flag in both the tables like
Create table member ( memberid iNT, Flag Char(1) --S - Student,
F- Faculty, T - Staff)

Primary Key (flag,memberid)
Create table Issues (memberid INT, Flag Char(1) -- S - Student, F-
Faculty, T- Staff)
Primary Key (flag,memberid)

Now Reference two tables with flag and memberid.

If you want to refernce member table with student,faculty,staff you
need to handle in trigger





Reply With Quote
  #4  
Old   
nehajain.cse@gmail.com
 
Posts: n/a

Default Re: SQL - Foreign key with references of multiple tables with same primary key field - 04-19-2007 , 06:06 AM



On Apr 8, 11:34 pm, "M A Srinivas" <masri... (AT) gmail (DOT) com> wrote:
Quote:
On Apr 9, 9:48 am, "Chirag" <chirag.dpa... (AT) gmail (DOT) com> wrote:

I want to create a table with

member id(primary key for Students,faculty and staff [Tables])

and now i want to create issues[Tables] with foreign key as member id
but in references i could not able to pass on reference as or
condition for students, faculty and staff.

Thank You,
Chirag

Two options

1. Create multiple member tables
member_student,member_faculty,member_staff and
issues_student,issues_faculty,issues_staff

2. Create a new column called flag in both the tables like
Create table member ( memberid iNT, Flag Char(1) --S - Student,
F- Faculty, T - Staff)

Primary Key (flag,memberid)
Create table Issues (memberid INT, Flag Char(1) -- S - Student, F-
Faculty, T- Staff)
Primary Key (flag,memberid)

Now Reference two tables with flag and memberid.

If you want to refernce member table with student,faculty,staff you
need to handle in trigger
Hi,
cant be create one foreign key at column level and others at table
level



Reply With Quote
Reply




Thread Tools
Display Modes

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.