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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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. |
| |||
| 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 |
| ||||
| 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 |