How do you delete a record form multiple tables

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default How do you delete a record form multiple tables

    I have a dbase that has about 30 tables in it. How
    can I delete a record out of all of the tables without
    doing 30 DELETE statements?

    Example:
    SQLstmt = "DELETE * FROM fd_1 WHERE CustomerSSN = '111-22-3333'"
    Set RS = conn.execute(SQLstmt)

    SQLstmt = "DELETE * FROM fd_2 WHERE CustomerSSN = '111-22-3333'"
    Set RS = conn.execute(SQLstmt)

    SQLstmt = "DELETE * FROM fd_3 WHERE CustomerSSN = '111-22-3333'"
    Set RS = conn.execute(SQLstmt)

    etc.....


    for some reason

    SQLstmt = "DELETE * FROM fd_1, fd_2, fd_3 WHERE CustomerSSN =
    '111-22-3333'"
    Set RS = conn.execute(SQLstmt)

    does not work.

    Mike


    Mike Guest

  2. Similar Questions and Discussions

    1. Delete against multiple tables + And / Or
      Hi there, a part of my music site exists of three tables: songs -> id, artist_id, song_name lyrics -> id, song_id, lyrics genre -> id,...
    2. update multiple records in multiple tables from one form
      hello I have been trying to run multiple update queries based on the data entered by user. Brief background: I am fetching data from various...
    3. Can one <form> submit data to multiple tables?
      Am I able to use a single form to write data to multiple tables in my database using php/mySQL?
    4. Submitting multiple record IDs via a form.
      I have a problem more to do with style than ability; I can solve this problem in a number of ways, but I'm keen to find the best way of doing...
    5. ASP form writing to multiple DB tables.
      I'm new to Access and ASP pages, but so far I have been doing OK. This one has me stumped. What I am trying to do is have an ASP form with several...
  3. #2

    Default Re: How do you delete a record form multiple tables

    This is the same concept as your other post where it's a matter of building
    a string in a loop and executing a query.

    For i = 1 to 30
    sSQL = "delete from fd_" & cstr(i) & " where CustomerSSN='111-22-3333'"
    conn.Execute sSQL
    Next

    Note again that it's NOT
    SET RS = conn.execute(sSQL)
    It's just
    conn.Execute sSQL


    Why does your database have all these tables like this?

    Ray at work


    "Mike" <mike4532> wrote in message
    news:%23tdQLwOxDHA.1396@TK2MSFTNGP10.phx.gbl...
    > I have a dbase that has about 30 tables in it. How
    > can I delete a record out of all of the tables without
    > doing 30 DELETE statements?
    >
    > Example:
    > SQLstmt = "DELETE * FROM fd_1 WHERE CustomerSSN = '111-22-3333'"
    > Set RS = conn.execute(SQLstmt)
    >
    > SQLstmt = "DELETE * FROM fd_2 WHERE CustomerSSN = '111-22-3333'"
    > Set RS = conn.execute(SQLstmt)
    >
    > SQLstmt = "DELETE * FROM fd_3 WHERE CustomerSSN = '111-22-3333'"
    > Set RS = conn.execute(SQLstmt)
    >
    > etc.....
    >
    >
    > for some reason
    >
    > SQLstmt = "DELETE * FROM fd_1, fd_2, fd_3 WHERE CustomerSSN =
    > '111-22-3333'"
    > Set RS = conn.execute(SQLstmt)
    >
    > does not work.
    >
    > Mike
    >
    >

    Ray at Guest

  4. #3

    Default Re: How do you delete a record form multiple tables

    I guess that I should of better explained what I need....

    Not all of the table are the same name with a dif number at the end.
    There are 20 rd_1, rd_2, etc... and there are also 10 other misc named
    tables.

    So a string loop will not work in this case.

    Can you do a: Delete * From ALL Where........

    Mike

    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    news:ew73h4OxDHA.2148@TK2MSFTNGP12.phx.gbl...
    > This is the same concept as your other post where it's a matter of
    building
    > a string in a loop and executing a query.
    >
    > For i = 1 to 30
    > sSQL = "delete from fd_" & cstr(i) & " where
    CustomerSSN='111-22-3333'"
    > conn.Execute sSQL
    > Next
    >
    > Note again that it's NOT
    > SET RS = conn.execute(sSQL)
    > It's just
    > conn.Execute sSQL
    >
    >
    > Why does your database have all these tables like this?
    >
    > Ray at work
    >
    >
    > "Mike" <mike4532> wrote in message
    > news:%23tdQLwOxDHA.1396@TK2MSFTNGP10.phx.gbl...
    > > I have a dbase that has about 30 tables in it. How
    > > can I delete a record out of all of the tables without
    > > doing 30 DELETE statements?
    > >
    > > Example:
    > > SQLstmt = "DELETE * FROM fd_1 WHERE CustomerSSN = '111-22-3333'"
    > > Set RS = conn.execute(SQLstmt)
    > >
    > > SQLstmt = "DELETE * FROM fd_2 WHERE CustomerSSN = '111-22-3333'"
    > > Set RS = conn.execute(SQLstmt)
    > >
    > > SQLstmt = "DELETE * FROM fd_3 WHERE CustomerSSN = '111-22-3333'"
    > > Set RS = conn.execute(SQLstmt)
    > >
    > > etc.....
    > >
    > >
    > > for some reason
    > >
    > > SQLstmt = "DELETE * FROM fd_1, fd_2, fd_3 WHERE CustomerSSN =
    > > '111-22-3333'"
    > > Set RS = conn.execute(SQLstmt)
    > >
    > > does not work.
    > >
    > > Mike
    > >
    > >
    >
    >

    Mike Guest

  5. #4

    Default Re: How do you delete a record form multiple tables

    In a answer to your last question.
    > Why does your database have all these tables like this?
    We have an Intranet that has an ASP driven site. On that site we input
    information about our customers.
    We do debt elimination and collect the debts of our clients and record
    them to a dbase. We have the ability
    to collect up to 20 different debts, such as credit cards, dept. store
    cards, etc... Not all of our clients have
    the same number of debts. I origionally had a big table that had 6
    fields about each debt and there were 20
    debts. That resulted in a table that was 120 columns. And if a client
    only had 5 debts then i was just waisting
    space by having the other 15 debts be null. So normalized the table and
    broke it into 20 seperate tables, one for
    each debt, that only have 6 records in each. Now I only record the
    information into a table if the information exists. So if a client only
    has 5 debts, i only write to tables 1-5.

    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    news:ew73h4OxDHA.2148@TK2MSFTNGP12.phx.gbl...
    > This is the same concept as your other post where it's a matter of
    building
    > a string in a loop and executing a query.
    >
    > For i = 1 to 30
    > sSQL = "delete from fd_" & cstr(i) & " where
    CustomerSSN='111-22-3333'"
    > conn.Execute sSQL
    > Next
    >
    > Note again that it's NOT
    > SET RS = conn.execute(sSQL)
    > It's just
    > conn.Execute sSQL
    >
    >
    > Why does your database have all these tables like this?
    >
    > Ray at work
    >
    >
    > "Mike" <mike4532> wrote in message
    > news:%23tdQLwOxDHA.1396@TK2MSFTNGP10.phx.gbl...
    > > I have a dbase that has about 30 tables in it. How
    > > can I delete a record out of all of the tables without
    > > doing 30 DELETE statements?
    > >
    > > Example:
    > > SQLstmt = "DELETE * FROM fd_1 WHERE CustomerSSN = '111-22-3333'"
    > > Set RS = conn.execute(SQLstmt)
    > >
    > > SQLstmt = "DELETE * FROM fd_2 WHERE CustomerSSN = '111-22-3333'"
    > > Set RS = conn.execute(SQLstmt)
    > >
    > > SQLstmt = "DELETE * FROM fd_3 WHERE CustomerSSN = '111-22-3333'"
    > > Set RS = conn.execute(SQLstmt)
    > >
    > > etc.....
    > >
    > >
    > > for some reason
    > >
    > > SQLstmt = "DELETE * FROM fd_1, fd_2, fd_3 WHERE CustomerSSN =
    > > '111-22-3333'"
    > > Set RS = conn.execute(SQLstmt)
    > >
    > > does not work.
    > >
    > > Mike
    > >
    > >
    >
    >

    Mike Guest

  6. #5

    Default Re: How do you delete a record form multiple tables

    if all debt types use the same (or similar) columns then you should only
    have 1 table for debts with a "debt_type" column to distinguish among them.

    In answer to "delete * from ALL"... No, delete doesn't work like that.

    --
    Mark Schupp
    Head of Development
    Integrity eLearning
    [url]www.ielearning.com[/url]


    "Mike" <mike4532> wrote in message
    news:eXizHZPxDHA.2556@TK2MSFTNGP10.phx.gbl...
    > In a answer to your last question.
    >
    > > Why does your database have all these tables like this?
    >
    > We have an Intranet that has an ASP driven site. On that site we
    input
    > information about our customers.
    > We do debt elimination and collect the debts of our clients and record
    > them to a dbase. We have the ability
    > to collect up to 20 different debts, such as credit cards, dept. store
    > cards, etc... Not all of our clients have
    > the same number of debts. I origionally had a big table that had 6
    > fields about each debt and there were 20
    > debts. That resulted in a table that was 120 columns. And if a client
    > only had 5 debts then i was just waisting
    > space by having the other 15 debts be null. So normalized the table
    and
    > broke it into 20 seperate tables, one for
    > each debt, that only have 6 records in each. Now I only record the
    > information into a table if the information exists. So if a client
    only
    > has 5 debts, i only write to tables 1-5.
    >
    > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    > news:ew73h4OxDHA.2148@TK2MSFTNGP12.phx.gbl...
    > > This is the same concept as your other post where it's a matter of
    > building
    > > a string in a loop and executing a query.
    > >
    > > For i = 1 to 30
    > > sSQL = "delete from fd_" & cstr(i) & " where
    > CustomerSSN='111-22-3333'"
    > > conn.Execute sSQL
    > > Next
    > >
    > > Note again that it's NOT
    > > SET RS = conn.execute(sSQL)
    > > It's just
    > > conn.Execute sSQL
    > >
    > >
    > > Why does your database have all these tables like this?
    > >
    > > Ray at work
    > >
    > >
    > > "Mike" <mike4532> wrote in message
    > > news:%23tdQLwOxDHA.1396@TK2MSFTNGP10.phx.gbl...
    > > > I have a dbase that has about 30 tables in it. How
    > > > can I delete a record out of all of the tables without
    > > > doing 30 DELETE statements?
    > > >
    > > > Example:
    > > > SQLstmt = "DELETE * FROM fd_1 WHERE CustomerSSN = '111-22-3333'"
    > > > Set RS = conn.execute(SQLstmt)
    > > >
    > > > SQLstmt = "DELETE * FROM fd_2 WHERE CustomerSSN = '111-22-3333'"
    > > > Set RS = conn.execute(SQLstmt)
    > > >
    > > > SQLstmt = "DELETE * FROM fd_3 WHERE CustomerSSN = '111-22-3333'"
    > > > Set RS = conn.execute(SQLstmt)
    > > >
    > > > etc.....
    > > >
    > > >
    > > > for some reason
    > > >
    > > > SQLstmt = "DELETE * FROM fd_1, fd_2, fd_3 WHERE CustomerSSN =
    > > > '111-22-3333'"
    > > > Set RS = conn.execute(SQLstmt)
    > > >
    > > > does not work.
    > > >
    > > > Mike
    > > >
    > > >
    > >
    > >
    >
    >

    Mark Schupp Guest

  7. #6

    Default Re: How do you delete a record form multiple tables

    Mike wrote:
    > In a answer to your last question.
    >
    >> Why does your database have all these tables like this?
    >
    > We have an Intranet that has an ASP driven site. On that site we
    > input information about our customers.
    > We do debt elimination and collect the debts of our clients and
    > record them to a dbase. We have the ability
    > to collect up to 20 different debts, such as credit cards, dept.
    > store cards, etc... Not all of our clients have
    > the same number of debts. I origionally had a big table that had 6
    > fields about each debt and there were 20
    > debts. That resulted in a table that was 120 columns. And if a
    > client only had 5 debts then i was just waisting
    > space by having the other 15 debts be null. So normalized the
    > table and broke it into 20 seperate tables, one for
    > each debt, that only have 6 records in each. Now I only record the
    > information into a table if the information exists. So if a
    > client only has 5 debts, i only write to tables 1-5.
    No, no, no. that's not normal. Have one table with one debt column and one
    debt-type column.

    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  8. #7

    Default Re: How do you delete a record form multiple tables

    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:evMk91PxDHA.2568@TK2MSFTNGP09.phx.gbl...
    > Mike wrote:
    > > In a answer to your last question.
    > >
    > >> Why does your database have all these tables like this?
    > >
    > > We have an Intranet that has an ASP driven site. On that site we
    > > input information about our customers.
    > > We do debt elimination and collect the debts of our clients and
    > > record them to a dbase. We have the ability
    > > to collect up to 20 different debts, such as credit cards, dept.
    > > store cards, etc... Not all of our clients have
    > > the same number of debts. I origionally had a big table that had 6
    > > fields about each debt and there were 20
    > > debts. That resulted in a table that was 120 columns. And if a
    > > client only had 5 debts then i was just waisting
    > > space by having the other 15 debts be null. So normalized the
    > > table and broke it into 20 seperate tables, one for
    > > each debt, that only have 6 records in each. Now I only record the
    > > information into a table if the information exists. So if a
    > > client only has 5 debts, i only write to tables 1-5.
    >
    > No, no, no. that's not normal. Have one table with one debt column and one
    > debt-type column.
    >
    > Bob Barrows
    >
    > --
    > Microsoft MVP - ASP/ASP.NET
    > Please reply to the newsgroup. This email account is my spam trap so I
    > don't check it very often. If you must reply off-line, then remove the
    > "NO SPAM"
    Normalize! (as Bob strongly suggests!)

    From an earlier post, I gather you have the following fields in 20 tables:

    RD_# (where "#" is 1 - 20)
    CustomerSSN
    RDName
    RDAccount
    RDCurrentBalance
    RDMinPayment
    RDActualPayment
    RDInterest
    RDComments


    Might I suggest these 2 tables instead?

    Customer Table
    CustomerSSN
    RDName

    Account Table
    CustomerSSN
    RDAccount
    RDCurrentBalance
    RDMinPayment
    RDActualPayment
    RDInterest
    RDComments

    Thus, the common key is "CustomerSSN" and there are one or more entries in
    the Account Table.






    McKirahan Guest

  9. #8

    Default Re: How do you delete a record form multiple tables


    I never perform multiple operations that must maintain database
    consistency and integrity inside an ASP script. I used a stored
    procedure in SQL Server, and encompass all of the statements inside a
    transaction. I use Update Queries if I'm using Access. I setup relations
    between my table to enforce the constraints.

    Inside the stored procedure, I check @@ERROR for != 0 after every SQL
    statement, and jump to an error handler that returns the error code and
    my own program-specific status code. Inside the error handler, I
    rollback the transaction. Then I return a recordset with the status code
    and error code.

    If no error occurs, I commit the transaction. Then I return a recordset
    with 0 for the status code, which signifies no error occurred.

    Note that all my stored procedures return a recordset.

    Rob

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Rob Galante Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139