Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2009
    Posts
    20

    Unanswered: update/delete cascades

    If I have already created the tables, and then I want to implement the update and delete cascades, is it possible? How do i go about doing it?

  2. #2
    Join Date
    Apr 2004
    Location
    The Netherlands
    Posts
    29

    Cascading deletes solution


  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    You can easily set foreign key relationships to implement cascading updates and deletes using the Database Diagram screen in SQL Server Management Studio.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    CREATE TABLE dbo.a (
       a int PRIMARY KEY
    )
    
    CREATE TABLE dbo.b (
       b int
     , CONSTRAINT fk_b FOREIGN KEY (b) REFERENCES dbo.a(a)
    )
    GO
    
    ALTER TABLE dbo.b
      DROP CONSTRAINT fk_b
    
    ALTER TABLE dbo.b
    ADD CONSTRAINT fk_b FOREIGN KEY (b) REFERENCES dbo.a(a)
          ON UPDATE CASCADE
          ON DELETE CASCADE
    
    GO
    DROP TABLE dbo.b
    DROP TABLE dbo.a
    *shrug*
    George
    Home | Blog

Posting Permissions

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