Trigger and procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahulae
    New Member
    • Jul 2008
    • 29

    Trigger and procedure

    given a propertyid and sale amount the system should change property status to 'sold'
    when it is marked sold askingprice should be added to totalsales.

    property(proper ty_id,property_ name,asking_pri ce,status,total _size,address,c ity,state,agent _id)

    agent(agent_id, last_name,first _name,start_dat e,contact_no,to tal_sales,prope rty_id)
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Sounds like homework. What have you done so far?

    Comment

    • rahulae
      New Member
      • Jul 2008
      • 29

      #3
      some how not getting the idea to do it

      help me

      Comment

      • rahulae
        New Member
        • Jul 2008
        • 29

        #4
        procedure

        create proc sp_prop_status
        (@property_id int,@asking_pri ce float(2))
        as
        begin
        If not exists (select * from property where property_id=@pr operty_id)
        begin
        select 'not a valid property'
        return
        end

        begin transaction
        update property set status = 'sold'
        where property_id=@pr operty_id
        if @@error <>0 or @@rowcount <> 1
        begin
        rollback transaction
        select 'insert failed'
        return
        end
        commit transaction
        end

        This is what i have done
        Last edited by rahulae; Jul 29 '08, 06:25 PM. Reason: updation

        Comment

        • rahulae
          New Member
          • Jul 2008
          • 29

          #5
          im not able to implement the 2nd part adding asking_price to total_sales when it is marked sold

          Comment

          • rahulae
            New Member
            • Jul 2008
            • 29

            #6
            delerna or administrator plz help me out

            Comment

            • ck9663
              Recognized Expert Specialist
              • Jun 2007
              • 2878

              #7
              Looks like you're expecting to update only 1 record with this condition @@rowcount <> 1, otherwise it rolls back.

              -- CK

              Comment

              • rahulae
                New Member
                • Jul 2008
                • 29

                #8
                yes ur right after updating status i should be able to use trigger to update total_sales

                Comment

                • ck9663
                  Recognized Expert Specialist
                  • Jun 2007
                  • 2878

                  #9
                  I mean record, not column.

                  If your table have many rows that will be updated @@rowcount is > 1 hence it rolls back.

                  If this is a homework, you have to figure out the rest.

                  -- CK

                  Comment

                  Working...