Skip to main content

Backup and restore database in SQL Server

  1. To backup the database, use below query.
    Backup database <databaseName> to disk ='<backupLocation>.bak' with init;
  2. To backup the logs, use below query.
    Backup log <databaseName> to disk ='<backupLocation>.trn' with init;
  3. To restore from the database backup, use below query.
    restore database <databaseName> from disk =<backupLocation>.bak' with norecovery, replace, move 'testmirror' to 'DATA.mdf', move 'testmirror_log' to 'DATA_log.ldf';
  4. To restore from the transaction log, use below query.
    restore log
    <databaseName> from disk ='<backupLocation>.trn' with recovery, replace, move 'testmirror' to 'DATA.mdf', move 'testmirror_log' to 'DATA_log.ldf'

Comments

Popular posts from this blog

Get all constraints in Oracle

 To get all the constraints created in Oracle database, use below query.              SELECT * FROM USER_CONSTRAINTS; If you want to get the constraints  created for a particular user then use below SQL query.              SELECT   *   FROM  USER_CONSTRAINTS where owner = 'userName';