Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi
SQL
I accidentaly ran a DELETE Table data usin "select * from Company"
command. i need to recover table. iam using sql2012 server 


thanks in advance
Posted
Updated 3-Dec-12 0:53am
v2

SQL Server keeps log for each deleted records. you can query these logs via fn_dblog sql server function.
SQL
Select [RowLog Contents 0]
FROM   sys.fn_dblog(NULL, NULL)
WHERE  AllocUnitName = 'dbo.TableName'
       AND Context IN ( 'LCX_MARK_AS_GHOST', 'LCX_HEAP' )
       AND Operation in ( 'LOP_DELETE_ROWS' )  

But this log is in Hex format. and you need to convert this Hex format to your actual data.
 
Share this answer
 
Comments
sandeep nagabhairava 3-Dec-12 7:03am    
i tried it but the msg was "The SELECT permission was denied on the object 'fn_dblog', database 'mssqlsystemresource', schema 'sys'."
pree_kh 3-Dec-12 7:09am    
put the DNN user in the db_owner role and make sure you have proper rights.
this normally happens when there is a problem with the user having deny privileges as well.
May be this can help:


Execute this code on a good server which will provide you the complete rights for PUBLIC role. Copy the output and paste to the server with the issue. Execute. Try logging in again.

SELECT SDP.state_desc ,
SDP.permission_name ,
SSU.[name] AS "Schema" ,
SSO.[name] ,
SSO.[type]
FROM sys.sysobjects SSO
INNER JOIN sys.database_permissions SDP ON SSO.id = SDP.major_id
INNER JOIN sys.sysusers SSU ON SSO.uid = SSU.uid
ORDER BY SSU.[name] ,
SSO.[name]
 
Share this answer
 
Comments
sandeep nagabhairava 3-Dec-12 7:21am    
when i execute the above quary i got 14 rows of output.

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