Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 13th, 2008, 06:44 AM
mudragada mudragada is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 3 mudragada User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 49 sec
Reputation Power: 0
Implementing version scenario in sqlserver

hello every one,

i have a problem , i need to implement the version scenario for a record that is about to be updated.ie., whenever i update a particular record the updated information is to be stored in master table and the record prior to update is to be stored in the version table, so that i can fetch all the record information from the insertion of the record to the latest available update and also no.of updates

i have desinged in this way,

master_table:
Rec_Id,W,X,Y,Z,Date_modified,num_of_versions

version_table
ver_Id,Rec_Id,W,X,Y,Z, Date_modified

i am unable to get the query,,

can any one help me in this scenario.

thanks and regards,
mudragada.

Reply With Quote
  #2  
Old October 18th, 2008, 04:45 AM
mudragada mudragada is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 3 mudragada User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 49 sec
Reputation Power: 0
I have implemented in this way.....
if any modifications its pleasure to hear.........

during insertion of the new record call this proc
ALTER PROCEDURE dbo.sp_InsertRecord

(
@FstName nvarchar(MAX),
@LstName nvarchar(MAX),
@sName nvarchar(MAX),
@dt_mod Datetime
)

AS
begin
Declare @masterId int;
//inserting the new record into the master table
Insert into master (Fname,Lname,Surname,Date_Modified) values (@FstName,@LstName,@sName ,@dt_mod )
//get the identity of the newly created record
select @masterId=@@IDENTITY
/*inserting the same record into version table for the copy of version */
Insert into version(master_Id,Fname,Lname,Surname,Date_Modifie d) values (@masterId,@FstName,@LstName,@sName ,@dt_mod )
/*updating master table num_of_ver column wth the count of new record*/
Update master set num_of_versions=(select count(*) from version where master_Id=@masterId) where master_Id=@masterId

END


during update of the record call this proc


ALTER PROCEDURE dbo.sp_updateInsRecord

(
@masterId int,
@FstName nvarchar(MAX),
@LstName nvarchar(MAX),
@sName nvarchar(MAX),
@dt_mod Datetime
)

AS

begin
/* updating the master table with the current update*/
Update master set Fname=@FstName,Lname=@LstName,Surname=@sName,Date_ Modified=@dt_mod where master_Id=@masterId

/*inserting the udated record into version table */
Insert into version(master_Id,Fname,Lname,Surname,Date_Modifie d) values (@masterId,@FstName,@LstName,@sName ,@dt_mod )

/*updating the version colum in master table*/
Update master set num_of_versions=(select count(*) from version where master_Id=@masterId) where master_Id=@masterId

END

hope this is the right way i have implemented if any suggestion post them..

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Implementing version scenario in sqlserver


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT