SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    May 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Foreign Keys to AUTO receive referenced Primary Keys in MySQL.. Is it possible?

    Hi there... I just registered here since I found all the answers from the users here to be quite helpful, this seems like a great place to get help (hard to find..)

    I have a minor problem with MySQL: I want to be able to construct my database so that the Foreign Key automatically receive the Primary Key value when I add new data to my database. This is for different projects but I'll use my personal CD-database as an example...

    Lets say I add a cd to the DB, it will get an ID(int) and according to what type of cd it is (game, movie, app, series) I want to add more information to the appropriate table (game, movie, app, series).

    I can figure out how to do this with PHP variables but isn't there a way that I can build my DB in such a way that that won't be necessary? At school I use Sybase PowerBuilder which has this function in a nice GUI :P but they never tought us how to do this in script/sql..

    So if someone could help me I'd be very greatful. (Also building a PHP/MySQL intranet site for a company now as a school project, and this would come in handy for that as well..)

  2. #2
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Foreign Keys to AUTO receive referenced Primary Keys in MySQL.. Is it possible?

    Originally posted by snek_one
    I can figure out how to do this with PHP variables but isn't there a way that I can build my DB in such a way that that won't be necessary?
    I don't think this is possible because MySQL does not support relationships between tables. You will have to make use of a programming language (PHP) to do this.

  3. #3
    SitePoint Member
    Join Date
    May 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm that's too bad.. Guess I'm gonna have to learn more PHP than I thought for this.. Oh well, it's about time I did anyway

    Thanks for the help at least!

  4. #4
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i believe MySQL 4.1 will support foreign keys properly.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  5. #5
    SitePoint Member
    Join Date
    May 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright, that would be about time.. I was already amazed to find out that MySQL supported foreign keys after I upgraded from an old version...

    4.1 will probably be out too late for my projects though...

  6. #6
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But you could port them over. It may be worthwhile for sheer performance. ...I have a few project I wish I could have put off until this release.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  7. #7
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by DR_LaRRY_PEpPeR
    i believe MySQL 4.1 will support foreign keys properly.
    About freaking time... I just hope that "properly" includes referential integrity and cascading deletes.
    Wayne Luke
    ------------


  8. #8
    SitePoint Member
    Join Date
    May 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aha, is that the expression for what I'm trying to do: referential integrity?

    That will save me some time reading manuals in the future

  9. #9
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by W. Luke
    About freaking time... I just hope that "properly" includes referential integrity and cascading deletes.
    heh. i think those are included.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •