?
Solved

Make sure a database is clean for a specific ID

Posted on 2012-04-07
4
Medium Priority
?
282 Views
Last Modified: 2012-04-08
Dear experts,

I'm building an administration system in Classic ASP, and that include profiles.

Now I have a lot of profiles, and some IDs are registered in several tables.

If I delete a profile on the member's list (table1), I will do like this:

        DeleteProfileSQL = "DELETE FROM [table1] WHERE [id] = " & Request.QueryString("id")
        Conn.Execute(DeleteProfileSQL)

Open in new window


...and that profile will be deleted in the table1!
But the ID of that person may be registered in other tables as well.

How do I make sure that when the record is deleted in table1, following will also happen:

In table2: Only update the existing record (remove the profile's ID)
In table3: Find all the records with the deleted profile's ID and delete the rows containing the profiles ID.

It will also occur that the deleted ID in table1 doesn't exist in any other tables.

Thanks in advance!!

/DanishCoder
0
Comment
Question by:DanishCoder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
ramrom earned 1200 total points
ID: 37820234
UpdateProfileSQL = "UPDATE [table2] SET [id] = 0 WHERE [id] = " & Request.QueryString("id")
Conn.Execute(UpdateProfileSQL 
DeleteProfileSQL = "DELETE FROM [table3] WHERE [id] = " & Request.QueryString("id")
Conn.Execute(DeleteProfileSQL

Open in new window


I am guessing that when you say "remove the profile's ID" you mean to set it = 0. If you have a different intention let me know.
0
 
LVL 53

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 800 total points
ID: 37820237
As long as you know your record layout for each table, you just add more delete statements.

If you have a contacts table with ID, Name, Address and Employee Table with ID, ContactID, Department and you want to delete all records for a specific contact, then you would delete using the contactID in the contacts table, then do another delete statement this time using the ContactID in the Employee Table.



<%

ProfileID =Request.QueryString("id")

DeleteProfileSQL = "DELETE FROM [table1] WHERE [id] = " & ProfileID
        Conn.Execute(DeleteProfileSQL)

DeleteProfileSQL = "DELETE FROM [table2] WHERE [somefield] = " & ProfileID 'somefield is the field where you will find the related id
        Conn.Execute(DeleteProfileSQL)

DeleteProfileSQL = "DELETE FROM [table3] WHERE [somefield] = " & ProfileID 'somefield is the field where you will find the related id
        Conn.Execute(DeleteProfileSQL)

%>
0
 
LVL 17

Expert Comment

by:ramrom
ID: 37821236
OP said "In table2: Only update the existing record (remove the profile's ID)"

Other than that our solutions seem to be the same.
0
 

Author Comment

by:DanishCoder
ID: 37821808
@ramrom
Yes, seems like that was what I was looking for - I just didn't know if there was a better or quicker solution. What I have is:

1. A member table, where the profile is registered, its ID is used in the group table, and volunteer table.
2. A group table, where I need to update the member's ID to 0 or '' when not entered (the group doesn't disappear because a profile in the member's table is deleted).
3. A volunteer table, where I would need to delete the row containing the member's ID

@padas
In this situation I know the table structure, and I suppose you will always know that, as you are the one who builds the table structure - and as ranrom said, both solutions seems to be the same.


Thanks for your time and expertise :)
DanishCoder
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question