Synchronizing data in two database tables after deletion

This is my school project. I am in the voice of the eForum part. I tried deleting the user and all the streams and responses by the deleted user will be deleted as well.

    public boolean deleteUser() {
    boolean success = false;
    DBController db = new DBController();
    db.setUp("IT Innovation Project");
    String sql = "DELETE FROM forumUsers where users_id = " + userID + "";
    if (db.updateRequest(sql) == 1)
        success = true;
    db.terminate();
    return success;
}

      

This method retrieves the value of the first column of the table and stores it as a user ID. Then it will execute delete sql command to delete a specific user.

    public boolean deleteThread() {
    boolean success = false;
    DBController db = new DBController();
    db.setUp("IT Innovation Project");
    String sql = "DELETE FROM forumTopics where topic_id = " + threadID
            + "";
    if (db.updateRequest(sql) == 1)
        success = true;
    db.terminate();
    return success;
}

      

Regarding this method, it will take the value of the first column of another table, which will show all streams and execute the delete sql statement.

However, after I deleted some user, the streams and responses by the remote user are still stored in the database. I am currently using one user table and one threads table in the database. Is there a way to so called "sync" both tables? Is this an inner join?

Thanks in advance.

+3


source to share


1 answer


This seems to be a perfect example for setting up your relationship with Cascade Delete ( http://support.microsoft.com/kb/304466 )

Cascading updates and deletions

For relationships that use referential integrity, you can specify whether you want Microsoft Access to automatically cascade updates or cascading deletions of related records. If you set these options, delete and update operations are normally allowed for referential integrity rules. When you delete records or change the primary key values ​​in the primary table, Microsoft Access makes the necessary changes to the linked tables to maintain referential integrity.

Please note that Cascade Delete should be used with great care. These posts are specific to SQL Server, but the ideas apply to any database:



For the most part, I don't delete records the first time, I delete them to delete them later, it's great how often people change their minds.

cascade delete

0


source







All Articles