473,385 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Using a trigger on a view

I have never written a trigger before, but I have a couple of uses for
them now so I am trying. I have a view that I created and I want to
have this trigger, run anytime the view is run. I don't know if my
problem is with the trigger or permissions on the view, right now I
have given everyone permission to select and update on the view (just
trying to figure this out). Here is the begining of my trigger.

use OTB
If Exists (Select name from sysobjects
Where name='trg_otb_update_catalog_udf' and type='TR')
Drop Trigger trg_otb_update_catalog_udf
Go
Create Trigger trg_otb_update_catalog_udf
On vw_OTB_catalog
For Insert, update
as
Update ar_cust_udf
set part_catalog=c1.parts_catalog
etc...

Everything in the update statement to the end of the trigger works as
I intended. However when I run this it will not create the trigger,
instead it errors and returns the following:

Server: Msg 208, Level 16, State 4, Procedure
trg_otb_update_catalog_udf, Line 1
Invalid object name 'vw_OTB_catalog'.

However this is the correct view name.
any ideas?
Thanks,
Mike
Jul 20 '05 #1
3 21451
On 15 Apr 2004 08:41:20 -0700, Mike wrote:
I have never written a trigger before, but I have a couple of uses for
them now so I am trying. I have a view that I created and I want to
have this trigger, run anytime the view is run. I don't know if my
problem is with the trigger or permissions on the view, right now I
have given everyone permission to select and update on the view (just
trying to figure this out). Here is the begining of my trigger.

use OTB
If Exists (Select name from sysobjects
Where name='trg_otb_update_catalog_udf' and type='TR')
Drop Trigger trg_otb_update_catalog_udf
Go
Create Trigger trg_otb_update_catalog_udf
On vw_OTB_catalog
For Insert, update
as
Update ar_cust_udf
set part_catalog=c1.parts_catalog
etc...

Everything in the update statement to the end of the trigger works as
I intended. However when I run this it will not create the trigger,
instead it errors and returns the following:

Server: Msg 208, Level 16, State 4, Procedure
trg_otb_update_catalog_udf, Line 1
Invalid object name 'vw_OTB_catalog'.

However this is the correct view name.
any ideas?


Hi Mike,

Let's just say that Microsoft can be nominated for the most misleading
error message of the year, okay?

The only type of triggers defined on a view are "instead of" triggers.
Change "For Insert, update" to "Instead of Insert, update" and this
error message will go away.

Remember - if an instead of trigger is defined, SQL Server will not
attempt to change any data in the base tables. You will have to make
sure that the trigger will apply the changes the user expects from his
of her data modification statement.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2
Ok, so say I want a piece of SQL code to run everytime the view is
accessed, even if no changes were made. Is there a way to do this that
I am not think of either through this trigger or some other way in SQL?

I realize that I could set up a batch file or write a program that would
accomplish this, but that really isn't what I am looking for. I want to
be able to use this view in a report, and then have it run the update
statement automatically without further end user intervention.

I am just trying to make a 2 step process into 1 step for the end user.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
On 15 Apr 2004 20:57:14 GMT, Michael Rea wrote:
Ok, so say I want a piece of SQL code to run everytime the view is
accessed, even if no changes were made. Is there a way to do this that
I am not think of either through this trigger or some other way in SQL?

I realize that I could set up a batch file or write a program that would
accomplish this, but that really isn't what I am looking for. I want to
be able to use this view in a report, and then have it run the update
statement automatically without further end user intervention.

I am just trying to make a 2 step process into 1 step for the end user.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Hi Michael,

It is possible to fire a trigger each time a delete, insert or update
statement is executed against a view, even if no actual modifications
were made. (A delete or update with no rows matching the where cluase,
an insert .. select with the select returning an empty result set or
an update that sets columns to the value they already had).

It is however NOT possible to fire a trigger on a select against a
view (or a table, for taht matter). Triggers are designed to fire on
data *modification* statements.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: June Moore | last post by:
Hi all, I have two tables tbl_A and tbl_B. Table Definitions: tbl_A (field_1, field_2, field_3) tbl_B (field_1, field_2) I would like to populate tbl_B when a record is inserted into tbl_A....
10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I...
4
by: Nathan Sokalski | last post by:
When editing an ASP Table, Visual Studio does not allow me to edit it in Design View. This makes it harder to add elements, because I must add every element either by using Design View to create...
3
by: Jason Huang | last post by:
Hi, MyForm is a C# Windows Form. MyFom has 3 GroupBoxes. Now I wanna update data from the textboxes in those 3 GroupBoxes. I have function Update1 for GroupBox1 to update table Table1, Update2...
1
by: lytung | last post by:
Hi all, i am having trouble trying to export this in xml. Basically inside an update trigger i need to export in xml or file the qty that has been changed. This then gets updated to another...
1
by: gaurkamal | last post by:
I want to delete record in table B when i delete record in Table A both table have a common column. I want to do it using trigger .Can any body give some idea. Table details are. Table A: ...
4
by: simo | last post by:
I have a requirement to create a sorted list of objects, stored within an assembly, and I would like to use a After Insert/Update trigger to notify that assembly that something has changed, rather...
12
by: brwalias | last post by:
Hi, using .net 2 sql server 2005 Here is my situation: I'm passing a variable in the url from a selection on Page A and need to display the results on the Results page be based on that...
2
by: potti | last post by:
Hi, I am inserting data in table1.using a trigger I want to populate TABLE2.My code is like this : TABLE1 :ST_INFO FIELDS : NAME (varchar),ACCOUNT_TYPE(varchar),TIME(date) TABLE2 :TOTALS FIELDS...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.