How to backup and restore a SQL Database

If the SQL databases are in simple recovery

[pastacode lang=”sql” manual=”Backup%0A%0AALTER%20DATABASE%20dbname%0A%0ASET%20READ_ONLY%3B%0A%0AGO%0A%20%0A%0ABackup%20database%20dbname%0A%0Ato%20disk%20%3D%20’C%3A%5C…%5Cdbname.bak’%0A%0A%20%0ARestore%0A%0A%0ARestore%20database%20dbname%0A%0Afrom%20disk%20%3D%20%20’C%3A%5C…%5Cdbname.bak’%0A%0Awith%20recovery%2C%20replace%0A%0A%20%0A%0AALTER%20DATABASE%20dbname%0A%0ASET%20MULTI_USER%3B%0A%0AGO” message=”” highlight=”” provider=”manual”/]

If the databases are in full recovery model

[pastacode lang=”sql” manual=”Backup%0A%0ABackup%20database%20dbname%0A%0Ato%20disk%20%3D%20’C%3A%5C…%5Cdbname.bak’%0A%0ABackup%20log%20dbname%0A%0Ato%20disk%20%3D%20’C%3A%5C…%5Cdbname.trn’%0A%0Awith%20norecovery%0A%0A%20%0ARestore%0A%0A%20%0ARestore%20database%20dbname%0A%0Afrom%20disk%20%3D%20’C%3A%5C…%5Cdbname.bak’%0A%0Awith%20norecovery%2C%20replace%0A%0ARestore%20log%20test2%0A%0Afrom%20disk%20%3D%20’C%3A%5C…%5Cdbname.trn’%0A%0Awith%20recovery%0A%20″ message=”” highlight=”” provider=”manual”/]

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...