Query to Restrict delete.

  • I have a store proc where in it has

    select authid from tblauthors where empid=(select empid from tbljobs where jobid=6)

    If @@rowcount > 0

    I do not want anubody to delete that empid.

  • Delete what empid?

    you may have an issue with this

    select authid from tblauthors where empid=(select empid from tbljobs where jobid=6)

    because in your subquery if there are more than 1 tbljob records with jobid of 6 you will receive an error. change the "=" to "in" to avoid an error.

    to prevent records from deleting you will need to implement a trigger.

    Check the deleted virtual table everytime a record is deleted, and make sure the desired record is not there.

  • I have no problem with that coz it just has only 1 value.

     

    But i want to restricy delete in the store proc itself, how can i do that.

  • Can you please post your proc?

    or a similar example,

    How is your delete structured?

    Just a guess here.

    Delete tblAuthors

    where authID = @authid

      and empid <> (select empid from tbljobs where jobid=6)

    It would be better if you post your procedure so we can see what your doing.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply