Difference between revisions of "MS SQL"

Jump to navigation Jump to search
668 bytes added ,  08:41, 3 December 2015
→‎Rebuild All Indexes: Added single user bit
(→‎Fragmentation: Added "Rebuild All Indexes")
(→‎Rebuild All Indexes: Added single user bit)
Line 236: Line 236:


==== Rebuild All Indexes ====
==== Rebuild All Indexes ====
Unless you are running SQL Enterprise, this needs to be run when your database is '''offline'''
Unless you are running SQL Enterprise, this needs to be run when your database is '''single-user mode'''.
 
<source lang="sql">
<source lang="sql">
USE DatabaseName                            /* Change to database name! */
USE DatabaseName                            /* Change to database name! */
Line 259: Line 260:
   
   
DEALLOCATE TableCursor  
DEALLOCATE TableCursor  
</source>
To put into Single-User Mode
# Take database offline
#* If database won't stop, look for processes still accessing the database and kill them
# Put into single-user mode
# Put database online
#* You can only run commands from one console window/connection
<source lang="sql">
/* Find processes and kill them*/
exec sp_who2
kill 32
/* Force offline - change database name */
USE master
ALTER DATABASE DatabaseName SET OFFLINE WITH ROLLBACK IMMEDIATE
/* Force into single-user */
USE master
ALTER DATABASE DatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
/* Put back into multi-user */
USE master
ALTER DATABASE DatabaseName SET MULTI_USER
</source>
</source>


[[Category:Applications]]
[[Category:Applications]]
[[Category:Microsoft]]
[[Category:Microsoft]]

Navigation menu