Advertisement
Fhernd

Receta_TSQL-2.6_Ej_3.sql

Jul 7th, 2015
1,151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.81 KB | None | 0 0
  1. -- OrtizOL - xCSw - http://ortizol.blogspot.com
  2.  
  3. -- Declaración de variables:
  4. DECLARE @TablasAdventureWorks TABLE (SchemaTable varchar(100));
  5. DECLARE @NombreTabla varchar(100);
  6. -- Inserta los nombres de las tablas en la tabla @ATablasAdventureWorks:
  7. INSERT @TablasAdventureWorks (SchemaTable)
  8.   SELECT TABLE_SCHEMA + '.' + TABLE_NAME
  9.   FROM INFORMATION_SCHEMA.tables
  10.   WHERE TABLE_TYPE = 'BASE TABLE'
  11.   ORDER BY TABLE_SCHEMA + '.' + TABLE_NAME;
  12. -- Reporte de espacio usado por cada table con el
  13. -- el procedimiento almacenado `sp_spaceused`:
  14. WHILE (SELECT COUNT(*) FROM @TablasAdventureWorks) > 0
  15. BEGIN
  16.   SELECT TOP 1 @NombreTabla = SchemaTable
  17.   FROM @TablasAdventureWorks
  18.   ORDER BY SchemaTable;
  19.   EXEC sp_spaceused @NombreTabla;
  20.   DELETE @TablasAdventureWorks
  21.   WHERE SchemaTable = @NombreTabla;
  22. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement