C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

Triggers


Posted Date: 26 Jun 2009      Posted By: Shanthi Ramamoorthy      Member Level: Bronze     Points: 1   Responses: 8



Hi,
How to create trigger.
Pl help me.
have to insert only one value in table.





Responses

Author: Shunmuganathan M    26 Jun 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Refer my resource. you will get good idea.

http://www.dotnetspider.com/resources/29332-Magic-tables-SQL-Server.aspx

By Nathan
Direction is important than speed
I am following the following Health Tips
http://dotnetspider.com/sites/1048/-Health-Tips-for-Healthy-Wealthy-IT.aspx



Author: UltimateRengan    26 Jun 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

SQL create trigger statement provides a way for the database management system to actively controls and monitor and manage the group of table when ever an update the data or delete the data or insert the data in that time performed.
Trigger excuted each time an sql insert,update,delete operation is performed.

create trigger tri_update on Emp
for update
as
begin
if update(EmpID)
begin
print'not update here'
rollback transaction
end
end

update Emp set EmpID='jj' where UserName='mahagr'
-------
output:
------
not update here
Msg 3609, Level 16, State 1, Line 1
The transaction ended in the trigger. The batch has been aborted.


different types of triggers:-

Row Triggers and Statement Triggers
BEFORE and AFTER Triggers
INSTEAD OF Triggers
Triggers on System Events and User Events

Advance Happy Diwali
SAP B1



Author: Anil Kumar Pandey    26 Jun 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

hi,

please refer this code..



CREATE TABLE tabname (
Col1 int,
Col2 VARCHAR2(20),
Col3 VARCHAR2(20)
)
CREATE OR REPLACE TRIGGER tg1
AFTER INSERT OR UPDATE OR DELETE ON tabname
DECLARE
col VARCHAR2(20);
BEGIN
//statement
END


Thanks & Regards
Anil Kumar Pandey



Author: Shivshanker Cheral    26 Jun 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

The following DML trigger prints a message to the client when anyone tries to add or change data in the Customer table.



USE AdventureWorks;
GO
IF OBJECT_ID ('Sales.reminder1', 'TR') IS NOT NULL
DROP TRIGGER Sales.reminder1;
GO
CREATE TRIGGER reminder1
ON Sales.Customer
AFTER INSERT, UPDATE
AS RAISERROR ('Notify Customer Relations', 16, 10);
GO



Author: Narendra Reddy vajrala    26 Jun 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Right click on the table, to which table you want to write
there you will see some options select All Tasks --> ManageTriggers..

and follow the suggestion given by above members

--Naren
Challenge the Limits, But Don't limit the Challenges.
http://dotnethelpbynaren.blogspot.com/



Author: Krishnaveni    26 Jun 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

http://www.sql-server-performance.com/articles/dev/triggers_2000_p1.aspx


Author: shankar v    29 Jun 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

* Whenever an DML statment get insert update delete trigger will automatically works...

* Sample Code:
create trigger trigger_name
on table_name
for update
as
begin
if(select Empage from inserted)='58'
update Employee set EmpStatus='Retd'
end
This code refers when employee's age turns 58 automatically his/her employee status turns as Retd ...

Regards & Thanks
Shankar V
www.teaminnovative.in



Author: Pooja    29 Jun 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

To Create the trigger:

Create or replace function function name() returns trigger as'

declare
-----
------
begin
------
------
end;
CREATE OR REPLACE name
{BEFORE | AFTER}{INSERT | UPDATE | DALETE}ON table
FOR EACH{ROW | STATEMENT}
EXECUTE PROCUDURE Function(argumants);

To run the trigger:
whatever you hava written in trigger defination i.e insert ,update ,delete,
e.g. insert into emp values(1,14);
[ press enter];



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Stored proceudre
Previous : Retriving identity value
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use