update 'inserted' table in trigger

Hello All,

i have some calculated fields while inserting.
is there any way to update the 'inserted' table in trigger?

or the only method
is to write a stored-proc to do 'calcule then insert'

Thanks.

Alien Chen
05/14/2002





0
Alien
5/14/2002 1:01:47 AM
sybase.ase.general 8655 articles. 0 followers. Follow

4 Replies
590 Views

Similar Articles

[PageSpeed] 15

alien@sol.com.tw wrote...
> Hello All,
> 
> i have some calculated fields while inserting.
> is there any way to update the 'inserted' table in trigger?
> 
> or the only method
> is to write a stored-proc to do 'calcule then insert'

Within the trigger you would use the INSERTED table to figure out which rows in the actual 
table had been inserted and you would update them.  Something like this:

UPDATE main_table
SET column1 = ...
FROM INSERTED 
WHERE main_table.key_column = INSERTED.key_column

-- 
Jim Egan [TeamSybase]
Senior Consultant
Sybase Professional Services
0
Jim
5/14/2002 3:38:32 AM
Hi Jim,

Does this actually works? Using update "main" table using "inserted" may
cause cycling, e.g. if used in trigger for update:
update fires trigger which updates main table and thus fires trigger again
and again....
Is it true?

Regards

Alexander Mitchenko

"Jim Egan" <dontspam.dbaguru@eganomics.com> wrote in message
news:MPG.174a34a4dfe7089998be2f@forums.sybase.com...
> alien@sol.com.tw wrote...
> > Hello All,
> >
> > i have some calculated fields while inserting.
> > is there any way to update the 'inserted' table in trigger?
> >
> > or the only method
> > is to write a stored-proc to do 'calcule then insert'
>
> Within the trigger you would use the INSERTED table to figure out which
rows in the actual
> table had been inserted and you would update them.  Something like this:
>
> UPDATE main_table
> SET column1 = ...
> FROM INSERTED
> WHERE main_table.key_column = INSERTED.key_column
>
> --
> Jim Egan [TeamSybase]
> Senior Consultant
> Sybase Professional Services


0
Alexander
5/27/2002 3:08:09 PM

it will only fire again when you've done "set self_recursion on". By
default this is off.

HTH,

Rob V.

"Alexander Mitchenko" <alex@alexm.carrier.kiev.ua> wrote in message
news:X$v0ACZBCHA.200@forums.sybase.com...
> Hi Jim,
>
> Does this actually works? Using update "main" table using "inserted"
may
> cause cycling, e.g. if used in trigger for update:
> update fires trigger which updates main table and thus fires trigger
again
> and again....
> Is it true?
>
> Regards
>
> Alexander Mitchenko
>
> "Jim Egan" <dontspam.dbaguru@eganomics.com> wrote in message
> news:MPG.174a34a4dfe7089998be2f@forums.sybase.com...
> > alien@sol.com.tw wrote...
> > > Hello All,
> > >
> > > i have some calculated fields while inserting.
> > > is there any way to update the 'inserted' table in trigger?
> > >
> > > or the only method
> > > is to write a stored-proc to do 'calcule then insert'
> >
> > Within the trigger you would use the INSERTED table to figure out
which
> rows in the actual
> > table had been inserted and you would update them.  Something like
this:
> >
> > UPDATE main_table
> > SET column1 = ...
> > FROM INSERTED
> > WHERE main_table.key_column = INSERTED.key_column
> >
> > --
> > Jim Egan [TeamSybase]
> > Senior Consultant
> > Sybase Professional Services
>
>

0
Rob
5/27/2002 3:27:48 PM
Thanks, Rob

Never use his option before

Alexander Mitchenko

"Rob Verschoor" <rob@DO.NOT.SPAM.sypron.nl.REMOVE.THIS.DECOY> wrote in
message news:YoN6HRZBCHA.289@forums.sybase.com...
>
>
> it will only fire again when you've done "set self_recursion on". By
> default this is off.
>
> HTH,
>
> Rob V.
>
> "Alexander Mitchenko" <alex@alexm.carrier.kiev.ua> wrote in message
> news:X$v0ACZBCHA.200@forums.sybase.com...
> > Hi Jim,
> >
> > Does this actually works? Using update "main" table using "inserted"
> may
> > cause cycling, e.g. if used in trigger for update:
> > update fires trigger which updates main table and thus fires trigger
> again
> > and again....
> > Is it true?
> >
> > Regards
> >
> > Alexander Mitchenko
> >
> > "Jim Egan" <dontspam.dbaguru@eganomics.com> wrote in message
> > news:MPG.174a34a4dfe7089998be2f@forums.sybase.com...
> > > alien@sol.com.tw wrote...
> > > > Hello All,
> > > >
> > > > i have some calculated fields while inserting.
> > > > is there any way to update the 'inserted' table in trigger?
> > > >
> > > > or the only method
> > > > is to write a stored-proc to do 'calcule then insert'
> > >
> > > Within the trigger you would use the INSERTED table to figure out
> which
> > rows in the actual
> > > table had been inserted and you would update them.  Something like
> this:
> > >
> > > UPDATE main_table
> > > SET column1 = ...
> > > FROM INSERTED
> > > WHERE main_table.key_column = INSERTED.key_column
> > >
> > > --
> > > Jim Egan [TeamSybase]
> > > Senior Consultant
> > > Sybase Professional Services
> >
> >
>


0
Alexander
5/27/2002 3:46:33 PM
Reply:

Similar Artilces:

Is having a trigger that inserts a row in Table 'A', when a row in same table is inserted by ADo.Net code?
I want to insert a row for a Global user  in Table 'A' whenever ADO.Net code inserts a Local user row into same table. I recommended using a trigger to implement this functionality, but the DBA was against it, saying that stored proecedures should be used, since triggers are unreliable and slow down the system by placing unecessary locks on the table. Is this true OR the DBA is saying something wrong? My thinking is that Microsoft will never include triggers if they are unreliable and the DBA is just wanting to offload the extra DBA task of triggers to the programmer so that a s...

Empty 'inserted' table in insert trigger
I have a table with insert trigger. Inside the trigger, I write records from the inserted table to another table. However, I found that the inserted table is empty. Any Idea? I am using ASE 12.5.0.3 Thanks in advance. not impossible. something like: insert tbl select * from other_tbl where 1=2 would fire the trigger, but not insert any rows, and have no corresponding rows in the inserted table. <Vicky> wrote in message news:4330d6dd.2d0a.1681692777@sybase.com... > I have a table with insert trigger. Inside the trigger, I > write records from the inserted tabl...

Error: Primary key for row in table 'x' is referenced by foreign key 'f' in table 'y'
(ASA 9 newest ebf) I'm getting this error even though mentioned foreign key has cascade updates (and deletes too) enabled. Is this some new behaviour in asa 9, or why can i get such message for cascaded foreign key? Any ideas? Thanks Pete Found a reason for it...but should it really work so? It's this way: - table a has columns a,b,c - table b has columns a,c, and references columns a,c (with a,c) in table a with cascade updates - table a hes before update trigger to change columns a when column b is changed (set new_row.a = ...) and that set new_row.a = ... i...

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

Update unable to find TableMapping['Table'] or DataTable 'Table'
hi! i got the following error message while trying to update an access db: Update unable to find TableMapping['Table'] or DataTable 'Table' i have the following code in my application: IDbDataAdapter yadAdapter = new OleDbDataAdapter(); OleDbCommand yadCommand = new OleDbCommand(); yadCommand.Connection = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=c:/inetpub/wwwroot/yad/Data/ASPNetDB.mdb"); yadAdapter.TableMappings.Clear(); yadAdapter.TableMappings.Add("NV", nvTable.ToString()); yadAdapter.TableMappings.Add("FV",...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

General Error: Unable to find in index 'index_description' for table 'ZZZ'
Does anyone know what can cause this error? For some reason we have been getting these errors lately, seeming spontaneously. There have been no updates or anything that correspond with several occurances of this issue. Sybase SQL Anywhere 7. what does dbvalid tell you? -- /steve Stephen Rice Sybase iAnywhere <Jeff Conrad> wrote in message news:46114cda.4764.1681692777@sybase.com... > Does anyone know what can cause this error? For some reason > we have been getting these errors lately, seeming > spontaneously. There have been no updates or anything that ...

DetailsView Insert Error: Cannot insert the value NULL into column 'customer', table 'DEMO
Using VWD Express edition creates a page(Default.aspx) with a Dropdownlist for selecting a customer and a GridView to show the details of the selected customer and to edit and delect a customer's detail. I add a button to link to page Add.aspx for add a new record. I add a DetailsView and the following code so it goes to New record mode when page loads:        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)               DetailsView1.ChangeMode(Det...

Error in Tutorial DetailsView"Cannot insert the value NULL into column 'contract', table 'pubs.dbo.authors'; column does not allow nulls. INSERT fails.
Hi,I am trying to do the insert part of detail's view Tutorial (the last one) and I received this error: "Cannot insert the value NULL into column 'contract', table 'pubs.dbo.authors'; column does not allow nulls. INSERT fails.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'contract', table 'pubs.dbo.authors'; column does not allow nulls. INSER...

getting the error: Cannot insert the value NULL into column 'name', table 'InterGlobe.dbo.IG_Admin'; column does not allow nulls. INSERT fails. The statement has been terminated.
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <script runat="server">   private void CrLogin_Click(object source, EventArgs e) {   try { //Response.Write("hello"); SqlDataSource2.Insert(); // Response.Redirect("logincreated.aspx"); } catch(Exception ex) { Response.Write(ex.Message); }   } </script>       <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">       &nbsp;<a...

How to INSERT INTO [Table] ([Field]) VALUES('I Have a ' in value')
Hi, I want to INSERT INTO [Table] ([Field]) VALUES('I Have a ' in value') please teach me how to xxx INSERT INTO [Table] ([Field]) VALUES('I Have a '' in value') instead of one single quote, u need to add one more.Om Prakash Use Parameterized Queries ...you woudnt have to worry about escape characters besides saving your db from sqlinjection attacks. hth***********************Dinakar NethiLife is short. Enjoy it.***********************...

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\NW.pm to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified NW.pm, it calls t/uni/case.pl, that, in case.pl, (when the path separators are '\'), the $file is '..\lib\unicore\To\Lower.pl' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

Providers: 'user' table vs 'aspnet_Users' table
Hi, I'm starting to write a set of custom providers- Membership, Role, and Profile.  The Membership provider accesses a table called 'user', and I just noticed that the 'Profile' provider appears to call a similarly named table called 'aspnet_Users'.  Are these tables similar in purpose?  I don't understand why the Profile provider would access a membership table other than the 'user' table; I'd prefer to ignore the 'aspnet_Users' table, but I doubt that it's possible. Can anyone explain how these tables are different or related in the overall provider model? B...

'Tab' N 'Insert'
Hello Friends, I want to insert a new row in my grid datawindow, whenever I press 'Tab' from the last column of the last row of my datawindow. Thanks Rahul Patodi In the user event mapped to the pbm_dwnkey event id put this: string ls_text long ll_row IF key = KeyTab! THEN IF THIS.GetColumn() = dw_1.Object.DataWindow.Column.Count THEN IF dw_1.GetRow() = dw_1.RowCount() THEN ll_row = dw_1.InsertRow(0) dw_1.ScrollToRow(ll_row) dw_1.SetRow(ll_row) END IF END IF END IF Rahul Patodi wrote: > Hello Friends, > I want to insert a new row i...

Web resources about - update 'inserted' table in trigger - sybase.ase.general

Resources last updated: 12/23/2015 2:24:38 PM