Saturday, August 27, 2011

insert data from one table to another in sql

Helo guys.. A simple way to insert data from one table to another

Insert into Table1(distcentre, distcode,disttname) select distributorcenter, UserCode,Name
from Table2

Saturday, August 6, 2011

Trigger Tutorial

                                                                 TRigger :--
Trigger is like stored Procedure.It is used after Insert update delete or Before it.The difference between both is that trigger has relation with tables while stored procedure not.
Suppose we have two tables ‘test’ and ‘test22’. Now I wants that when a new record is inserting  in the table test then after insert a trigger automatically  and pick the last inserted record  from test and insert the same into test22 table.. Here we go
Step I --  Create Trigger

Create trigger   myfirst <-----(Trigger Name)
on test  <-----------(Table name on which we are applying)
after insert
declare @idss as int, @nameb as nvarchar(50),@cls as nvarchar(50)
select @idss=id,@nameb=name1,@cls=class from test where id= (select isnull(max(id),0) from test)
insert into test22 values(@idss,@nameb,@cls)

Step II --  Now when you insert a record in test then automatically the same record will insert in ‘test22’

Any problem plz mail me at 
I am trying to do best to update my blog.