Trigger in asp.net
-
which type of trigger this is ? Lets say it is on update then update any record when you want it triggered
Rizwan Bashir <a href="http://www.alm-soft.com/">ALM Soft</a>[<a href="http://www.alm-soft.com/" target="_blank" title="New Window">^</a>]
-
Sir i created trigger(insert,update,delete) as we can call stored procedure(insert,update,delete table) but the question is how we use this trigger in web application as we created in sql server to fire them.
rizvan sivally
so your triggers are not Database oriented, basically a code in asp.net is required to be run lets say every one hour , if it is so then use Timer which will be run on background and wont require any one to browse the page to trigger it like window service. check this for timer ( the last post on this page)http://forums.asp.net/t/1187287.aspx/1[^]
Rizwan Bashir <a href="http://www.alm-soft.com/">ALM Soft</a>[<a href="http://www.alm-soft.com/" target="_blank" title="New Window">^</a>]
-
Sir i created trigger(insert,update,delete) as we can call stored procedure(insert,update,delete table) but the question is how we use this trigger in web application as we created in sql server to fire them.
rizvan sivally
As the name suggests - 'Trigger', these triggers are automatically fired. And according to my knowledge, one cannot fire the trigger explicitly. That means, they get automatically fired when the task for which they have been made occurs. i.e. when some data is inserted / updated / deleted in the table. For eg. If you have made an insert trigger on a table, it will be fired only when some data is inserted in it..and so on. You don't have to call / fire these triggers in your code.
-
hiiiiiii to al one canl any one can hep me that i wanted to set trigger in asp.net web page by sql server how to call that trigger in web page please help me to sort out this problem
rizvan sivally
You first need to understand the trigger. Here is a brief explanation : Trigger is native to SQL and not to ASP.NET. Trigger is a code segment in SQL that gets executed when a specified condition is met. There are three types of trigger Inser, Update, Delete trigger. Insert Trigger will be executed when you insert a new row into the table. Same applies to update and delete trigger. So with this much explanation you must be clear that Trigger is the thing that is not called explicitly, rather SQL server will automatically execute your trigger when you insert, update or delete any record from the table. Coming back to your question : As you said, you know how to call a stored procedure, so call it as you do. Write a trigger on your desired table for a insert/update/delete operation. When the specified operation is performed in the Stored Procedure, trigger will be automatically fired by SQL. Important : Trigger is in SQL and not ASP.NET. Trigger can not be executed explicitly as you do Stored Procedure. Trigger is taken care by SQL server. For further reference : How to Write Trigger 1. http://msdn.microsoft.com/en-us/library/ms189799.aspx[^] 2. http://www.sqlservercentral.com/Forums/Topic351362-92-1.aspx[^] 3. http://download.oracle.com/docs/cd/B12037_01/server.101/b10759/statements_7004.htm[^] How Trigger Works 1. http://manuals.sybase.com/onlinebooks/group-as/asg1250e/sqlug/@Generic__BookTextView/47865;pt=47764[^] 2. http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/triggers.htm[
-
Sir i created trigger(insert,update,delete) as we can call stored procedure(insert,update,delete table) but the question is how we use this trigger in web application as we created in sql server to fire them.
rizvan sivally
You do not need to use the triggers through ASP.Net. They will be automatically fired by SQL.
I quit being afraid when my first venture failed and the sky didn't fall down.
-
You first need to understand the trigger. Here is a brief explanation : Trigger is native to SQL and not to ASP.NET. Trigger is a code segment in SQL that gets executed when a specified condition is met. There are three types of trigger Inser, Update, Delete trigger. Insert Trigger will be executed when you insert a new row into the table. Same applies to update and delete trigger. So with this much explanation you must be clear that Trigger is the thing that is not called explicitly, rather SQL server will automatically execute your trigger when you insert, update or delete any record from the table. Coming back to your question : As you said, you know how to call a stored procedure, so call it as you do. Write a trigger on your desired table for a insert/update/delete operation. When the specified operation is performed in the Stored Procedure, trigger will be automatically fired by SQL. Important : Trigger is in SQL and not ASP.NET. Trigger can not be executed explicitly as you do Stored Procedure. Trigger is taken care by SQL server. For further reference : How to Write Trigger 1. http://msdn.microsoft.com/en-us/library/ms189799.aspx[^] 2. http://www.sqlservercentral.com/Forums/Topic351362-92-1.aspx[^] 3. http://download.oracle.com/docs/cd/B12037_01/server.101/b10759/statements_7004.htm[^] How Trigger Works 1. http://manuals.sybase.com/onlinebooks/group-as/asg1250e/sqlug/@Generic__BookTextView/47865;pt=47764[^] 2. http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/triggers.htm[
Thanks alot sir as we know what ever we put the message in the trigger it will show after action is fired in database. now question is that is trigger also restrict any data to insert,delete or update in database as well as for webapplication Thnaking you again
rizvan sivally
-
You do not need to use the triggers through ASP.Net. They will be automatically fired by SQL.
I quit being afraid when my first venture failed and the sky didn't fall down.
-
the next question is that is that possible to restrict to insert,update and delete data by trigger in the database and in web application if possible then what will be query of the trigger
rizvan sivally
Yes, It is possible to restrict DML by triggers. You said that you have already made triggers. Then you only have to edit them and add your logic for restricting some action. It must be in if-else construct. If the action is not valid according to your logic, then just add 'Rollback Transaction' in your if construct! And you're done! You have just restricted the invalid DML! Enjoy! For further details, Visit this[^]
-
Yes, It is possible to restrict DML by triggers. You said that you have already made triggers. Then you only have to edit them and add your logic for restricting some action. It must be in if-else construct. If the action is not valid according to your logic, then just add 'Rollback Transaction' in your if construct! And you're done! You have just restricted the invalid DML! Enjoy! For further details, Visit this[^]
-
Thanks alot sir as we know what ever we put the message in the trigger it will show after action is fired in database. now question is that is trigger also restrict any data to insert,delete or update in database as well as for webapplication Thnaking you again
rizvan sivally
Yes for sure, if you do not want any invalid to insert in the database then also you can use the trigger. But again there are two options to do so.. Option 1: Use the Constraints 1. http://dev.mysql.com/doc/refman/5.0/en/constraint-invalid-data.html[^] 2. http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/general005.htm[^] 3. http://odetocode.com/articles/79.aspx[^] Option 2: Use Trigger 1. http://manuals.sybase.com/onlinebooks/group-as/asg1250e/sqlug/@Generic__BookTextView/48841;pt=48327/*[^] 2. Just do the rollback in the trigger to restrict the data Maintain data integrity: http://ss64.com/ora/syntax-constraints.html[^] I would recommend you using the first approach, because Triggers are not that easy when it comes to maintainance of the project. Hope this helps. All the best.
I quit being afraid when my first venture failed and the sky didn't fall down.
-
hiiiiiii to al one canl any one can hep me that i wanted to set trigger in asp.net web page by sql server how to call that trigger in web page please help me to sort out this problem
rizvan sivally