Tuesday, 30 December 2014

Get All Details from Database and tables with rows and Db size


SET NOCOUNT ON 
DBCC UPDATEUSAGE(0)

--Check DB size.
EXEC sp_spaceused

-- Table row counts and sizes.
CREATE TABLE #Temptable
(
    [name] NVARCHAR(128),
    [rows] CHAR(11),
    reserved VARCHAR(18),
    data VARCHAR(18),
    index_size VARCHAR(18),
    unused VARCHAR(18)
)

INSERT # Temptable EXEC sp_msForEachTable 'EXEC sp_spaceused ''?'''

-- # select data from table
SELECT * FROM  # Temptable

-- # Count tatal rows
SELECT SUM(CAST([rows] AS int)) AS [rows]FROM   # Temptable

-- # Drop Temp Table

DROP TABLE # Temptable

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...