473,791 Members | 3,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_u pdate_catalog_u df' 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 21481
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_u pdate_catalog_u df' 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
4581
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. Note that tbl_A.field_1 = tbl_B.field_1 and tbl_A.field_2 = tbl_B.field_2 . How do I write a trigger on tbl_A to get the corresponding record
10
5639
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 create a single View and specify also in this View the WHERE clause that is common in these stored procedures, I will have the new stored procecures changed to be like:
4
3937
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 the element outside of the table and then using cut & paste in HTML View to move it to the desired location, or by manually typing the code in using HTML View. The first technique sometimes does not automatically update the list of elements...
3
4208
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 for GroupBox2 to update table Table2, Update3 for GroupBox3 to update table Table3. And there is a function TotalUpdate for MyForm. The function TotalUpdate comprises of Update1, Update2, and Update3.
1
8355
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 system. Is this a good idea ? should i be using another table in between in case something happens on the other end? However, I tried something like this and it didn't recognize the selected table inside the bcp:
1
1882
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: Channel_ID, Name Table B User_Id,Channel_ID, Description
4
2568
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 than polling the database for changes all the time. My initial problem is that I need to create a static list so that it can be dynamically looked at by other assemblies, but SQL Server won't allow me to attach a dll which contains a static...
12
4714
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 variable in the url. I would like that variable to trigger a stored and
2
1741
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 : CURR_DAY(date),DISCONNECTIONS(number) I am inserting data in ST_INFO using SQLLOADER.I want to populate TOTALS with the TIME,count of TIME field after insertion. CREATE OR REPLACE TRIGGER TRI_TOTALS AFTER INSERT ON ST_INFO FOR EACH ROW BEGIN
0
9517
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9997
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5435
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.