Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friend
I have some problem when implementing program.The actual problem is as follows :-

Consider my table User:-
The following attributes:-
userid    name    email           address    phone    company    designation
1          a       a@gmail.com    nagpur      1           x        developer   
2          b       b@gmail.com    pune        2           y          dba             
3          c       c@gmail.com    mumbai      3           z        engineers
4          d       d@gmail.com    nagpur      4           y          developer


if you have updated any information in the user id 1 and 3 just like :-
butes:-
userid    name    email           address    phone    company    designation
1          a       a@gmail.com    pune        2           y       manager   
2          b       b@gmail.com    pune        2           y          dba             
3          c       c@gmail.com    nagpur      5           x       developer
4          d       d@gmail.com    nagpur      4           y       developer


This two userid information updated so my question is "How to understand user this two rows updated or not" ? is any query please give me information as soon as possible .


Thanks in advanced !!
Posted
Updated 29-Jul-13 2:50am
v2
Comments
ZurdoDev 29-Jul-13 8:37am    
What's your question? It is not clear.
Member 8089110 29-Jul-13 8:46am    
Sir,if you have updated record in your table for example :- in this table first and third rows updated information so how to understand or in which query i retrieved information this query rows or this id is updated or deleted or inserted ?
Maciej Los 29-Jul-13 8:53am    
Still not clear ;(
What to understand? If you write software to manage above data, you need to know who and when made changes.
Member 8089110 29-Jul-13 9:05am    
if you have changes in user table so how to understand this table or rows changes. is any query to retrieve information or rows this rows changes ?
Sudhakar Shinde 29-Jul-13 9:25am    
You can very well check how many rows are affected by the UPDATE statement. Is this what you are looking for?

If You want to know what are the rows updated then u can use do it in two ways..
1. Write a select Statement before Update Statement selecting rows which will be updated Like...
SQL
Select Columnname from TableName Where Condition
Update TableName set column= something Where Condition

2. U can use a TRIGGER for update of that Particular Table and save those records in to some new table...
Check this link for Triggers[^]
SQL
CREATE TRIGGER TriggerName
ON TableName
AFTER UPDATE 
AS 
IF ( UPDATE (ColumnName))
BEGIN
--Do Something
END;


If you just want to Know the no of Rows affected by a statement u can use @@RowCount...
SQL
Create Table #Test(id Int, value Nvarchar(40))

Insert into #Test 
Select 1,'Value1' Union All
Select 2,'Value2' Union All
Select 3,'Value3' Union All
Select 4,'Value4' 

Select @@ROWCOUNT [RowCount After Insert] -- Returns 4

Select * From #Test
Select @@RowCount [RowCount After Select] -- Returns 4

Update #Test Set id=1 where id<4
Select @@RowCount [RowCount After Update] -- Returns 3

Update #Test Set id=1 where id=0
Select @@ROWCOUNT			  -- Returns 0

Drop Table #Test 


you can fetch column update's date if column is primary key/foreign key like this
SQL
Select * From sys.objects where type_desc in('PRIMARY_KEY_CONSTRAINT','FOREIGN_KEY_CONSTRAINT')
Order by modify_date Desc

Hope this Helps...
 
Share this answer
 
v2
Comments
Adarsh chauhan 30-Jul-13 2:42am    
Nice.. +5
Raja Sekhar S 30-Jul-13 2:47am    
Thank You... Adarsh..
I think your question is - how to understand which rows have been updated by your query (and not the number of rows). I haven't come across any such query which would provide the list of rows which have been updated.

Can you try adding a new column to the table which would display the Updated timestamp and make out which rows have been updated by looking at the time. Obviously this will work only in a dev kind of environment but would not in an environment with multiple users. You can still give it a try by adding 2 columns which contain the "LastUpdatedBy" and "LastUpdatedDate" columns.
 
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