Results 1 to 6 of 6
  1. #1
    vaibhavspawar is offline Member
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0

    Default Listing columns in tables...

    Hello everyone,
    I want to delete a record from table. But the ID of this record is used as foreign key in many other tables. Thus I've to delete all other records from other tables which uses this ID as Foreign Key. So does anybody knows the simple way to do this.

    One way I am trying is,
    I am using DatabaseMetadata Interface & using that I've listed all tables & columns in them. Now I've to compare each column name & If found, I've to delete it. I feel it so messing. Please Help... :)

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default

    Give your foreign keys ON DELETE CASCADE?
    Because that's what you are effectively doing.

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Yup. Let the Database do the job it was designed to do.

  4. #4
    vaibhavspawar is offline Member
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    Give your foreign keys ON DELETE CASCADE?
    Because that's what you are effectively doing.
    Will you please tell me how to do this in java?

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    You don't. You do that when creating the table.

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default

    Yep, this is a db thing.

    You can alert the tables, but I think (you'd need to look at the docs) that you have to add a new foreign key. I'm not sure you can ALTER a foreign key to make it cascade.

Similar Threads

  1. listing files at the FTP
    By oulutas in forum New To Java
    Replies: 6
    Last Post: 10-10-2010, 11:30 AM
  2. Listing Installed DSA
    By anoopasta in forum XML
    Replies: 1
    Last Post: 05-06-2010, 04:10 PM
  3. Listing tables of a database
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-12-2008, 09:30 AM
  4. Listing subdirectories/files
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-13-2008, 07:19 AM
  5. Listing all available Locales
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-29-2007, 04:54 PM

Posting Permissions

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