Professional Documents
Culture Documents
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.
CUI:
ALTER DATABASE dbname SET OFFLINE WITH ROLLBACK IMMEDIATE //taking DB offline
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:
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