Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I found that if I use Backup feature in MSSQL,

when I restore, the tables' primary key disappear.

So currently I backup the database.mdf and database.ldf files.

But the problem of backup these files is I need to stop the MSSQL service.

 

So, if there any other better way?

Posted

Try running this script in the Query Analyser:

 

BACKUP DATABASE dbname

TO DISK = 'c:\dbname.bak'

 

You don't need to stop anything to run this backup.

Posted

Run this script to get the logical filenames:

 

RESTORE FILELISTONLY

FROM DISK = 'c:\dbname.bak'

 

The script above will return the logical filenames for you to put in place of:

'dbname_dat' = returned data filename

'dbname_log' = returned log filename

 

RESTORE DATABASE dbname

FROM DISK = 'c:\dbname.bak'

WITH MOVE 'dbname_dat' TO 'c:\sql\data\dbname.mdf',

MOVE 'dbname_log' TO 'c:\sql\logs\dbname.ldf'

GO

 

The paths for the data and log files can be anything you want.

Posted

You can also do a single file attach (just to get more complicated). Use this option for dropping a log file when it gets too big.

 

Detach the database first:

 

EXEC sp_detach_db 'dbname', true

 

Move the log file so that SQL Server can't find it (don't delete it yet).

 

Attach the logical data file only and ignore the log file in the backup:

 

EXEC sp_attach_single_file_db @dbname = 'dbname',

@physname = 'C:\SQL\Data\dbname.mdf'

 

Delete the log file if everything works.

 

Let me know if you have any problems.

Posted

I can backup my database. But when I try to restore this backup from your command: "Restore filelistonly from disk = '..'", the command run fine but I get nothing? what is this command for? because the result still no change, still one backup file and the my database record still no change

 

I need to create a new blank database to restore or I can direct overwrite my existing database?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...