Notícias

AddThis Social Bookmark Button

Imprimir
AddThis Social Bookmark Button

 

 

Skol e suas propagandas com muito bom humor. Muito massa.

Imprimir
AddThis Social Bookmark Button

Parte 1:

Parte 2:

Parte 3:

 

Fonte: alexlpereira

Imprimir
AddThis Social Bookmark Button

Introduction

In this article, I want to tell you about some useful undocumented DBCC commands, and how you can use these commands in SQL Server 7.0 and 2000 for administering and monitoring.

DBCC is an abbreviation for Database Console Command. DBCC commands are generally used to check the physical and logical consistency of a database, although they are also used for a variety of miscellaneous tasks, as you will see here.

Note, the command:

DBCC TRACEON (3604)

is issued before each of the following DBCC examples in order to better demonstrate the effects of the command by displaying a trace of the output of the DBCC command. It is not actually required to run the DBCC commands examined below. If you run any of the DBCC commands below without the above option, the command runs, but you don't see what it is doing.

Undocumented DBCC commands

Here you can find some useful undocumented DBCC commands.

1. DBCC BUFFER

This command can be used to display buffer headers and pages from the buffer cache.

Syntax:

dbcc buffer ([dbid|dbname] [,objid|objname] [,nbufs], [printopt])

where
 
  dbid|dbname   - database id|database name
  objid|objname - object id|object name
  nbufs         - number of buffers to examine
  printopt      - print option
                  0 - print out only the buffer header and page header
                      (default)
                  1 - print out each row separately and the offset table
                  2 - print out each row as a whole and the offset table

This is the example:

DBCC TRACEON (3604)
dbcc buffer(master,'sysobjects')

2. DBCC BYTES

This command can be used to dump out bytes from a specific address.

Syntax:

dbcc bytes ( startaddress, length )

where
 
  startaddress  - starting address to dump  
  length        - number of bytes to dump

This is the example:

DBCC TRACEON (3604)
dbcc bytes (10000000, 100)

3. DBCC DBINFO

Displays DBINFO structure for the specified database.

Syntax:

DBCC DBINFO [( dbname )]

where
 
  dbname - is the database name.

This is the example:

DBCC TRACEON (3604)
DBCC DBINFO (master)

4. DBCC DBTABLE

This command displays the contents of the DBTABLE structure.

Syntax:

DBCC DBTABLE ({dbid|dbname})

where 
 
  dbid|dbname  - database name or database ID

This is the example:

DBCC TRACEON (3604)
DBCC DBTABLE (master)

The DBTABLE structure has an output parameter called dbt_open. This parameter keeps track of how many users are in the database.

Look at here for more details:
FIX: Database Usage Count Does Not Return to Zero

5. DBCC DES

Prints the contents of the specified DES (descriptor).

Syntax:

dbcc des [( [dbid|dbname] [,objid|objname] )]

where
 
dbid|dbname   - database id|database name.
objid|objname - object id|object name

This is the example:

DBCC TRACEON (3604)
DBCC DES

6. DBCC HELP

DBCC HELP returns syntax information for the specified DBCC statement. In comparison with DBCC HELP command in version 6.5, it returns syntax information only for the documented DBCC commands.

Syntax:

DBCC HELP ('dbcc_statement' | @dbcc_statement_var | '?')

This is the example:

DBCC TRACEON (3604)
DECLARE @dbcc_stmt sysname
SELECT @dbcc_stmt = 'CHECKTABLE'
DBCC HELP (@dbcc_stmt)

7. DBCC IND

Shows all pages in use by indexes of the specified table.

Syntax:

dbcc ind( dbid|dbname, objid|objname, printopt = {-2|-1|0|1|2|3} )

where
 
  dbid|dbname   - database id|database name.
  objid|objname - object id|object name
  printopt      - print option

There is change in this command in how it is used in SQL Server 7.0, in that the printopt parameter is now no longer optional.

This is the example:

DBCC TRACEON (3604)
DBCC IND (master, sysobjects, 0)

8. DBCC log

This command is used to view the transaction log for the specified database.

Syntax:

DBCC log ( {dbid|dbname}, [, type={-1|0|1|2|3|4}] )

PARAMETERS: 
   Dbid or dbname - Enter either the dbid or the name of the database
                    in question.
 
      type - is the type of output:
 
      0 - minimum information (operation, context, transaction id)
 
      1 - more information (plus flags, tags, row length, description)
 
      2 - very detailed information (plus object name, index name,
          page id, slot id)
 
      3 - full information about each operation
 
      4 - full information about each operation plus hexadecimal dump
          of the current transaction log's row.
 
     -1 - full information about each operation plus hexadecimal dump
          of the current transaction log's row, plus Checkpoint Begin,
          DB Version, Max XDESID
 
by default type = 0

To view the transaction log for the master database, run the following command:

DBCC log (master)

9. DBCC PAGE

You can use this command to view the data page structure.

Syntax:

DBCC PAGE ({dbid|dbname}, pagenum [,print option] [,cache] [,logical])

PARAMETERS: 
   Dbid or dbname - Enter either the dbid or the name of the database
                    in question.
 
   Pagenum - Enter the page number of the SQL Server page that is to
             be examined.
 
   Print option - (Optional) Print option can be either 0, 1, or 2.
 
                  0 - (Default) This option causes DBCC PAGE to print
                      out only the page header information.
                  1 - This option causes DBCC PAGE to print out the
                      page header information, each row of information
                      from the page, and the page's offset table. Each
                      of the rows printed out will be separated from
                      each other.
                  2 - This option is the same as option 1, except it
                      prints the page rows as a single block of
                      information rather than separating the
                      individual rows. The offset and header will also
                      be displayed.
 
   Cache - (Optional) This parameter allows either a 1 or a 0 to be
           entered.
           0 - This option causes DBCC PAGE to retrieve the page
               number from disk rather than checking to see if it is
               in cache.
           1 - (Default) This option takes the page from cache if it
               is in cache rather than getting it from disk only.
 
   Logical - (Optional) This parameter is for use if the page number
             that is to be retrieved is a virtual page rather then a
             logical page. It can be either 0 or 1.
 
             0 - If the page is to be a virtual page number.
             1 - (Default) If the page is the logical page number.

This is the example:

DBCC TRACEON (3604)
DBCC PAGE (master, 1, 1)

Look at here for more details:
Data page structure in MS SQL 6.5

10. DBCC procbuf

This command displays procedure buffer headers and stored procedure headers from the procedure cache.

Syntax:

DBCC procbuf( [dbid|dbname], [objid|objname], [nbufs], [printopt = {0|1}] )

where
 
  dbid|dbname   - database id|database name.
  objid|objname - object id|object name
  nbufs         - number of buffers to print    
  printopt - print option
             (0  print out only the proc buff and proc header (default)  
              1  print out proc buff, proc header and contents of buffer)

This is the example:

DBCC TRACEON (3604)
DBCC procbuf(master,'sp_help',1,0)

11. DBCC prtipage

This command prints the page number pointed to by each row on the specified index page.

Syntax:

DBCC prtipage( dbid, objid, indexid, indexpage )

where
 
  dbid      - database ID  
  objid     - object ID  
  indexid   - index ID  
  indexpage - the logical page number of the index page to dump

This is the example:

DBCC TRACEON (3604)
DECLARE @dbid int, @objectid int
SELECT @dbid = DB_ID('master')
SELECT @objectid = object_id('sysobjects')
DBCC prtipage(@dbid,@objectid,1,0)

12. DBCC pss

This command shows info about processes currently connected to the server.

Syntax:

DBCC pss( suid, spid, printopt = { 1 | 0 } )

where
 
  suid     - server user ID     
  spid     - server process ID    
  printopt - print option
             (0  standard output,
              1  all open DES's and current sequence tree)

This is the example:

DBCC TRACEON (3604)
dbcc pss

13. DBCC resource

This command shows the server's level RESOURCE, PERFMON and DS_CONFIG information. RESOURCE shows addresses of various data structures used by the server. PERFMON structure contains master..spt_monitor field info. DS_CONFIG structure contains master..syscurconfigs field information.

Syntax:

DBCC resource

This is the example:

DBCC TRACEON (3604)
DBCC resource

14. DBCC TAB

You can use the following undocumented command to view the data pages structure (in comparison with DBCC PAGE, this command will return information about all data pages for viewed table, not only for particular number).

Syntax:

DBCC tab (dbid, objid)

where
 
  dbid  - is the database id
  objid - is the table id

This is the example:

DBCC TRACEON (3604)
DECLARE @dbid int, @objectid int
SELECT @dbid = DB_ID('master')
SELECT @objectid = object_id('sysdatabases')
DBCC TAB (@dbid,@objectid)

 

 

fonte: mssqlcity

Imprimir
AddThis Social Bookmark Button

da Reportagem Local

O diretor de "A Hora do Pesadelo", que estreia em 7 de maio no Brasil, foi contra a moda das três dimensões. Em entrevista ao jornal norte-americano "Los Angeles Times", o cineasta Samuel Bayer revelou ter batido o pé contra o 3D.

"Quando a New Line iniciou várias conversas sobre a conversão da obra para 3D, nós demos um passo para trás", disse. Segundo ele, o longa-metragem de terror foi pensado para duas dimensões.

 

No longa-metragem, o psicopata Freddy Krueger persegue um grupo de adolescentes suburbanos em seus sonhos. O elenco conta com Jackie Earle Haley, Rooney Mara, Kyle Gallner, Thomas Dekker e Katie Cassidy.

O primeiro longa da franquia foi feito por Wes Craven e lançado em 1984. O sucesso do trabalho levou à criação de uma série de sequências, tornando o vilão um dos mais populares da história do cinema.

 

fonte: Folha Online

 


Imprimir
AddThis Social Bookmark Button
  1. Criando o script que será executado via comando pelo Sistema operacional:

Crie um arquivo com a extensão .sql no bloco de notas ou no SQL Query com as seguintes instruções:

 

Se for SQL 2000:

USE NOME_DO_BANCO_SQL

BACKUP DATABASE NOME_DO_BANCO_SQL TO DISK= "DIRETORIO_ONDE_SERÁ_SALVO_O_BACKUP\NOME_DO_BANCO_SQL.BAK"

 

Se for SQL 2005/SQL Express 2005:

USE [NOME_DO_BANCO_SQL]

BACKUP DATABASE [NOME_DO_BANCO_SQL] TO  DISK = N' DIRETORIO_ONDE_SERÁ_SALVO_O_BACKUP\NOME_DO_BANCO_SQL.BAK' WITH NOFORMAT, INIT,  NAME = N' NOME_DO_BANCO_SQL-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10

GO

 

Se o SGBD conter mais de um banco, faça:

 

Se for SQL 2000:

USE NOME_DO_BANCO_SQL

BACKUP DATABASE NOME_DO_BANCO_SQL TO DISK= "DIRETORIO_ONDE_SERÁ_SALVO_O_BACKUP\NOME_DO_BANCO_SQL.BAK"

USE NOME_DO_2º_BANCO_SQL

BACKUP DATABASE NOME_DO_2º_BANCO_SQL TO DISK= "DIRETORIO_ONDE_SERÁ_SALVO_O_BACKUP\ NOME_DO_2º_BANCO_SQL.BAK"

Se for SQL 2005/SQL Express 2005:

USE [NOME_DO_BANCO_SQL]

BACKUP DATABASE [NOME_DO_BANCO_SQL] TO  DISK = N' DIRETORIO_ONDE_SERÁ_SALVO_O_BACKUP\NOME_DO_BANCO_SQL.BAK' WITH NOFORMAT, INIT,  NAME = N' NOME_DO_BANCO_SQL-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10

GO

 

USE [NOME_DO_2º_BANCO_SQL]

BACKUP DATABASE [NOME_DO_2º_BANCO_SQL] TO  DISK = N' DIRETORIO_ONDE_SERÁ_SALVO_O_BACKUP\ NOME_DO_2º_BANCO_SQL.BAK' WITH NOFORMAT, INIT,  NAME = N'NOME_DO_2º_BANCO_SQL -Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10

GO

 

... E assim por diante se existir mais bancos no SGBD.

Salve o script .sql em um diretório onde estará localizado os backup’s (por exemplo: C:\Backup).

 

  1. Para executar o SCRIPT .sql criado, precisamos criar um EXECUTAVEL .bat com o seguinte conteúdo:

 

Se for SQL 2000:

OSQL -U sa -P SENHA_DO_USUARIO_SA -i "DIRETORIO_ONDE_ESTÁ_O_SCRIPT_SQL_DE_BACKUP\NOME_DO_ARQUIVO_SQL_DE_BACKUP.SQL"

Se for SQL 2005:

SQLCMD -S NOME_DO_SERVIDOR_SQL -d NOME_DO_BANCO -U sa -P SENHA_DO_USUARIO_SA -i DIRETORIO_ONDE_ESTÁ_O_SCRIPT_SQL_DE_BACKUP\NOME_DO_ARQUIVO_SQL_DE_BACKUP.SQL

Se for SQL 2005 Express:

sqlcmd -S .\SQLExpress -i DIRETORIO_ONDE_ESTÁ_O_SCRIPT_SQL_DE_BACKUP\NOME_DO_ARQUIVO_SQL_DE_BACKUP.SQL

Salve este .bat no mesmo diretório do script .sql.

 

Utilizando qualquer programa gerenciador de backup com suporte a agendamento (por exemplo Cobian Backup, Genie Backup, Arc Server e etc.) faça com que eles executem o .bat no horário preferido p ser realizado o backup SQL.

Coloque neles também para fazerem compressão do arquivo e ative a opção para eles salvarem a data/hora no nome deste arquivo.

 

Dicas:

  • Crie um diretório dentro do diretório onde estão o .sql e .bat (Por exemplo: C:\Backup\SQL). Deixe este diretório SQL para salvar somente os .bak. Altere isto no script SQL. Assim os backups ficarão mais organizados;
  • Coloque o agendamento em horários onde não ocorrem muitas solicitações do banco de dados;
  • Sempre verifique o diretório de backup e faca sua manutenção salvando eles em uma unidade externa (FITA DAT, RD1000, HD EXTERNO e etc.);
<>