Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Triggers

This is a discussion on Triggers within the SQL forums, part of the Databases category; How to wite Tiggers in sql? Give me the example.........

Go Back   Geeks Talk > Databases > SQL
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 04-22-2008
Junior Member
 
Join Date: Apr 2008
Location: visakhaptnam
Posts: 18
Thanks: 2
Thanked 2 Times in 1 Post
ushalakshmi is on a distinguished road
Triggers

How to wite Tiggers in sql?
Give me the example......
Reply With Quote
The Following 2 Users Say Thank You to ushalakshmi For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 04-23-2008
Junior Member
 
Join Date: Apr 2007
Posts: 5
Thanks: 3
Thanked 0 Times in 0 Posts
keerthv is on a distinguished road
Re: Triggers

Lets say you want to create trigger on table1 having columns id and name.

The syntax would be

create trigger insert on my_table as
begin
insert into my_table values (0,"new NAME inserted")
end

for any insert into your my_table object as below:

insert into my_table values (1,"name1")

O/P will be:

id name
-- ------
1 name1
0 new NAME inserted

The above is an example for insert trigger.

Similarly you can create update and delete triggers.

Last edited by keerthv; 04-23-2008 at 06:58 AM.
Reply With Quote
  #3 (permalink)  
Old 04-23-2008
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,853
Thanks: 9
Thanked 168 Times in 142 Posts
debasisdas has a spectacular aura aboutdebasisdas has a spectacular aura about
Re: Triggers

By SQL if you mean SQL Server then please find a related discussion here.
Reply With Quote
The Following User Says Thank You to debasisdas For This Useful Post:
  #4 (permalink)  
Old 07-01-2009
Junior Member
 
Join Date: Jul 2009
Location: Hyd
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
es77398 is on a distinguished road
Re: Triggers

Hi usha, here is an example.. Example to create table level or statement triggers create or replace trigger secure_emp before insert on emp begin if to_char(sysdate,’dy’) in(‘sat’,’sun’) or to_char(sysdate,’hh24:mi’) not between ’08:00’ and ’18:00’ then raise_application_error(-20001,’you may insert into emp table only during business hours..’); end if; end; / here is the output.. testing secure_emp insert into emp (empno, ename) values (101,’ravi’); error at line 1 ora-20001 you may insert into emp table only during business hours ora-06512 at plsql secure_emp, line 4 ora-04088 error during execution of trigger “plsql secure_emp” regards, e.sagar.
Reply With Quote
  #5 (permalink)  
Old 07-01-2009
Contributing Member
 
Join Date: Jun 2009
Location: United States
Posts: 71
Thanks: 0
Thanked 5 Times in 4 Posts
CSOOR is on a distinguished road
Re: Triggers

Please mention the server name.
Reply With Quote
Reply

  Geeks Talk > Databases > SQL

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Views, Triggers, Normalization bharathi_ark SQL Server 9 11-10-2007 06:21 AM
which Triggers have been Expired in Oracle 10g Medix Oracle Apps 0 08-03-2007 04:06 PM
Sequence of commit triggers Geek_Guest Oracle 0 07-10-2007 01:49 PM
About Report Triggers JobHelper Oracle 3 01-09-2007 08:01 AM
Triggers Types scott SQL 1 07-30-2006 07:18 PM


All times are GMT -4. The time now is 05:14 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved