473,406 Members | 2,390 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,406 software developers and data experts.

SQL Triggers and stored procedures

Hi All,I have two tables in a database and need to create a trigger after update on one table so that it updates another. may u pliz help me with this problem I have.
May 16 '07 #1
8 1289
DeMan
1,806 1GB
Hi MandlaT,

Welcome to the scripts!! I will move this ost to the SQL forum for you. In future you can post there directly, by selecting the SQL forum from the "Forums" tab on the blus bar at the top of your screen.

I hope you find the information you need!
May 16 '07 #2
Thanks! I look forward to getting replies.
May 16 '07 #3
frozenmist
179 Expert 100+
Hi Mandla,
You can have the following syntax for the trigger
Expand|Select|Wrap|Line Numbers
  1. create trigger trigger_name on table1
  2. after update
  3. as
  4. begin
  5. update table2 set col=<new value> [where <condition>];
  6. end
  7.  
Hope this helps
Cheers
May 16 '07 #4
Thanks, will let you know about the outcome.
May 16 '07 #5
Thanks, It worked but I'm getting duplicate values. how can I solve the problem?
May 17 '07 #6
frozenmist
179 Expert 100+
Thanks, It worked but I'm getting duplicate values. how can I solve the problem?
Hi,
Can you give more input. May be the update statement you are using or the trigger

Cheers
May 17 '07 #7
Hi Thanks for answering me,
when there is an update on dstParameters it should set the trigger to update dstControlData. but am getting duplicate values. It should only accept different values on the date eg 200704 or 200705 on [dstYearMonth].
-- =============================================
-- Author: User
-- Create date: 17/05/2007
-- Description: Updating
-- =============================================
ALTER TRIGGER .[dbo].[updateData]
ON .[dbo].[dstSalesParameters]
AFTER UPDATE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;


-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
--DECLARE @data XML;

DECLARE @distributer nvarchar(15);
DECLARE @salesPeriod int;
DECLARE @salesRec int;
DECLARE @customerRec int;
DECLARE @materialRec int;
DECLARE @callSheetRec int;
DECLARE @importPriceRec int;
DECLARE @extractPriceRec int;
DECLARE @extractEquipRec int;




SET @distributer = (SELECT dstDistributer FROM inserted);
SET @salesPeriod = (SELECT SalesPeriod FROM inserted);
SET @salesRec = (SELECT ExtractSaleRec FROM inserted);
SET @customerRec = (SELECT ExtractCustomerRec FROM inserted);
SET @materialRec = (SELECT ExtractMaterialRec FROM inserted);
SET @callSheetRec = (SELECT ExtractCallSheetRec FROM inserted);
SET @importPriceRec= (SELECT ImportPriceRec FROM inserted);
SET @extractPriceRec = (SELECT ExtractPriceRec FROM inserted);
SET @extractEquipRec = (SELECT ExtractEquipmentRec FROM inserted)


--FROM dstSalesParameters

INSERT [dbo].[dstControlData]
(
--[dstControlID],
[dstAgentCode],
dstYearMonth,
dstSalesRec,
dstCustomerRec,
dstMaterialRec,
dstCallSheetRec,
dstIPriceRec,
dstEPriceRec,
dstEquipmentRec
)
VALUES
(
@distributer,
@salesPeriod,
@salesRec,
@customerRec,
@materialRec,
@callSheetRec,
@importPriceRec,
@extractPriceRec,
@extractEquipRec
);





END
May 17 '07 #8
Dear MandlaT,

I am not totally clear what you're asking but maybe you want to do a select on dstControl for the Yeardate you are about to insert so that you do so only if it doesnot exist.

Regards
MakingDBA
May 20 '07 #9

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

Similar topics

17
by: serge | last post by:
How can i delete all user stored procedures and all table triggers very fast in a single database? Thank you
1
by: Manish Bafna | last post by:
speaking of me, I'm not very new to Access, but I haven't worked on it as a professional. I know that you can fire queries in Access, but I don't think you can create views. i want to know that...
1
by: jagdpenta | last post by:
This is my second post What are the advantages of stored procedures, triggers, indexes E-Mail address blocked: See forum rules - moderator Thanks in advance
1
by: Miaaa Mukherjee | last post by:
Hello, I want to know something about the stored procedures and triggers which are used. I want to know that the procedures n triggers r created in SQL Server 2005 or...
5
by: FP | last post by:
Hi, i have read that with Visual Studio 2005 it's possible to create stored procedures and triggers for a Sql Server 2005 database. I must admit that i have already written the stored procedures...
2
by: cvraghavan1979 | last post by:
Hi guys, let me know the difference between the use of direct queries and the stored procedures / Triggers. also pls specify the advantages of using the stored procedures / triggers....
2
by: sonia.sardana | last post by:
Hey can anyone tell me whether Triggers and Stored Procedures are same? Triggers are stored procedures that get executed automatically when an Insert,Update,or Delete operation takes place. ...
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?
1
by: anuragshrivastava64 | last post by:
I am new to SQL Server. I have got a project where lot of stored procedures ,UDF's and triggers are used. The problem is I am finding all the functions and procedures but not been able to find any...
2
by: ajaysbedi | last post by:
Hi, I have 2 triggers on a table, both triggers are updating the another table create trigger DB.TRG1 AFTER INSERT ON Table1REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL WHEN ( NEW.DEPT <>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.