Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2012
    Posts
    16

    Unanswered: delete stored procedure with some complications

    Hai,

    I am new to the stored procedure
    pls help me

    I need a stored procedure for deleting a record which was a primary key if that record is exist in another table it wont delete and display a msg by returing a value -1
    pls help me
    thanks in advance

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Code:
    create procedure DeleteCrap(@ID bigint)
    as
    begin
    if exists (select * from SubTable where ID = @ID) return -1
    else delete from PrimaryTable where ID = @ID
    return 0
    
    end
    This is no substitute for establishing referential integrity in your database design.
    If it's not practically useful, then it's practically useless.

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

Tags for this Thread

Posting Permissions

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