Loading ...
Sorry, an error occurred while loading the content.

Re: [mugh-sqlcon] Foreign Key constraint

Expand Messages
  • Roji. P. Thomas
    Mei, What is the point in having a foreign key to two diffent tables, when both the tables needs to have the same data? Regards Roji. P. Thomas ... From:
    Message 1 of 14 , Dec 5, 2005
    • 0 Attachment
      Mei,
       
          What is the point in having a foreign key to two diffent tables, when both the tables needs to have the same data?
       
      Regards
      Roji. P. Thomas
      ----- Original Message -----
      Sent: Monday, December 05, 2005 12:51 PM
      Subject: Re: [mugh-sqlcon] Foreign Key constraint

      Hi Babu,
       
      You can always create a table with foreign keys something like this
       
      create
      table tbl( col1 int
      , constraint fk_t3_1 foreign key (col1) references t1(a)
      , constraint fk_t3_2 foreign key (col1) references t2(a))
       
      But, whatever the data you are entering in this child table should be present in both the parent tables t1 & t2 unlike you said "any one of the parent tables" :(.
       
      Other option to achieve your goal is to use the INSERT TRIGGER on your chile table.
       
      Thanks
      Mei

      Babu PP <babupp@...> wrote:
      Hi,
      I have a doubt in creating the foreign key constraints.
      Can I create a relation like, many-parents-one-child ?  I mean there are 3 PK tables, related to one FK table.  My expectation is while entering data in child table, PK should be existing in any one of the parent table.
      Is it possible to do like this.  Or what is the work-around for this.
      Thanks in advance.
      Regards
      Babu


      Yahoo! Shopping
      Find Great Deals on Gifts at Yahoo! Shopping

      __________________________________________________
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around
      http://mail.yahoo.com

    • Meiyalagan.B
      Hi Roji, Hmmm... that was a great question ... I just wanted to show SQL Server allows us to create more than one foreign keys on a single column to different
      Message 2 of 14 , Dec 5, 2005
      • 0 Attachment
        Hi Roji,
         
        Hmmm... that was a great question ... I just wanted to show SQL Server allows us to create more than one foreign keys on a single column to different tables .... 
        And i too feel that we may not have such implementation in real time scenario :)
         
        - Mei

        "Roji. P. Thomas" <thomasroji@...> wrote:
        Mei,
         
            What is the point in having a foreign key to two diffent tables, when both the tables needs to have the same data?
         
        Regards
        Roji. P. Thomas
        ----- Original Message -----
        Sent: Monday, December 05, 2005 12:51 PM
        Subject: Re: [mugh-sqlcon] Foreign Key constraint

        Hi Babu,
         
        You can always create a table with foreign keys something like this
         
        create
        table tbl( col1 int
        , constraint fk_t3_1 foreign key (col1) references t1(a)
        , constraint fk_t3_2 foreign key (col1) references t2(a))
         
        But, whatever the data you are entering in this child table should be present in both the parent tables t1 & t2 unlike you said "any one of the parent tables" :(.
         
        Other option to achieve your goal is to use the INSERT TRIGGER on your chile table.
         
        Thanks
        Mei

        Babu PP <babupp@...> wrote:
        Hi,
        I have a doubt in creating the foreign key constraints.
        Can I create a relation like, many-parents-one-child ?  I mean there are 3 PK tables, related to one FK table.  My expectation is while entering data in child table, PK should be existing in any one of the parent table.
        Is it possible to do like this.  Or what is the work-around for this.
        Thanks in advance.
        Regards
        Babu


        Yahoo! Shopping
        Find Great Deals on Gifts at Yahoo! Shopping
        __________________________________________________
        Do You Yahoo!?
        Tired of spam? Yahoo! Mail has the best spam protection around
        http://mail.yahoo.com

        __________________________________________________
        Do You Yahoo!?
        Tired of spam? Yahoo! Mail has the best spam protection around
        http://mail.yahoo.com


        Yahoo! Personals
        Single? There's someone we'd like you to meet.
        Lots of someones, actually. Yahoo! Personals

      • Preethiviraj Kulasingham
        When Inheritance come into picture, you may face a scenario like this. you may not have the same data in both parent tables. Let me give a simple scenario: You
        Message 3 of 14 , Dec 6, 2005
        • 0 Attachment
          When Inheritance come into picture, you may face a scenario like this.
           
          you may not have the same data in both parent tables.
           
          Let me give a simple scenario:
          You have a Library system you you keep the books and periodicals into different tables. (You may need to keep them into different tables as they may have different informatin) you want the users to borrow one item (either a book or a periodical)
           
          My solution is to keep a table called Items which keeps the primary key (item ID) Let books table and Periodicals table refer (1 to 1 relationship) from Items.  Your transaction table will refer to the item table (either a book or a periodical)
           


          "Roji. P. Thomas" <thomasroji@...> wrote:
          Mei,
           
              What is the point in having a foreign key to two diffent tables, when both the tables needs to have the same data?
           
          Regards
          Roji. P. Thomas
          ----- Original Message -----
          Sent: Monday, December 05, 2005 12:51 PM
          Subject: Re: [mugh-sqlcon] Foreign Key constraint

          Hi Babu,
           
          You can always create a table with foreign keys something like this
           
          create
          table tbl( col1 int
          , constraint fk_t3_1 foreign key (col1) references t1(a)
          , constraint fk_t3_2 foreign key (col1) references t2(a))
           
          But, whatever the data you are entering in this child table should be present in both the parent tables t1 & t2 unlike you said "any one of the parent tables" :(.
           
          Other option to achieve your goal is to use the INSERT TRIGGER on your chile table.
           
          Thanks
          Mei

          Babu PP <babupp@...> wrote:
          Hi,
          I have a doubt in creating the foreign key constraints.
          Can I create a relation like, many-parents-one-child ?  I mean there are 3 PK tables, related to one FK table.  My expectation is while entering data in child table, PK should be existing in any one of the parent table.
          Is it possible to do like this.  Or what is the work-around for this.
          Thanks in advance.
          Regards
          Babu


          Yahoo! Shopping
          Find Great Deals on Gifts at Yahoo! Shopping
          __________________________________________________
          Do You Yahoo!?
          Tired of spam? Yahoo! Mail has the best spam protection around
          http://mail.yahoo.com



           
          Best Regards,
          G.R. Preethiviraj Kulasingham
          Database Administrator
           


          Yahoo! Personals
          Single? There's someone we'd like you to meet.
          Lots of someones, actually. Yahoo! Personals

        • NandaKishore
          The best material is www.microsoft.com/sql/2005. Go through the webcasts, articles on topic wise which will give enough information Thanks Santhosh
          Message 4 of 14 , Dec 6, 2005
          • 0 Attachment
            The best material is www.microsoft.com/sql/2005. Go through the webcasts, articles on topic wise which will give enough information
             
            Thanks


            Santhosh <san_spy@...> wrote:
            Hi Guys,
            Hope many of you might have read many books on SQL
            2005. Can you please suggest me some good book in a
            DBA prespective.


            with smiles
            santhosh


                       
            __________________________________________
            Yahoo! DSL – Something to write home about.
            Just $16.99/mo. or less.
            dsl.yahoo.com




            NandaKishore

            MBA (Systems) |MCDBA |MCP|+91-98850-25889


            Yahoo! Personals
            Single? There's someone we'd like you to meet.
            Lots of someones, actually. Yahoo! Personals

          • VISHNAT
            By any chance are you talking about 4NF? regards Viswanath ... tables. Since ... these tables, ... will have ... thinking of may ... childtable ... these ...
            Message 5 of 14 , Dec 6, 2005
            • 0 Attachment
              By any chance are you talking about 4NF?

              regards
              Viswanath


              --- In sqlcon@yahoogroups.com, Babu PP <babupp@g...> wrote:
              >
              > Hi All,
              >
              > Thanks for your feed-back.
              >
              > I'm planning to go ahead with implementing triggers on child
              tables. Since
              > the wirte operation is less and the read will be very high on
              these tables,
              > I think that could be the best solution here.
              >
              > Thanks once again.
              > Have a nice day.
              >
              > Regards
              > Babu
              >
              >
              >
              > On 12/5/05, Preethiviraj Kulasingham <preethi_kulasingham@y...>
              wrote:
              > >
              > > HI Babu,
              > > For this design, I would like to introduce a master table which
              will have
              > > the primary key. The three tables (Many-parents) you are
              thinking of may
              > > have one-to-one relationship to the master table. Finally your
              childtable
              > > will have the foreign key of Master table.
              > >
              > > You may think of the issues in having "public" parimary keys of
              these
              > > parent tables may be different and with different lengths. I
              suggest you to
              > > have an IDENTITY field as primary key. This could be used only
              for internal
              > > purpose only.
              > >
              > > Another method is having a trigger to maintain this type of
              constraint.
              > > However, it has its own performance implications.
              > >
              > > :)
              > >
              > > *Babu PP <babupp@g...>* wrote:
              > >
              > > Hi,
              > > I have a doubt in creating the foreign key constraints.
              > > Can I create a relation like, many-parents-one-child ? I mean
              there are 3
              > > PK tables, related to one FK table. My expectation is while
              entering data
              > > in child table, PK should be existing in any one of the parent
              table.
              > > Is it possible to do like this. Or what is the work-around for
              this.
              > > Thanks in advance.
              > > Regards
              > > Babu
              > >
              > >
              > >
              > >
              > >
              > >
              > > Best Regards,
              > > *G.R. Preethiviraj Kulasingham*
              > > Database Administrator
              > > http://preethiviraj.blogspot.com/ <http://preethik.blogspot.com/>
              > >
              > >
              > > ------------------------------
              > > *Yahoo! Personals*
              > > Single? There's someone we'd like you to meet.
              > > Lots of someones, actually. Yahoo!
              Personals<http://us.rd.yahoo.com/evt=36108/*http://personals.yahoo.co
              m+%0A>
              > >
              > > SqlCon is a special interests group run under the aegis of MUGH -
              > > http://www.mugh.net
              > > http://www.mugh.net/sql
              > >
              > > Visit http://www.mugh.net/dnug to join .NET User Group.
              > >
              > >
              > >
              > > ------------------------------
              > > YAHOO! GROUPS LINKS
              > >
              > >
              > > - Visit your group "sqlcon
              <http://groups.yahoo.com/group/sqlcon>"
              > > on the web.
              > >
              > > - To unsubscribe from this group, send an email to:
              > > sqlcon-unsubscribe@yahoogroups.com<sqlcon-
              unsubscribe@yahoogroups.com?subject=Unsubscribe>
              > >
              > > - Your use of Yahoo! Groups is subject to the Yahoo! Terms of
              > > Service <http://docs.yahoo.com/info/terms/>.
              > >
              > >
              > > ------------------------------
              > >
              > >
              >
            • ved_17in
              JOIN ASKSQLEXPERTS and find out SQL 2005 books.... Ved Prakash ... webcasts, articles on topic wise which will give enough information ... http://www.mugh.net
              Message 6 of 14 , Dec 15, 2005
              • 0 Attachment
                JOIN ASKSQLEXPERTS and find out SQL 2005 books....


                Ved Prakash



                --- In sqlcon@yahoogroups.com, NandaKishore <nandakishoren@y...>
                wrote:
                >
                > The best material is www.microsoft.com/sql/2005. Go through the
                webcasts, articles on topic wise which will give enough information
                >
                > Thanks
                >
                >
                > Santhosh <san_spy@y...> wrote:
                > Hi Guys,
                > Hope many of you might have read many books on SQL
                > 2005. Can you please suggest me some good book in a
                > DBA prespective.
                >
                >
                > with smiles
                > santhosh
                >
                >
                >
                > __________________________________________
                > Yahoo! DSL – Something to write home about.
                > Just $16.99/mo. or less.
                > dsl.yahoo.com
                >
                >
                >
                > SqlCon is a special interests group run under the aegis of MUGH -
                http://www.mugh.net
                > http://www.mugh.net/sql
                >
                > Visit http://www.mugh.net/dnug to join .NET User Group.
                >
                >
                >
                >
                > ---------------------------------
                > YAHOO! GROUPS LINKS
                >
                >
                > Visit your group "sqlcon" on the web.
                >
                > To unsubscribe from this group, send an email to:
                > sqlcon-unsubscribe@yahoogroups.com
                >
                > Your use of Yahoo! Groups is subject to the Yahoo! Terms of
                Service.
                >
                >
                > ---------------------------------
                >
                >
                >
                >
                >
                >
                >
                > NandaKishore
                >
                > MBA (Systems) |MCDBA |MCP|+91-98850-25889
                >
                >
                >
                >
                >
                >
                > ---------------------------------
                > Yahoo! Personals
                > Single? There's someone we'd like you to meet.
                > Lots of someones, actually. Yahoo! Personals
                >
              • Suresh Kumar
                Hi Everybody, I am going to take up Brain Bench Examination on SQL ANSI FUNDAMENTAL. Where can I find the info on SQL ANSI FUNDAMENTAL. If you have any
                Message 7 of 14 , Dec 19, 2005
                • 0 Attachment
                  Hi Everybody,
                   
                  I am going to take up Brain Bench Examination on SQL ANSI FUNDAMENTAL. Where can I find the info on SQL ANSI FUNDAMENTAL. If you have any material on this, pls pass it.
                   
                  Thanks
                  Suresh

                  ved_17in <ved_17in@...> wrote:

                  JOIN ASKSQLEXPERTS and find out SQL 2005 books....


                  Ved Prakash



                  --- In sqlcon@yahoogroups.com, NandaKishore <nandakishoren@y...>
                  wrote:
                  >
                  > The best material is www.microsoft.com/sql/2005. Go through the
                  webcasts, articles on topic wise which will give enough information
                  >   
                  >   Thanks
                  >  
                  >
                  > Santhosh <san_spy@y...> wrote:
                  >   Hi Guys,
                  > Hope many of you might have read many books on SQL
                  > 2005. Can you please suggest me some good book in a
                  > DBA prespective.
                  >
                  >
                  > with smiles
                  > santhosh
                  >
                  >
                  >            
                  > __________________________________________
                  > Yahoo! DSL – Something to write home about.
                  > Just $16.99/mo. or less.
                  > dsl.yahoo.com
                  >
                  >
                  >
                  > SqlCon is a special interests group run under the aegis of MUGH -
                  http://www.mugh.net
                  > http://www.mugh.net/sql
                  >
                  > Visit http://www.mugh.net/dnug to join .NET User Group.
                  >
                  >
                  >
                  >    
                  > ---------------------------------
                  >   YAHOO! GROUPS LINKS
                  >
                  >    
                  >     Visit your group "sqlcon" on the web.
                  >    
                  >     To unsubscribe from this group, send an email to:
                  >  sqlcon-unsubscribe@yahoogroups.com
                  >    
                  >     Your use of Yahoo! Groups is subject to the Yahoo! Terms of
                  Service.
                  >
                  >    
                  > ---------------------------------
                  >  
                  >
                  >  
                  >
                  >
                  >
                  >
                  > NandaKishore
                  >
                  > MBA (Systems) |MCDBA |MCP|+91-98850-25889
                  >
                  >
                  >
                  >
                  >
                  >            
                  > ---------------------------------
                  >  Yahoo! Personals
                  >  Single? There's someone we'd like you to meet.
                  >  Lots of someones, actually. Yahoo! Personals
                  >





                  Send instant messages to your online friends http://au.messenger.yahoo.com

                • Suresh Kumar
                  Hi Everybody, I am going to take up Brain Bench Examination on SQL ANSI FUNDAMENTAL. Where can I find the info on SQL ANSI FUNDAMENTAL. If you have any
                  Message 8 of 14 , Dec 19, 2005
                  • 0 Attachment
                    Hi Everybody,
                     
                    I am going to take up Brain Bench Examination on SQL ANSI FUNDAMENTAL. Where can I find the info on SQL ANSI FUNDAMENTAL. If you have any material on this, pls pass it.
                     
                    Thanks
                    Suresh

                    Send instant messages to your online friends http://au.messenger.yahoo.com

                  Your message has been successfully submitted and would be delivered to recipients shortly.