473,466 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How are parameters passed in Triggers?

nitindel
67 New Member
Hi All,
May i know how do we pass parameters in Triggers and if no parameters are passed then how they get fired...??

Thanks & Regards
Nitin Sharma
Jun 26 '08 #1
13 10526
debasisdas
8,127 Recognized Expert Expert
trigger do not require parameters. They execute automatically on the related database events.
Jun 27 '08 #2
ck9663
2,878 Recognized Expert Specialist
Trigger does not dictate whether a trigger will fire or not. Triggers are based on events that happen to your table, not the parameters inside it.

-- CK
Jun 29 '08 #3
coolminded
137 New Member
Trigger does not dictate whether a trigger will fire or not. Triggers are based on events that happen to your table, not the parameters inside it.

-- CK
hi,
what if i need to send some extra field to be inserted when a trigger gets fired.
i have a table and when a trigger is fired, the content of that table is inserted in the next table with the same table structure but with one more field 'modified_by'. how can i insert the field 'modified_by' when that trigger is fired. modified_by can be any name through which the application is logged in.
thanx
Jun 30 '08 #4
debasisdas
8,127 Recognized Expert Expert
yes you can do that .

but what is the problem ?
Jul 2 '08 #5
coolminded
137 New Member
yes you can do that .

but what is the problem ?
Hi Debasisdas,

let me clear my confusion,
i have 2 tables tbl_1, tbl_2.
tbl_1 contains id,name and address. and tbl_2 contains old_id, old_name, old_address, new_id, new_name, new_address and modified_by.
i wrote one trigger which inserts the old values as well as the new values in tbl_2 when there is any updation or deletion in tbl_1.

now my problem is how can i insert 'modified_by' in tbl_2, which is the 'user name' in any other table through which the application is logged in. i want to insert the 'username' as the 'modified_by' in tbl_2. how can i pass the username in the trigger so that when ever it gets fired, it also insert the 'username' as 'modified_by' in tbl_2.

now i think it is clear.
with regards,
Jul 2 '08 #6
ck9663
2,878 Recognized Expert Specialist
During insert to tbl2, identify the field names on the t-sql. Harcode the modified_by part. Something like,

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO (field1, field2, field3, modified_by) tbl2
  2. select field1, field2, field3, user_name() from inserted (or deleted whichever case).
  3.  
Happy coding...

-- CK
Jul 4 '08 #7
coolminded
137 New Member
During insert to tbl2, identify the field names on the t-sql. Harcode the modified_by part. Something like,

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO (field1, field2, field3, modified_by) tbl2
  2. select field1, field2, field3, user_name() from inserted (or deleted whichever case).
  3.  
Happy coding...

-- CK
i think you don't understand what i am trying to say.

i want to pass the parameter at the run time, and it's the name of the person who has logged in. how can i know who has logged in by using the select statement? and the username comes from different table, not the same table
thanx
Jul 6 '08 #8
ck9663
2,878 Recognized Expert Specialist
You're saying there's another table?

You got tbl_1 which is your transaction table. Anything happened there, you inserted the record in tbl_2. Where do you get the modified_by field?

-- CK
Jul 8 '08 #9
coolminded
137 New Member
You're saying there's another table?

You got tbl_1 which is your transaction table. Anything happened there, you inserted the record in tbl_2. Where do you get the modified_by field?

-- CK
another table tbl_3 contains modified_by field.
Jul 13 '08 #10
ck9663
2,878 Recognized Expert Specialist
You might just need to use JOIN


-- CK
Jul 13 '08 #11
coolminded
137 New Member
You might just need to use JOIN


-- CK

how to join the tables in the trigger. i want to know that
i wrote a trigger
Expand|Select|Wrap|Line Numbers
  1.              on update or delete on tbl_1
  2.                  call trigger trigger_name
  3.  
how can i join tbl_1 and tbl_2 in the trigger
thanx
Jul 14 '08 #12
icon29
1 New Member
I understand ur problem.You won't find this solution while doing google.You can pass parameters toriggers just like Procedures.It will work fine....

Vikrant Sharma(Ludhiana,india)
www.dotnetworkshop.in
iconsoftech,com
Sep 1 '08 #13
ck9663
2,878 Recognized Expert Specialist
Could you post a sample code that allow passing of parameter to trigger, please? I was not aware that I can do that. I might be making things hard for a lot of things coz I never thought you can pass a parameter to a trigger.

Coolminded,
You can use JOIN like in any other t-sql. Here's the JOIN Fundamentals in BOL.

Good luck.

-- CK
Sep 2 '08 #14

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

Similar topics

1
by: John Miles | last post by:
Hi -- This is a bit of an implementation-specific problem, but I'd like to post it here to see if there's a general answer within the auspices of the language. I'm developing a high(er)-level...
3
by: Peter | last post by:
Has anyone seen this before? I start SQL*Plus, and login by typing sqlplus Quantum/Password@BPrd I type: select '&1' from dual; it responds
5
by: Andy | last post by:
Hi Could someone clarify for me the method parameter passing concept? As I understand it, if you pass a variable without the "ref" syntax then it gets passed as a copy. If you pass a...
2
by: Samba | last post by:
Hi, Mine is a very basic doubt ... (1) If we are using a static field/object, then the field/object is shared across all the places in the entire application as it is stored only at one...
33
by: C# Learner | last post by:
Note ---- Please use a fixed-width font to view this, such as Courier New. Problem
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
1
by: Vams | last post by:
Everyone, I need your help, I am trying to pass a parameter to a function that is to be called by a trigger. But, the correct function isn't being recognized and I am getting an error stating...
3
by: danbraund | last post by:
Hi everyone, I'm a long time C coder, who is coding his final year project in C++ to run under the MIT click routing system. Being fairly new to the OO side of the language, my problem is this: ...
11
by: =?Utf-8?B?U2VyZ2lv?= | last post by:
I need to pass two parameter to a vb.net 2003 windows form application, is this posible? how?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.