Trigger in sybase - triggers

I have requirement where trigger needs to be created on same table.
Here is the condition,
When A code is inserted into table at the same time trigger gets involved and writes B code
Where Type is column which will be having value as A then need to insert Type column only With B value rest thing will remain same .
Please assist

Related

How to create tsvector_update_trigger on Non-character type data

How can we create tsvector update trigger on Non-character data type.
For example, i have created a ts vector trigger something like this.
CREATE TRIGGER tr_doc_id_col
BEFORE INSERT OR UPDATE
ON document
FOR EACH ROW
EXECUTE PROCEDURE tsvector_update_trigger('tsv_doc_id', 'pg_catalog.english', doc_id');
Here,
tr_doc_id_col -- Name of the trigger
document -- Name of the table
tsv_doc_id -- tsvector form of the doc_id
doc_id -- Name of the column. It's data type is integer
This trigger should update the tsv_doc_id, when there is insert, delete or update happens on doc_id column.
But, the trigger is throwing an error saying that doc_id is not of character type (i.e it is not able to update based on non-character type column).
I have tried creating same kind of triggers on columns like title, body which are text data type. In this case it is working very well, but in the earlier case.
Can any of you tell me how to do in the case of non-character data type like doc_id?
tsvector_update_trigger is just a convenience function, and it does what it does. You can always write your own implementation of it with whatever embellishments you want (in this case, casting to text), but you can't change the behavior of the existing one. But it is also rather obsolete. The modern way to do it is with GENERATED columns.
create table document (
doc_id int,
tsv_doc_id tsvector generated always as (to_tsvector('english',doc_id::text)) stored
);
Although I would question the utility of a tsvector which always contains exactly one integer.

Trigger on any column change except specific one

I want to trigger on all column changes on a table except a specific one, but listing all the columns in the AFTER INSERT OR UPDATE OF clause is a problem because the table has many columns and the set of columns changes at times, making maintaining the trigger definition in sync very error prone. How can I do this in a way that I just specify the column to omit from the trigger? For the moment I have an event trigger that prints a warning to update the trigger when that table is altered, but that relies on the user noticing the warning and obviously won't help when creating a new db.

Triggering Code when a specific value is inserted into a table column in an Azure SQL Table

I am seeking suggestions on methods to trigger the running of code based on specific event occurring.
Basically I need to monitor all inserts into a table and compare a column value against a parameter set in another table.
For example, when a new record is added to the table and the column [Temperature] is greater than 30 (which is a value set in another table). Send an alert email to notify of this situation.
You can create a trigger (special type of stored procedure) that is automatically executed after an insert happened. Documentation for triggers is here: https://technet.microsoft.com/en-us/library/ms189799(v=sql.120).aspx
You will not be able to send an email out of SQL Database though.
Depending on how quick you need the notification after the insert, maybe you could make an insert into yet another table from within the trigger and query this new table periodically (e.g. using a script in Azure automation) and have the email logic outside the database.

Can "Insert Trigger For Each Row After Each Statement" use index with the newly added values?

I am using Postgres 9.3.
I just added a trigger to a table.
It is an after insert trigger which is executed for each row after each statement.
I coded the trigger function assuming the index of the same table contains the newly added rows.
If this is not true, mass inserts will slow down significantly.
I google it a bit but couldn't find an answer.
So, to sum up my questions is after a statement, is index updated before or after the "after insert trigger for each statement" in Postgres 9.3?
Here is the trigger definition I've used:
CREATE TRIGGER trigger_name
AFTER INSERT OR UPDATE
ON table_name
FOR EACH STATEMENT
EXECUTE PROCEDURE trigger_funtion();
An AFTER trigger FOR EACH ROW will see that row in the table. For that to happen reliably the row must have already been added to any indexes. So the index has been updated.
However, if you attempt to modify the table that caused the AFTER trigger to be fired within the AFTER trigger, this usually results in an infinite loop and an error. It is rarely the correct thing to do.
Usually when you're trying to do that, you actually want a BEFORE trigger that modifies the row before it is saved.
If you need to modify some other row in the same table, that often suggests a data model problem. You should very rarely, if ever, need to modify one row in a table using a trigger when a different row is modified.

How to send Postgres procedure entire record from trigger

I am new to Postgres (9.0.5) and have written very few functions/triggers in general. I would like to set up a trigger on my widgets table such that every time a widget is inserted, updated or deleted, the entire record is passed to a stored procedure as an argument. The procedure can then inspect the record for various changes and decide what action to take. Here's my best attempt so far, though I know I'm way off course:
CREATE OR REPLACE TRIGGER tg_widgets
ON TABLE widgets
AFTER EVERY INSERT, UPDATED, DELETE
DO run_widget_handler
CREATE OR REPLACE PROCEDURE run_widget_handler AS
# Definitition here
# If the widget's name was changed, do X
# Else if the widget's wow_factor was changed, do Y
# Else, do Z
I'm not worried about how to implement the definition of run_widget_handler, just looking for help and writing the trigger and passing the widget to the proc. Thanks in advance.
You don't need to "pass" the row to the trigger function (btw: there is no "procedure" in PostgreSQL, only functions).
If the function is declared as "returns trigger", you can automatically access the complete row as "new" or "old".
More details in the manual: http://www.postgresql.org/docs/current/static/plpgsql-trigger.html