Need Help In Trigger

  • Hi ,

    I had created one view, which is derived from table from diff. DB on the same server.

    Now I m creating trigger on the view it is giving an ERROR

    " The object % does not exist or is invalid for this operation."

    ????

    Regards,

    Abhijit

  • Can you post the text of the view and the trigger please?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Text of the view contains only...

    SELECT *

    FROM

  • Select * from ..... ????

    And the trigger?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • sorry for d wrong reply...

    Select * from of object on diff DB.

    & trigger contains..... inserting record in history table, which schema is same.

  • Can you please post the code? You can change the table and column names if needed. It's hard to debug from descriptions

    Is the history table in the DB with the view, or the DB that the view is referencing?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Create table dbo.tmpTriggerTest

    (

    IDINT IDENTITY(1, 1),

    Value1VARCHAR(10)

    )

    GO

    Create table dbo.tmpTriggerTestHistory

    (

    IDINT,

    Value1VARCHAR(10)

    )

    GO

    Create View dbo.vw_tmpTriggerTest

    AS

    SELECT * FROM dbo.tmpTriggerTest

    GO

    Consider tat tmpTriggerTest is a table from different DB on same server.

    I had created view namely vw_tmpTriggerTest which is deriveed from table

    tmpTriggerTest. Now, in SQL server we can create trigger on view i want to create trigger on view created.

    any queries plz revert. 🙂

  • The view as you've written it will select from a table in the same database as it is created. To select from a table in a different database, it should read

    Create View dbo.vw_tmpTriggerTest

    AS

    SELECT * FROM OtherDB.dbo.tmpTriggerTest

    GO

    (Replace OtherDB with the name of the database that the table is in)

    Do you have the trigger code please? Is the history table in the same DB as the table, or as the view?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Hi !,

    I have written the view in the same way as you had mentioned.

    I have added the one trigger for insert, update, delete operation, in which i just insert the inserted , updated, deleted row in history table

  • This is hard work, isn't it? You've been asked four times now to post the code of the trigger. You have to help yourself if you expect anyone else to help you.

    John

  • When the exact code of the view and the exact code of the trigger appear, I'll help you. Until then, you're wasting my time.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Hi gail i m not wasting any person time, i have already explained you the view and the trigger.

    but its k.. i got my answer thxs for your valueable time and replies

  • Explanations don't help much when debugging code. That's why I kept asking for the code of the trigger and view.

    I had an idea what might be wrong, but without seeing the actual trigger, I was just guessing.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Hi Abjhit,

    How did you solve it

  • Use "Instead OF" trigger instead of "FOR" trigger... Actually microsofts error message is misleading

Viewing 15 posts - 1 through 14 (of 14 total)

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