Click here to Skip to main content
15,891,785 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
Dear Sir

i want to write a query in Sql Server which will show updated data of a table in the database. When ever i run the query i will be able to see all the data that has been updated in the database .

if there is any query please help me ..


Sashibhusan Meher
Posted
Comments
[no name] 11-Dec-11 3:45am    
My 5!

Your best option if you have not implemented timestamps on your tables is to use a tool to browse the transaction log, see here :

http://www.apexsql.com/sql_tools_log.aspx[^]
 
Share this answer
 
Comments
Amir Mahfoozi 11-Dec-11 3:17am    
+5 it was in my mind too but I preferred to introduce SQL ways to him.
thatraja 11-Dec-11 3:35am    
5!
Mehdi Gholam 11-Dec-11 3:36am    
Thanks
One way is write a trigger for every table in which you want to track the changes. And also create another table that has such a structure that can store all of your changed data.

For information about triggers :
http://www.go4expert.com/forums/showthread.php?t=15510[^]

http://msdn.microsoft.com/en-us/magazine/cc164047.aspx[^]

Another way is enabling Change Tracking in your database. to learn more about it read here :
http://www.databasejournal.com/features/mssql/article.php/3875186/A-Look-at-SQL-Server-2008-Change-Tracking.htm[^]

To have a comparison between these two methods read here :
http://msdn.microsoft.com/en-us/library/cc280519%28v=SQL.100%29.aspx[^]

Hope it helps.
 
Share this answer
 
Comments
Mehdi Gholam 11-Dec-11 3:28am    
Nice, 5'ed
Amir Mahfoozi 11-Dec-11 3:56am    
Thanks :)
thatraja 11-Dec-11 3:35am    
5!
Amir Mahfoozi 11-Dec-11 3:56am    
Thanks :)
[no name] 11-Dec-11 3:42am    
My 5!
Depends on how you define "updated". Updated since when?

I would handle it by adding a DateTime column to the database which reflects the last change. I could then retrieve only the updated records for whatever range I needed with a simple SQL SELECT query.
 
Share this answer
 
How about creating a Transaction Log by creating a new table, or saving it as XML or maybe a textfile or a CSV file. So you can use this Transaction Log for your Audit Trailing.

Another solution would be creating a Time Stamp or a Date Updated field o each of your table and updating that field everytime a user updates a record from that table.

Regards,
Eduard
 
Share this answer
 
say $name is the value of the updated column, the column name is name, and the table name is testtb, you would type:

$query = mysql_query("SELECT * FROM testdb WHERE name=$name");
$array = mysql_fetch_array($query);
$rnd = $array['<Name of column you want to pull value from>'];
echo "$rnd";
 
Share this answer
 
v2
Comments
Sicppy 11-Dec-11 2:58am    
sorry i ment,

$query = mysql_query("SELECT * FROM testtb WHERE name=$name");
$array = mysql_fetch_array($query);
$rnd = $array['<name of="" column="" you="" want="" to="" pull="" value="" from="">'];
echo "$rnd";
RaviRanjanKr 11-Dec-11 2:58am    
Always wrap your code in "Pre" tag.

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