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. Cascading referential integrity.

Cascading referential integrity.

Scheduled Pinned Locked Moved Database
questionannouncement
3 Posts 3 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.
  • U Offline
    U Offline
    User 11127370
    wrote on last edited by
    #1

    HI, I want to know that while creating cascading referential integrity constraint between tables having foreign key relationships. For e.g:- I have two tables Employee and EmployeeLeave,now i want to use cascading referential integrity constraint code:- Alter Table dbo.EmployeeLeave Add Constraint rfkcEmployeeID Foreign Key(EmployeeID) References dbo.Employee(EmployeeID) ON DELETE NO ACTION ON UPDATE NO ACTION So, My question is that i can even use this Constraint at the time of Creating Table For e.g:- Create Table dbo.EmployeeLeave ( EmployeeID int constraint rfkcEmployeeID Foreign Key(EmployeeID)References dbo.Employee(EmployeeID) ON DELETE NO ACTION ON UPDATE NO ACTION ) Is this code is correct??? Is it will work??? Thanks...

    C L 2 Replies Last reply
    0
    • U User 11127370

      HI, I want to know that while creating cascading referential integrity constraint between tables having foreign key relationships. For e.g:- I have two tables Employee and EmployeeLeave,now i want to use cascading referential integrity constraint code:- Alter Table dbo.EmployeeLeave Add Constraint rfkcEmployeeID Foreign Key(EmployeeID) References dbo.Employee(EmployeeID) ON DELETE NO ACTION ON UPDATE NO ACTION So, My question is that i can even use this Constraint at the time of Creating Table For e.g:- Create Table dbo.EmployeeLeave ( EmployeeID int constraint rfkcEmployeeID Foreign Key(EmployeeID)References dbo.Employee(EmployeeID) ON DELETE NO ACTION ON UPDATE NO ACTION ) Is this code is correct??? Is it will work??? Thanks...

      C Offline
      C Offline
      CHill60
      wrote on last edited by
      #2

      What happened when you tried it?

      1 Reply Last reply
      0
      • U User 11127370

        HI, I want to know that while creating cascading referential integrity constraint between tables having foreign key relationships. For e.g:- I have two tables Employee and EmployeeLeave,now i want to use cascading referential integrity constraint code:- Alter Table dbo.EmployeeLeave Add Constraint rfkcEmployeeID Foreign Key(EmployeeID) References dbo.Employee(EmployeeID) ON DELETE NO ACTION ON UPDATE NO ACTION So, My question is that i can even use this Constraint at the time of Creating Table For e.g:- Create Table dbo.EmployeeLeave ( EmployeeID int constraint rfkcEmployeeID Foreign Key(EmployeeID)References dbo.Employee(EmployeeID) ON DELETE NO ACTION ON UPDATE NO ACTION ) Is this code is correct??? Is it will work??? Thanks...

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Member 11161625 wrote:

        Is this code is correct???

        Syntactic it is correct, but it will do nothing, as you instructed it. That is the default behaviour. If you want the "leave" days to be removed from the database when the employee is removed from the database, then you'd want a cascading delete. (ON DELETE CASCADE, not "NO ACTION"). That way you can prevent getting "orphaned" records. If you still need the leave-data from that person and don't want to wipe the records, I'd recommend "ON DELETE SET NULL", since the key would have become invalid - but then the record isn't deleted, just the key is removed - handy if you need the leave-data for statistics or other stuff. Last, there is also a "SET DEFAULT" option; if a manager is deleted from the database, then you might want to automatically update all affected workers to some default-manager.

        Member 11161625 wrote:

        Is it will work???

        Depends on the specs. Press F5 and see if it does what you expect. Disclaimer; various database-engines may use different keywords and not support them all.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

        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