Arquivo da categoria: Banco de dados

Selecionar banco de dados e tamanhos

SELECT 
      database_name = DB_NAME(database_id)
    , log_size_mb = CAST(SUM(CASE WHEN type_desc = 'LOG' THEN size END) * 8. / 1024 AS DECIMAL(8,2))
    , row_size_mb = CAST(SUM(CASE WHEN type_desc = 'ROWS' THEN size END) * 8. / 1024 AS DECIMAL(8,2))
    , total_size_mb = CAST(SUM(size) * 8. / 1024 AS DECIMAL(8,2))
FROM sys.master_files WITH(NOWAIT)
WHERE database_id = DB_ID() -- for current db 
GROUP BY database_id

Executar bloco de comando no PostgreSQL

Bloco nomeado

DO $$ 
	<<first_block>>
DECLARE
  film_count integer := 0;
BEGIN
   -- get the number of films
   SELECT COUNT(*) 
   INTO film_count
   FROM "Lancamento";
   -- display a message
   RAISE NOTICE 'The number of films is %', film_count;
END first_block $$;

Bloco anonimo

DO $$ 
DECLARE
  film_count INTEGER := 0;
BEGIN
   -- get the number of films
   SELECT COUNT(*) INTO film_count FROM "Lancamento";
   -- display a message
   RAISE NOTICE 'The number of films is %', film_count;
END
$$;