BOTÕES DE ACESSO RÁPIDO:
USE etrade
GO
ALTER DATABASE etrade SET SINGLE_USER; /* Coloca o banco em modo single user para executar os comandos abaixo */
DBCC CHECKDB ('etrade') WITH TABLOCK, ALL_ERRORMSGS, NO_INFOMSGS;
ALTER DATABASE etrade SET MULTI_USER; /* Volta o banco em modo multi user */
USE etrade
GO
ALTER DATABASE etrade SET SINGLE_USER;
DBCC CHECKTABLE(9999999,REPAIR_ALLOW_DATA_LOSS);
ALTER DATABASE etrade SET MULTI_USER;
(Usuário Único)
ALTER DATABASE etrade SET MULTI_USER;
(Suspeito)
Caso o banco esteja em "Suspect", execute os comandos abaixo. Mais informações em Repair A Suspect Database
EXEC sp_resetstatus etrade
ALTER DATABASE etrade SET EMERGENCY
DBCC checkdb(etrade)
ALTER DATABASE etrade SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB (etrade, REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE etrade SET MULTI_USER
(Emergencia)
ALTER DATABASE etrade SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB (etrade, REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE etrade SET MULTI_USER
(Recuperação pendente / Recovery pending)
ALTER DATABASE Etrade SET EMERGENCY;
GO
ALTER DATABASE Etrade set single_user
GO
DBCC CHECKDB (Etrade, REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS;
GO
ALTER DATABASE Etrade set multi_user
GO
Read-Only
False
USE etrade
GO
ALTER DATABASE etrade SET READ_WRITE WITH NO_WAIT
GO
Restricted_User
MULTI_USER
ALTER DATABASE etrade SET MULTI_USER;
colocar online
Não é muito aconselhável rodar isso sem antes dar um checkdb pra ver os erros, pois é importante que o banco conheça os erros antes.
Veja mais aqui: SQL SERVER CENTRAL
DBCC CHECKDB(etrade, REPAIR_ALLOW_DATA_LOSS);
SELECT
database_name, name, backup_start_date, backup_finish_date, datediff(mi, backup_start_date, backup_finish_date) [tempo (min)],
position, first_lsn, last_lsn, server_name, recovery_model,
type, cast(backup_size/1024/1024 as numeric(15,2)) [Tamanho (MB)], B.is_copy_only
FROM msdb.dbo.backupset B
SET NOCOUNT ON
DECLARE
@REORG_FRAG_THRESH FLOAT = 10.0
,@REBUILD_FRAG_THRESH FLOAT = 30.0
,@FILL_FACTOR TINYINT = 80
,@REPORT_ONLY BIT = 0
,@PAGE_COUNT_THRESH SMALLINT = 1000
,@OBJECTID INT
,@INDEXID INT
,@PARTITIONCOUNT BIGINT
,@SCHEMANAME NVARCHAR(130)
,@OBJECTNAME NVARCHAR(130)
,@INDEXNAME NVARCHAR(130)
,@PARTITIONNUM BIGINT
,@PARTITIONS BIGINT
,@FRAG FLOAT
,@PAGE_COUNT INT
,@COMMAND NVARCHAR(4000)
,@INTENTIONS NVARCHAR(4000)
DECLARE @TABLE_VAR TABLE(
OBJECTID INT,
INDEXID INT,
PARTITIONNUM INT,
FRAG FLOAT,
PAGE_COUNT INT)
INSERT INTO @TABLE_VAR
SELECT
[OBJECT_ID],
[INDEX_ID],
[PARTITION_NUMBER],
[AVG_FRAGMENTATION_IN_PERCENT],
[PAGE_COUNT]
FROM
SYS.DM_DB_INDEX_PHYSICAL_STATS (DB_ID(), NULL, NULL , NULL, 'LIMITED')
WHERE
[AVG_FRAGMENTATION_IN_PERCENT] > @REORG_FRAG_THRESH
AND PAGE_COUNT > @PAGE_COUNT_THRESH
AND INDEX_ID > 0
DECLARE PARTITIONS CURSOR FOR
SELECT *
FROM
@TABLE_VAR
OPEN PARTITIONS
WHILE (1=1) BEGIN FETCH NEXT
FROM
PARTITIONS
INTO @OBJECTID,
@INDEXID,
@PARTITIONNUM,
@FRAG,
@PAGE_COUNT
IF @@FETCH_STATUS < 0 BREAK
SELECT
@OBJECTNAME = QUOTENAME(O.[NAME]),
@SCHEMANAME = QUOTENAME(S.[NAME])
FROM
SYS.OBJECTS [O] WITH (NOLOCK)
JOIN SYS.SCHEMAS [S] WITH (NOLOCK) ON S.[SCHEMA_ID] = O.[SCHEMA_ID]
WHERE
O.[OBJECT_ID] = @OBJECTID
SELECT
@INDEXNAME = QUOTENAME([NAME])
FROM
SYS.INDEXES WITH (NOLOCK)
WHERE
[OBJECT_ID] = @OBJECTID
AND [INDEX_ID] = @INDEXID
SELECT
@PARTITIONCOUNT = COUNT (*)
FROM
SYS.PARTITIONS WITH (NOLOCK)
WHERE
[OBJECT_ID] = @OBJECTID
AND [INDEX_ID] = @INDEXID
SET @INTENTIONS = @SCHEMANAME + N'.' + @OBJECTNAME + N'.' + @INDEXNAME + N':' + CHAR(13) + CHAR(10)
SET @INTENTIONS = REPLACE(SPACE(LEN(@INTENTIONS)), ' ', '=') + CHAR(13) + CHAR(10) +@INTENTIONS
SET @INTENTIONS = @INTENTIONS + N' FRAGMENTATION: ' + CAST(@FRAG AS NVARCHAR) + N'%' + CHAR(13) +
CHAR(10) + N' PAGE COUNT: ' + CAST(@PAGE_COUNT AS NVARCHAR) + CHAR(13) + CHAR(10)
IF
@FRAG < @REBUILD_FRAG_THRESH
BEGIN
SET @INTENTIONS = @INTENTIONS +N' OPERATION: REORGANIZE' + CHAR(13) + CHAR(10)
SET @COMMAND = N'ALTER INDEX ' + @INDEXNAME + N' ON ' + @SCHEMANAME + N'.' + @OBJECTNAME +
N' REORGANIZE; ' + N' UPDATE STATISTICS ' + @SCHEMANAME + N'.' + @OBJECTNAME + N' ' + @INDEXNAME + ';'
END
IF
@FRAG >= @REBUILD_FRAG_THRESH
BEGIN
SET @INTENTIONS = @INTENTIONS + N' OPERATION: REBUILD' + CHAR(13) + CHAR(10)
SET @COMMAND =
N'ALTER INDEX ' + @INDEXNAME + N' ON ' + @SCHEMANAME + N'.' + @OBJECTNAME + N' REBUILD'
END
IF
@PARTITIONCOUNT > 1
BEGIN
SET @INTENTIONS = @INTENTIONS + N' PARTITION: ' + CAST(@PARTITIONNUM AS NVARCHAR(10)) + CHAR(13) + CHAR(10)
SET @COMMAND = @COMMAND + N' PARTITION=' + CAST(@PARTITIONNUM AS NVARCHAR(10))
END
IF
@FRAG >= @REBUILD_FRAG_THRESH AND @FILL_FACTOR > 0 AND @FILL_FACTOR < 100
BEGIN
SET @INTENTIONS = @INTENTIONS + N' FILL FACTOR: ' + CAST(@FILL_FACTOR AS NVARCHAR) + CHAR(13) + CHAR(10)
SET @COMMAND = @COMMAND + N' WITH (FILLFACTOR = ' + CAST(@FILL_FACTOR AS NVARCHAR) + ')'
END
IF
@REPORT_ONLY = 0
BEGIN
SET @INTENTIONS = @INTENTIONS + N' EXECUTING: ' + @COMMAND
PRINT @INTENTIONS
EXEC (@COMMAND)
END
ELSE
BEGIN
PRINT @INTENTIONS
END
END;
CLOSE PARTITIONS;
DEALLOCATE PARTITIONS;
Index
Como recriar Index no banco do E-Trade >> Clique Aqui << e veja como fazer.