MS SQL Server 2005: What Happens If LDF-file are lost? - sql-server

If I put my MS SQL Log file on another drive and the drive crashes.
What happens to my MS SQL Database, will it create a new log file or how do I correct it?

you need to recover/repair the database, see here: Recover a database without the ldf file

Related

SQL Server: Why isn't the log file up-to-date with the database file on full recovery mode?

Using SQL Server 2012 on full recovery and looking at the directory:
C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\
I see .mdf and .ldf files.
For a particular database, the modified times are very different? Why is this? I would have thought that as you modify a database your transaction would be recorded in the ldf file (regardless of the type of query)?
This is correct behavior. The modified dates change when SQL Server closes the files (SQL Server shut down or the database is detached), or when the file is grown (either automatically or manually). All other times, SQL Server essentially bypasses the file system when performing the writes, and so the modified dates aren't updated.

My database has been deleted suddenly on the server how to recover it?

I'm running an application on windows server that connect to a SQL Server database.
Today, when I opened SQL Server Management Studio, I was surprised the database is not in the list of the databases!
I don't know what's the reason. I searched in the server files but I can't find the database and also in the recycle bin.
I put my database in C:\db\myWeb.mdf and suddenly it's been removed!
Can anyone tell me how to recover the database?
UPDATE:
I used stealer phoenix to find the database files deleted on disk but unfortunately i didn't find the db then i tried to add new database with the same name of the deleted db but SQL management studio said that the database "MyWeb" already exist! that's mean it's some where in the server but i couldn't find it ?! .
The only thing you can do when the actual database files are missing is restore a backup of your server.
Optionally, when you have no backup, you could use a hard disk recovery tool (like Runtime GetDataBack to find the database files deleted on disk).

SQL Server : backup database with T-SQL?

I am looking for a way to backup a SQL Server database with T-SQL. I do no have root access to this server through the console, as my only access comes through SQL Server Management Studio.
Could someone please show me the SQL that I could use to export the raw SQL for my entire database?
BACKUP DATABASE #strDB TO DISK =#BackupFile WITH RETAINDAYS = 10, NAME = N'MyDataBase_DATA-Full Database Backup', STATS = 10
You must define #BackupFile and #strDB as the database name.
All of this is free in Books Online which you can find online.
If you only have access to the server through Management Studio, where do you expect it to stream your backup? Getting the T-SQL to work is one thing - getting SQL Server to be able to write the backup to a place where you can access it is quite another. You may want to look at Red-Gate's SQL Azure Backup:
http://www.red-gate.com/products/dba/sql-azure-backup/

Error copying SQL Server 2000 database to SQL Server 2008

I'm trying to upgrade a database from a SQL Server 2000 instance to a SQL Server 2008 instance. I'm doing this by right clicking on the database and selecting copy database. My current issue is that I'm getting this error in the log file:
OnError,AQUE-SQLDEV,NT
AUTHORITY\SYSTEM,aque-db2000_aque-sqldev_sql2008_Transfer Objects
Task,{F0ACDE4D-D023-400C-BE3C-91CD3A537988},{40E67169-0F3F-4F86-AD2E-6E2CB532BA5C},18/10/2011
15:38:37,18/10/2011 15:38:37,0,0x,Script failed for User 'WebUser'.
StackTrace: at
Microsoft.SqlServer.Management.Smo.Scripter.ScriptWithList(DependencyCollection
depList, SqlSmoObject[] objects) at
Microsoft.SqlServer.Management.Smo.Scripter.ScriptWithList(SqlSmoObject[]
objects) at
Microsoft.SqlServer.Management.Smo.Transfer.Microsoft.SqlServer.Management.Common.ITransferMetadataProvider.SaveMetadata()
at
Microsoft.SqlServer.Management.Dts.DtsTransferProvider.Configure(ITransferMetadataProvider
metadataProvider) at
Microsoft.SqlServer.Management.Smo.Transfer.GetTransferProvider()
at Microsoft.SqlServer.Management.Smo.Transfer.TransferData() at
Microsoft.SqlServer.Dts.Tasks.TransferObjectsTask.TransferObjectsTask.TransferDatabasesUsingSMOTransfer()
InnerException-->Creating a user without an associated login is not
supported in SQL Server 2008.;
Does anyone know why this might be happening?
Thanks,
Sachin
Based on the error it sounds like you need to create a login first on the SQL 2008 server that matches the same login/user that exists on the SQL 2000 server. You could do a couple of things:
create a new database in 2008 to migrate to
create a new login in 2008 that matches the existing login from sql 2000
map the new login to that new database from step #1
run the copy database wizard
If it was me, I would do as marc_s suggested and perform a full backup of the existing database on sql 2000, then restore to a blank database in sql 2008. If you can, update the compatibility mode in database properties to be 2008. I've done this hundreds of times and works like a charm.
The reason can be that a file with the new Database name already exist on the filesystem. We encountered this when we renamed Database X to X_Old, and tried to copy database Y to X. This cannot be done, because database X_Old is still associated with the filename X.
Either delete the conflicting database, or rename the file on the file system.
See http://codecopy.wordpress.com/2012/01/03/error-while-copying-a-database/

MS SQL Server restoring database from MDF & LDF not showing latest data

The database is MS SQL Server Express 2005. The database is in simple mode.
I am trying to restore an existing database to a new server. I copied the MDF and LDF files to a new server. I attached the MDF and verified that the correct LDF was associated with it. After attaching the database, I compared the data from both databases and found that the new attached data was not current. Why?
Detach the database.
Copy the MDF and LDF files
Reattach on new server
I'm surprised you managed to copy the files at first because SQL Server locks the files exclusively.
You need to detach to cleanly "shut down" the database.
Just detach database. Last transactions will be saved into database, and you can successfully attach database.

Resources