Thứ Ba, 11 tháng 9, 2018

[SQL] Capture Space Used

IF OBJECT_ID(N'[dbo].[SpaceUsedLogs]', N'U') IS NULL
BEGIN
 CREATE TABLE SpaceUsedLogs (
  name VARCHAR(200)
  ,rows BIGINT
  ,reserved VARCHAR(100)
  ,data VARCHAR(100)
  ,index_size VARCHAR(100)
  ,unused VARCHAR(100)
  ,created_date DATETIME DEFAULT getdate()
  )
END
GO

DECLARE @spaceUsed TABLE (
 name VARCHAR(200)
 ,rows BIGINT
 ,reserved VARCHAR(100)
 ,data VARCHAR(100)
 ,index_size VARCHAR(100)
 ,unused VARCHAR(100)
 )

INSERT INTO @spaceUsed
EXEC sp_spaceused [Table Name 1]

INSERT INTO @spaceUsed
EXEC sp_spaceused [Table Name 2]

-- ...

INSERT INTO SpaceUsedLogs (name, rows, reserved, data, index_size, unused)
SELECT * FROM @spaceUsed

1 nhận xét :

  1. Have you ever considered about adding a little bit more than just your articles? I mean, what you say is important and everything. But imagine if you added some great graphics or videos to give your posts more, "pop"! Your content is excellent, but with pics and clips, this site could undeniably be one of the best in its niche. Wonderful blog! How To Password Protect Folder Like A Professional.

    Trả lờiXóa