Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. preventing delete of parent

preventing delete of parent

Scheduled Pinned Locked Moved Database
database
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    keroed_edmond
    wrote on last edited by
    #1

    i have two tables in my database parentTbl with primary key id and childTbl with foreign key pId. i created a relationships between them is it possible to ensure that the record in the parentTbl can not be deleted if it is been used in a record in childTbl. i want to this from a database level i know if i was using store procedure i could always put a check but i was wondering if open the database and the table directly and try to delete record if i can set up the constraints to even prevent this from occurring once there is a corresponding record in the childTbl

    P 1 Reply Last reply
    0
    • K keroed_edmond

      i have two tables in my database parentTbl with primary key id and childTbl with foreign key pId. i created a relationships between them is it possible to ensure that the record in the parentTbl can not be deleted if it is been used in a record in childTbl. i want to this from a database level i know if i was using store procedure i could always put a check but i was wondering if open the database and the table directly and try to delete record if i can set up the constraints to even prevent this from occurring once there is a corresponding record in the childTbl

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      This is what a foreign key is for. Ensure that it doesn't perform a cascade delete then the database will take care of this for you automatically.

      the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
      Deja View - the feeling that you've seen this post before.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups