Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have table with

id ,name,address-table 1

data,name,address-table 2

when i update my table 1 that old date should be move to table 2

I want do this using stored procedure without trigger table...

any idea...
Posted
Comments
[no name] 19-Aug-12 11:27am    
Any idea about what? If you want to do it in a stored procedure then write a stored procedure. What is the problem? You would really benefit from reading and applying http://www.codeproject.com/Articles/64628/Code-Project-Quick-Answers-FAQ

If you are not using a trigger (which would be the best way), you can run a job that compares the two tables and updates the second one with any records added in the first at a particular interval.
 
Share this answer
 
If your update query is like this...

SQL
  UPDATE tableName Set  column1 = something1,column2=something2,column3=something3
  WHERE <condition>

</condition>


Then follow the example bellow

Step 1: Create a Employee Table
SQL
   CREATE TABLE [dbo].[Employee](
	[EmployeeId] [int] NOT NULL,
	[EmployeeName] [varchar](50) NOT NULL,
	[Rank] [varchar](50) NOT NULL
) ON [PRIMARY]


Step 2: Create a Employee Log table

SQL
CREATE TABLE [dbo].[EmployeeLog](
	[EmployeeId] [int] NOT NULL,
	[EmployeeName] [varchar](50) NOT NULL,
	[Rank] [varchar](50) NOT NULL
) ON [PRIMARY]


Step 3: Insert few records into the Employee Table

SQL
INSERT [dbo].[Employee] ([EmployeeId], [EmployeeName], [Rank]) VALUES (1, N'Deepak', N'First')
GO
INSERT [dbo].[Employee] ([EmployeeId], [EmployeeName], [Rank]) VALUES (2, N'Damu', N'Five')
GO
INSERT [dbo].[Employee] ([EmployeeId], [EmployeeName], [Rank]) VALUES (3, N'Pankaj', N'First')
GO
INSERT [dbo].[Employee] ([EmployeeId], [EmployeeName], [Rank]) VALUES (4, N'Rahul', N'Third')
GO
INSERT [dbo].[Employee] ([EmployeeId], [EmployeeName], [Rank]) VALUES (5, N'Riyaz', N'Fourth')
GO
INSERT [dbo].[Employee] ([EmployeeId], [EmployeeName], [Rank]) VALUES (6, N'vimal', N'Five')
GO
INSERT [dbo].[Employee] ([EmployeeId], [EmployeeName], [Rank]) VALUES (7, N'Damu', N'Five')


Step 4:

SQL
 --update query 
   UPDATE Employee SET EmployeeName = 'Damu',Rank='Five',EmployeeId = EmployeeId
   OUTPUT deleted.EmployeeId ,deleted.EmployeeName,deleted.Rank INTO EmployeeLog
   WHERE EmployeeId = 5

--To see the result
   SELECT * FROM employeelog
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900