Unix Technical Forum

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

This is a discussion on SQL - Foreign key with references of multiple tables with same primary key field within the SQL Server forums, part of the Microsoft SQL Server category; --> I want to create a table with member id(primary key for Students,faculty and staff [Tables]) and now i want ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 02:50 PM
Chirag
 
Posts: n/a
Default SQL - Foreign key with references of multiple tables with same primary key field

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 02:50 PM
Ed Murphy
 
Posts: n/a
Default Re: SQL - Foreign key with references of multiple tables with sameprimary key field

Chirag 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.


Create a Members table, then have all the other tables reference it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 02:50 PM
M A Srinivas
 
Posts: n/a
Default Re: SQL - Foreign key with references of multiple tables with same primary key field

On Apr 9, 9:48 am, "Chirag" <chirag.dpa...@gmail.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



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-01-2008, 02:54 PM
nehajain.cse@gmail.com
 
Posts: n/a
Default Re: SQL - Foreign key with references of multiple tables with same primary key field

On Apr 8, 11:34 pm, "M A Srinivas" <masri...@gmail.com> wrote:
> On Apr 9, 9:48 am, "Chirag" <chirag.dpa...@gmail.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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:40 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com