SQL Server 2008 transaction log issue - sql

I am learning about SQL Server 2008. I have created a database with full backup mode and made a transaction without commit. In the system database info the log_reuse_wait_desc column is still has the value 'NOTHING'. But the tutorial which I am following shows that the value changes to 'ACTIVE_TRANSACTION'. Am I missing any configuration changes?
Thanks
Prathap

I believe that the log_reuse_wait_desc column is only updated as a response to certain actions such as log backups, checkpoints and attempts of SQL Server to clear old VLFs. Most of the time this column is accurate (or accurate enough to be useful). I once read an article about this behavior from an authoritative community member but I cannot find it right now.
Try performing a CHECKPOINT or a log backup. The column should be updated by that.

Related

How to recover deleted data from SQL server table? [duplicate]

I accidentaly ran a DELETE command against a table with a wrong WHERE
clause.
I am using SQL Server 2005.
Is there a way that could help me recover the lost data?
It is possible using Apex Recovery Tool,i have successfully recovered my table rows which i accidentally deleted
if you download the trial version it will recover only 10th row
check here http://www.apexsql.com/sql_tools_log.aspx
You have Full data + Transaction log backups, right? You can restore to another Database from backups and then sync the deleted rows back. Lots of work though...
(Have you looked at Redgate's SQL Log Rescue? Update: it's SQL Server 2000 only)
There is Log Explorer
I think thats impossible, sorry.
Thats why whenever running a delete or update you should always use BEGIN TRANSACTION, then COMMIT if successful or ROLLBACK if not.
What is gone is gone. The only protection I know of is regular backup.

Unknown HTML Data Entered in SQL Server Database

Recently found out that unknown html codes were inserted into my SQL Server database without my knowledge, it's something like this in every cell
[my original database data]</title><style>.a2vf{position:absolute;clip:rect(475px,auto,auto,475px);}</style><div class=a2vf>These rules are bound <a href=http://paydayloansforsure.com >fast payday loans</a> unscrupulous len...
I initially thought my database password was compromised. So I changed my password to a more difficult one, but after a couple of days, it appeared again. Anyone knows how it got into the database like that and how to prevent it?
UPDATE:
After some investigation, I suspect this might be caused by a software which I downloaded to schedule backup SQL databases. I've reformatted my local machine and start all over again, it did not happened anymore.
After some investigation, I suspect this might be caused by a software which I downloaded to my local machine to schedule SQL databases backup. I've reformatted my local machine it did not happen anymore.

Need help in understanding flow of events when we perform update or delete statements in MS SQL server

I am not able to correctly understand the flow of events when we perform an update/delete statement in sql server.As per understanding below events occur,but still in confusion.Can you please clarify this or post a detailed event log
A.)Update statement performed on a DB in full recovery mode and committed
DB reads the page from the disk if not in memory and page data will be modified.
Same will be written in Tlog file and the log buffer hardens this to disk before the mdf file is written to disk.
Lazy writer or Tlog backup will force the MDF to write to disk under some circumstances.
But still some questions on this
B.)I am always under assumption that ,when you modify something in SQL server that will be written to log file first and when checkpoint occurs this will be moved into MDF file.
Can you help me understand which one is correct,is it A or B?
Ultimately i found answer i am looking for posting here,incase if it might help some one
SQL Server 2012 : SQL Server Architecture - THE LIFE CYCLE OF A QUERY (part 3) - A Simple Update Query
Read more at http://mscerts.programming4.us/sql_server/SQL%20Server%202012%20%20%20SQL%20Server%20Architecture%20-%20THE%20LIFE%20CYCLE%20OF%20A%20QUERY%20(part%203)%20-%20A%20Simple%20Update%20Query.aspx#S7WVSwMhfbLq85TC.99

Strange Sql Server 2005 behavior

Background:
I have a site built in ASP.NET with Sql Server 2005 as it's database. The site is the only site on a Windows Server 2003 box sitting in my clients server room. The client is a local school district, so for data security reasons there is no remote desktop access and no remote Sql Server connection, so if I have to service the database I have to be at the terminal. I do have FTP access to update ASP code.
Problem:
I was contacted yesterday about an issue with the system. When I looked in to it, it seems a bug that I had solved nearly a year ago had returned. I have a stored procedure that used to take an int as a parameter but a year ago we changed the structure of the system and updated the stored procedure to take an nvarchar(10). The stored procedure somehow changed back to taking an int instead of an nvarchar.
There is an external hard drive connected to the server that copies data periodically and has the ability to restore the server in case of failure. I would have assumed that somehow an older version of the database had been restored, but data that I know was inserted 7 days and 1 day before the bug occurred is still in the database.
Question:
Is there anyway that the structure of a Sql Server 2005 database can revert to a previous version or be restored to a previous version without touching the actual data? No one else should have access to the server so I'm going a little insane trying to figure out how this even happened.
Any ideas?
Using SQL Server's built-in backup and restore mechanism, there is no means to pick only certain objects to restore. With transaction log backups, you can restore to a point in time which might be before a certain transaction or ALTER statement was made but that's the closest you get. There are tool's which will let you pick certain objects to restore however they work by either restoring the database to a copy and copying over the objects you want or reading the backup directly and copying out those objects. In other words, this is not something could have happened using the built-in tools accidentally. My guess is that someone accidentally ran an old script of the stored proc(s) that reverted it.
It would be trivial to change a stored procedure without touching any data, or any other stored procedure. How who why when, that's the problem.
One suggestion, run
select * from sys.procedures
and check the create_date and modify_date columns, for both your problem procedure and all other procedures in the database.
I've witnessed similar things happening with an app I have installed at one client location. Every so often the s'procs revert to an older version.
It's just one client, the app is installed at several others which have never had this issue, and they happen to be a school district as well. It happens about once every 3 months or so, and no one should be touching that machine. I'm not even sure they have anyone in house that would know how to open enterprise manager.
Out of curiousity, what backup software is your client using? and, after checking the creation / modify dates on the procedures, did a server reboot occur around that time?
The reason I ask is that my client has backup software that does some really weird things on that server. For example, on reboot it has to "play back" changes, including file operations, since the last successful backup. Also, is it installed in a VM?
Through Data Transformation Services (DTS) ? or if the scripts that set up the database are available someplace..

Undo changes to SQL Server 2005 database

I've ran some "ALTER" scripts on the database [SQL Server Server 2005], and overwrote some sprocs. Is there any way to undo changes and get my old sprocs back?
Is there a way to get the scripts that were executed out of the .LDf file? That way i can re-run my initial "create" script for my sprocs.
I don't have a backup file with old sprocs.
p.s. i backed the DB up as per #Gulzar's deleted answer, and looks like I'm "hosed".
#Pittsburgh DBA: thanx for the solution, but it doesn't seem to work after the backup.
MORAL: Wait for 10 minutes before trying the suggested answers out
Update from Gulzar: What I meant was a file backup before trying anything (to be safe). Not a SQL Server backup.
FIRST: DO NOT TAKE ANY BACKUPS JUST YET.
There are several tools on the market to do this sort of thing.
You might try this one:
ApexSQL Log
In case anybody else has the same problem - Were you doing transaction log backups every X minutes? If so, you can use Quest LiteSpeed's log reader or Quest Toad for SQL Server's log reader to read the log file backups. It gives undo/redo scripts too for any transaction in the log backups or the ldf.
And after that, look into using ApexSQLScript to script out your databases on a regular basis (and store in version control).
yo do can!!
go to sql server managment studio,connect to your db, left click on your db and go to "tasks".
select restore -> database.
then click the "timeline" button and select 'especific date' and select the day before your mistake.
All programs that have access to your db mus be closed.
It worked for me, i had this very same probelm.