Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    1
    Member #
    40511

    Automatic updates with cascading?

    Hello! I'm very new to SQL development and I've trying to make something like a social networking site. I plan to use cascading updates to a foreign key to link a user ID from one table (my main users table) to a table full of posts. I don't even know for sure that this is the best way to achieve what I'm trying to accomplish, but assuming it is, I want it set up so that if a new user joins the site, it auto increments a row in the ID column on the user table as well as in any table where that ID is a primary key.

    The trouble I'm having is that it doesn't make a new row. Right now I have two fake users registered for testing purposes in the user table and they have IDs 1 and 2, respectively. But adding them did nothing to the user ID foreign key in my posts table. I'm assuming it's not supposed to, but if it's not, what's the point of setting a foreign key?

    EDIT: I figured out another method of doing what I'm trying to do. I don't know if there's a way I can delete this thread since no one had replied but either way, I'm good now. Thanks!
    Last edited by Sam_Sung; Oct 17th, 2014 at 09:36 PM.

  2.  

  3. #2
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    If you could post how you fixed it, we could leave the thread up for future users who have the same problem.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  4. #3
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    A foreign key is intended to identify the "one" in a "one-to-one" or "one-to-many" relationship. For example, an orders table could contain a Customer_ID foreign key that would tie to a customers table, since one customer could place anywhere from 0 orders upwards. As such, your Customer_ID would only be a primary key on the customers table, not the orders table. Primary key = unique identifier. Hopefully that clears it up for you.

    Other than that, what Ron said...if you can do so without compromising your project.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Remove Ads

Posting Permissions

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

Tags for this Thread

All times are GMT -6. The time now is 08:18 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com