Skip to main content

Trigger for insert, update in sql server


deleted and inserted are logical (conceptual) tables. They are structurally similar to the table on which the trigger is defined, that is, the table on which the user action is attempted, and hold the old values or new values of the rows that may be changed by the user action. For example, to retrieve all values in the deleted table, use:
SELECT * FROM deleted



Create TRIGGER [dbo].[test1_insupd]
ON [dbo].[test1]
FOR INSERT, UPDATE
AS

BEGIN
declare @f1 int
declare @f2 varchar(10)
declare @vishg char(1)
select @f1 = f1, @f2 = f2, @vishg = vishg from inserted
if UPDATE ( visHG ) and @vishg = '1'
begin
IF EXISTS(select * from test2 where f1 = @f1)
update test2 set f2 = 'true in t1' where f1 = @f1
else
insert into test2(f2) values( 'true in t1')
end
else
begin
IF EXISTS(select * from test2 where f1 = @f1)
update test2 set f2 = 'not true' where f1 = @f1
else
insert into test2(f2) values('not true')

end


END

Popular posts from this blog

Android Developer Learning Resource

Developing In Eclipse, with ADT http://developer.android.com/guide/developing/eclipse-adt.html Signing Your Applications http://developer.android.com/guide/publishing/app-signing.html Compile and sign with Eclipse ADT To create a signed and aligned .apk in Eclipse: Select the project in the Package Explorer and select File > Export . Open the Android folder, select Export Android Application, and click Next . The Export Android Application wizard now starts, which will guide you through the process of signing your application, including steps for selecting the private key with which to sign the .apk (or creating a new keystore and private key). Complete the Export Wizard and your application will be compiled , signed , aligned , and ready for distribution. DroidDraw is a graphical user interface (GUI) builder for the Android platform http://code.google.com/p/droiddraw/

RMO programming

http://msdn2.microsoft.com/en-us/library/ms151819.aspx SQL Server Express does not include SQL Server Agent, which is typically used to run replication agents. If you use a pull subscription (in which agents run at the Subscriber), you must synchronize the subscription using Windows Synchronization Manager or RMO. For more information, see the following topics: Windows Synchronization Manager RMO programming: How to: Synchronize a Pull Subscription (RMO Programming) Replication does not support the Run As Normal User (RANU) feature of SQL Server Express. For more information about this feature, see the SQL Server Express documentation.