You are on page 1of 2

Database Detach and Attach:

The data and transaction log files of a database can be detached and attached to the same or
another instance of SQL server. It is useful if we want to change the database to different instance of
SQL server on same computer or to move the database.

Online and Offline Database:

Taking the database offline and online

CUI:

CREATE DATABASE dbname //create test db

ALTER DATABASE dbname SET OFFLINE WITH ROLLBACK IMMEDIATE //taking DB offline

ALTER DATABASE dbname SET ONLINE //taking DB online

DROP DATABASE dbname //clean up

GUI:

1. Open SSMS
2. Connect to Database engine using DB administrator credentials
3. Expand Server node
4. To take databse offline, Right click Databases -> Select Tasks -> Take Offline
5. To bring back online, Right click Databases -> Select Tasks -> Bring Online.

SHRINK DB:

To reduce the size of the databse, use shrink

GUI:

1. Open SSMS
2. Connect to Database engine using DB administrator credentials
3. Expand Server node
4. Expand Databases and Right click the database that we want to shrink.
5. Point to Tasks-> Shrink and then click Database.
6. Click OK

CUI:

DBCC SHRINKDATABSE
( database_name | database_id | 0
[ , target_percent ]
[ , { NOTRUNCATE | TRUNCATEONLY } ]
)
[ WITH NO_INFOMSGS ]
Database backup and Restoring:
 Backing up is the only way to protect our data.
Database backup:
1. Open SSMS
2. Connect to Database engine using DB administrator credentials
3. Expand Server node
4. Right click Databases and point to Tasks-> Click Backup

The backup databse dialog box will appear.


5. In the Database dropdown list, verify database name.
6. Recovery model text box is reference only. We can perform a database backup for any recovery
model(Full, Bulk-Logged or Simple)
7. In the Backup type Dropdown list, Select Full.
8. Optionally, you can select the Copy-only backup checkbox to create a copy-only backup.
9. For Backup component, select the Database radio button.
10. In the Destination section, use the Back up to drop-down list to select the backup destination.
Click Add to add additional backup objects and/or destinations.
To remove a backup destination, select it and click Remove. To view the contents of an existing
backup destination, select it and click Contents.

You might also like