AllInWorld99 provides a reference manual covering many aspects of web programming, including technologies such as HTML, XHTML, CSS, XML, JavaScript, PHP, ASP, SQL,FLASH, jQuery, java, for loop, switch case, if, if else, for...of, for...in, for...each,while loop, blogger tips, blogger meta tag generator, blogger tricks, blogger pagination, client side script, html code editor, javascript editor with instant output, css editor, online html editor, materialize css tutorial, materialize css dropdown list,break, continue statement, label,array, json, get day and month dropdown list using c# code, CSS button,protect cd or pendrive from virus, cordova, android example, html and css to make android app, html code play,telerik show hide column, Transparent image convertor, copy to clipboard using javascript without using any swf file, simple animation using css, SQL etc. AllInWorld99 presents thousands of code examples (accompanied with source code) which can be copied/downloaded independantly. By using the online editor provided,readers can edit the examples and execute the code experimentally.


Trigger in SQL

     Triggers could be defined on the table, view, database or schema with the event is associated. If you write a trigger for delete, trigger will execute when the table data's are deleted.

Trigger in sql
Syntax
create trigger <Trigger_name>
on Table_name
<AFTER,BEFORE> <INSERT,DELETE,UPDATE>
as
declare @ID varchar(20);
select @ID=alice_name.ColumnName from inserted alice_name;

Example
create trigger tIU
on Emp_tb_help_HelpDesk
after UPDATE,insert
as
 declare @HID int; 
 select @HID=i.HelpDeskID  from inserted i;
 insert into Emp_tb_help_HelpDesk_History(HID) values(@HID)

Trigger execute changes on particular column

     If you write a trigger like above method, trigger will execute if any modification on specified table.

Syntax
IF (UPDATE (ColumnName1) OR update(ColumnName2))
begin
  --------------------
  --------------------
End

Example Program
create trigger tIU on Emp_tb_help_HelpDesk after UPDATE,insert
as
 declare @HID int; 
 declare @status varchar(50);
 declare @priority varchar(50);
 
IF (UPDATE (Priority) OR update(Status)) --Priority and Status is the Column Name
begin
 select @HID=i.HelpDeskID,@status=i.status,@priority=i.priority from inserted i;
 insert into Emp_tb_help_HelpDesk_History(HID,status,Priority,InsertedDate) values(@HID,@status,@priority,getdate())
end

2 comments:

Total Pageviews