473,385 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Could anyone help me in writing triggers? Plzz

I have an employee table which contains the fields EmpId,EmpName,DeptId,DateOfJoin,Sal,Addr

how to write a trigger for this table such that

whenever a new employee is added to the employee table one row should be added in the Finance table(ID,SAL) for that employee and update Department table(DeptId,DeptName,NoOfEmployees)

such that Department.NoOfEmployees = Department.NoOfEmployees + 1

and whenever an employee s deleted the reverse operation shud take place

and also Whenever the salary field is updated the difference should be updated in the finance table.

Please tell me how to use Insert,Update Delete triggers for this table?
Jul 5 '07 #1
5 1724
debasisdas
8,127 Expert 4TB
Since you had posted a question in Article section it it being moved to Oracle forum.
Jul 5 '07 #2
debasisdas
8,127 Expert 4TB
create an after INSERT or DELETE trigger
if inserting then
insert the new id and sa l into finance table.
also do the same on department table and update the no foemployees by the total numbers of records in the table.

do the reverse in delete event.

if u still have any doubts do post back next time with the code you have tried .
Jul 5 '07 #3
Actually i m a fresher and nevr tried triggers cud u giv an example so that i can try and get back to u with the code.. the table stryctures are

Employee (EmpID, EmpName,DeptID DateOfJoin, Sal, Addr)
Finance (EmpID, Sal)
Club (Clubname, EmpID, Fee, DateOfJoin)
Leave (EmpID, Date)
Department (DeptID, DeptName, NoOfEmployees)
Jul 6 '07 #4
debasisdas
8,127 Expert 4TB
Please find the details regarding triggers here.

Hope that helps you in understanding triggers better.
Jul 6 '07 #5
1. CREATE OR REPLACE TRIGGER mytrig
2. After INSERT ON Employee
3. FOR each ROW
4. BEGIN
5. IF inserting THEN
6. INSERT INTO Finance VALUES(:NEW.empno,:NEW.sal);
7. UPDATE INTO Department SET Department.NoOfEmployees = Department.NoOfEmployees + 1;
8. END IF;
9. END;

Wil dis query work? plz correct if der s anythng wrong...
Jul 6 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: vegetax | last post by:
I was a java developer one year ago ,before i moved to python i realy liked it at the beggining, but i got very disapointed lately since my previus two python proyects where relatively big,and...
1
by: aj | last post by:
plzz help me to add How a Blank row in a datagrid without using dataset or any other. plzzz help me
40
by: dev_cool | last post by:
hello everybody, i'm a new member of this group, this is my first ever post. i've found a c program that prints prime numbers through an infinite loop. But I really don't understand the code....
5
by: irin07 | last post by:
hello... i just learn how to use php,can anyone help me about how to edit database using php,plzz....i need urgently and i really blank about this. this the database dbhelpdesk table...
0
debasisdas
by: debasisdas | last post by:
trigger sample code Ex#10 ======================= INSTEAD OF TRIGGER ---------------------------------------- create or replace trigger mytrig instead of delete or insert or update on eview...
0
debasisdas
by: debasisdas | last post by:
This thread contains some useful tips/sample codes regarding TRIGGERS in oracle, that the forum members may find useful. TRIGGERS: =============== Database trigger is a PL/SQL block that is...
2
by: localp | last post by:
what is a web site and file architecture ? why do we write it ? and what is its content ? plzz help me.
4
by: --CELKO-- | last post by:
I need to convert a bunch of DB2 triggers to Oracle. Is there any kind of tools for this?
3
by: ABOD | last post by:
hi all...plzz..help me to solve this Q. write a multithreading program to multiply ttwo matrices M and N. The two matrices may have differnrt size. M is (r*w) and N is(w*z) The result is a r*z...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.