MCDBA Brasil


  • Home
  • Sobre
  • Contato

Livros





Links Rápidos

SQL Server Builds (All Versions/Editions)


Download SQL Server 2017 (trial)


SQL Server 2017 Feature Pack


SQL Server 2016 Feature Pack


Cumulative Update SQL Server 2017 builds


Cumulative Update SQL Server 2016 builds


Cumulative Update SQL Server 2014 builds


Cumulative Update SQL Server 2012 builds


SQL Server 2005/2008 Samples Databases


Documentando o Servidor SQL Server


Analisando a Performance do Servidor-CheckList


Virtual PASS PT


Faça parte do maior virtual chapter do PASS com conteúdos técnicos em Português sobre SQL Server.

Todos os meses um evento Online para você! Acompanhe aqui os WebCasts já agendados

Sindicalize seu blog ou site ao VirtualPASSPT

SQL Server Blogs

SQL Server Query Processing Team


SQL Programmability & API Development Team


SQL Server Manageability Team


Latin America Support Team


Database + Disk + Performance


Microsoft SQL Server Support


SQL CLR Team


SQL Query Optimization Team


SQL 2005 Code Samples


SQL Server Express Team


SQL SMO Samples


SQL Storage Engine Team


SQL CAT Team


SQL Protocols Team


PSS SQL Server Engineers


Slava Oks on SQLOS


Ken Henderson’s blog


LUTI@Microsoft Blog


kimberly L. Trip’s blog


Fernando Garcia Blog

Dica da Semana

Procedure para Documentar as Estruturas dos Databases

por Nilton Pinheiro fevereiro 4, 2007 Nenhum comentário

O script abaixo cria a procedure sp_dba_estrutura a qual permite obter a estrutura dos database no SQL Server 7.0 ou 2000. Ao executar a procedure você terá as seguintes informações para os arquivos de dados e log:

=========================================
 Estrutura dos bancos para recuperaCao
=========================================
 
DATABASE: DBADM              
NOME DO FILE: DBADM                   
ID DO FILE: 1
PATH DO FILE: G:/MSSQL$A/data/DBADM.mdf           
GRUPO DO FILE : PRIMARY            
SIZE: 768 KB
MAX SIZE: Unlimited
GROWTH: 80 KB
USAGE: data only          
=================================================
DATABASE: DBADM              
NOME DO FILE: DBADM_log               
ID DO FILE: 2
PATH DO FILE: G:/MSSQL$A/data/DBADM_log.LDF  
SIZE: 504 KB
MAX SIZE: Unlimited
GROWTH: 80 KB
USAGE: log only           


A PROCEDURE


if exists (select * from sysobjects where id = object_id(‘dbo.sp_dba_estrutura’) and sysstat & 0xf = 4)
 drop procedure dbo.sp_dba_estrutura
GO
set quoted_identifier off
set nocount on
go
create procedure sp_dba_estrutura
 /* @CMD varchar(255)= OUTPUT  */
as
declare @dbname char(20)
declare @CMD varchar (1024)
declare @nome char(25)
declare @fileid  char(2)
declare @filename  char(80)
declare @filegroup  char(20)
declare @size       varchar(20)
declare @maxsize    varchar(20)
declare @growth     nvarchar(20)
declare @usage      char(20)


/*Descricao :
* Esta procedure objetiva demonstrar a estrutura de criação dos fILES
* de todos os databases
* Elaborada por : Joao Tadeu dos Santos – DBA – Suporte – Informática  
* Data : 24/04/2001 */


create table #temp_estrutura
( dbname char(25) null ,
nome char(25),
fileid  char(2),
filename  char(80),
filegroup  char(20) null,
size       varchar(20),
maxsize    varchar(20),
growth     nvarchar(20),
usage      char(20))


begin transaction estrutura
DECLARE dbcursor CURSOR  for
SELECT   name
FROM master..sysdatabases order by name
FOR READ ONLY
OPEN dbcursor
FETCH NEXT FROM dbcursor INTO @dbname
WHILE (@@FETCH_STATUS <> -1)
BEGIN
      select @CMD = “insert into #temp_estrutura ” + “select ” + “‘” +
      rtrim(@dbname) + “‘” + “, t1.name,  t1.fileid, t1.filename,
      t2.groupname,convert(nvarchar(15), t1.size * 8) + N’ KB’,
      caset1.maxsize when -1 then N’Unlimited’ else convert(nvarchar(15),
      t1.maxsize * 8) + N’ KB’ end),(case t1.status & 0x100000 when
      0x100000 then convert(nvarchar(3), t1.growth) + N’%’ else convert
      nvarchar(15), t1.growth * 8) + N’ KB’ end), (case t1.status & 0x40
      when 0x40 then ‘log only’ else ‘data only’ end) from ” + “master”
      +”..sysaltfiles t1,” + “master” + “..sysfilegroups t2 ” +
      ” WHERE dbid= DB_ID” + “(” + “‘” + rtrim (@dbname) + “‘” + “)” +
      ” and t1.groupid *= t2.groupid order by fileid”
      /* print @CMD    */
     exec (@CMD)
     FETCH NEXT FROM dbcursor INTO @dbname
END
close dbcursor
DEALLOCATE dbcursor


print ‘ ‘
print  ‘=========================================’
print ‘ Estrutura dos bancos para recuperaCao ‘
print  ‘=========================================’
print ‘ ‘


DECLARE dbcursor1 CURSOR  for
select dbname, nome,fileid,filename, filegroup,size,maxsize,growth,usage from #temp_estrutura
order by dbname, fileid 
FOR READ ONLY
OPEN dbcursor1
FETCH NEXT FROM dbcursor1 INTO @dbname, @nome,@fileid,@filename, @filegroup,@size,@maxsize,@growth,@usage
WHILE (@@FETCH_STATUS <> -1)
BEGIN
 
    select @CMD = ‘DATABASE         : ‘ + @dbname
    print @CMD
    select @CMD = ‘NOME DO FILE     : ‘ + @nome
    print @CMD
    select @CMD = ‘ID DO FILE       : ‘ + @fileid
    print @CMD
    select @CMD = ‘PATH DO FILE     : ‘ + convert (varchar (80),@filename)
    print @CMD 
    select @CMD = ‘GRUPO DO FILE    : ‘ + @filegroup
    print @CMD
    select @CMD = ‘SIZE             : ‘ + @size
    print @CMD
    select @CMD = ‘MAX SIZE         : ‘ + @maxsize
    print @CMD
    select @CMD = ‘GROWTH           : ‘ + @growth
    print @CMD
    select @CMD = ‘USAGE            : ‘ + @usage
    print @CMD
    SELECT @CMD = ‘=====================================================================’
    PRINT @CMD


FETCH NEXT FROM dbcursor1 INTO @dbname, @nome,@fileid,@filename, @filegroup,@size,@maxsize,@growth,@usage
END
close dbcursor1
DEALLOCATE dbcursor1


 SELECT @CMD = ‘================  F  I  M  ===========================================’
    PRINT @CMD


commit transaction estrutura


— autor : João Tadeu dos Santos

Avaliação:
Compartilhe:
  • Anterior Restaurando o Banco de Dados Master19 anos atrás
  • Próximo Coleta de DBCC ShowContigs19 anos atrás

Deixe uma resposta Cancelar resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

MVP Reconnect Award

Categorias

  • Artigos (359)
  • Dica da Semana (95)
  • Documentação (54)
  • Downloads (113)
  • MSDE 2000 (3)
  • Sem categoria (1)
  • Tutoriais (9)

Posts recentes

  • #FechouBrasil #PartiuPortugal
  • Brigando com o erro “The cached MSI file is missing”
  • MCDBABRASIL está de volta
  • Documentando o Servidor SQL Server
  • Brigando com os Erros 17182, 17826 e 17120

SQL Server AlwaysOn Video Series

Video1: Introdução ao SQLServer2012 AlwaysOn


Video2: Introdução ao SQLServer2012 AlwaysOn Availability Group


Video3: Introdução ao SQLServer2012 AlwaysOn AVG-Demo


Video4: Introdução ao SQLServer2012 AlwaysOn Listener


Video5: Introdução ao SQLServer2012 AlwaysOn Readable Secondaries


Video6: Introdução ao SQLServer2012 AlwaysOn Readable Secondaries-Demo


Video7: Introdução ao SQLServer2012 AlwaysOn Failover Clustering


Serie SQL Server Failover Clustering End-to-End

Parte 1: Configuração da Rede e Ambiente


Parte 2: Configurando o Windows 2008 R2 Domain Controler e DNS


Parte 3: Preparando os nós para o Failover Cluster


Parte 4: Configurando um Failover Cluster de 2 nós


Parte 5: Configurando as LUNs no iSCSI Software Target (Parte 1)


Parte 6: Configurando as LUNs no iSCSI Software Target (Parte 2)


Parte 7: Apresentando as LUNs para os nós do Failover Cluster


Parte 8: Configurando os discos no Failover Cluster


Parte 9: Instalando a primeira instância virtual do SQL Server 2008


Parte 10: Instalando a segunda instância virtual do SQL Server 2008


Parte 11: Instalando e Configurando o MSDTC no Failover Cluster


Parte 12: Configurando Mount Points no Cluster e SQL Server 2008


Vídeo Extra: Removendo uma Instância do SQL Server 2008 R2 em Cluster


Alta Disponibilidade no SQL Server 2008 R2: Failover Clustering Overview


Alta Disponibilidade no SQL Server 2008 R2: Failover Clustering na Prática

Menu

  • Home
  • Sobre
  • Contato

Mais

  • RSS Feeds
2026 MCDBA Brasil.