473,574 Members | 3,067 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 21465
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
4571
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
5599
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...
4
3927
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...
3
4196
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...
1
8345
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...
1
1869
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
2561
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...
12
4696
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
1733
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...
0
7764
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...
0
8110
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8138
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...
1
5658
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...
0
5336
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3775
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...
0
3794
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1102
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...

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.