.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

while updating table...the old data should be save in another table

Posted By: Rama Krishna     Posted Date: March 20, 2013    Points:5   Category :Sql Server
Hi ..Below procedures are for insert and update the data in table "datatype"

But my requirement is whenever updating the table "datatype"....at the same time the data which was in "datatype" table...should be stored in another table "datatypehistory".

for that i have already created "datatypehistory" table with same structure As "datatype" table.

can anyone suggest..how can i achieve this requirement?

CREATE PROCEDURE [dbo].[AddDataType]
@TypeName [nvarchar](255),
@TypeProperty [nvarchar](255)
AS
BEGIN
SET NOCOUNT ON;

INSERT INTO DataType(TypeName, TypeProperty)
VALUES(@TypeName, @TypeProperty)

SELECT SCOPE_IDENTITY()
END

--UPDATE Procedure
CREATE PROCEDURE [dbo].[SetDataType]
@ID [int],
@TypeName [nvarchar](255),
@TypeProperty [nvarchar](255)
AS
BEGIN
SET NOCOUNT ON;

UPDATE DataType SET TypeName = @TypeName, TypeProperty = @TypeProperty
WHERE ID = @ID
END

Responses
Author: Narayanan             
Posted Date: April 08, 2013     Points: 20   

Hi,
To Create a SP for datatypeHistory table. Please check if already data exists or not, if exists update the Data or insert the data.
call this SP in your Update function.

Try this URL
stackoverflow.com/questions/108403/solutions-for-insert-or-update-on-sql-server

Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend