Archives by Tag 'SQL'

MSSQL : List all tables with size and row count

By admin - Last updated: Sunday, December 13, 2009

It comes to be very handy while analyzing the database tables.
Here is a quick and dirty script lists all the tables and their rows counts, data size.

DECLARE @table table(Id int IDENTITY(1,1)
, Name varchar(256))

INSERT INTO @table
SELECT b.name + ‘.’+ a.name
FROM sys.tables a INNER JOIN sys.schemas b
ON a.schema_id = b.schema_id

INSERT INTO @table
SELECT ‘-1′

DECLARE @result table( TableName varchar(256)
, TotalRows [...]

SQL XML, select from xml using nodes() function

By admin - Last updated: Thursday, October 1, 2009

Very handy function that helps me move small data around.

DECLARE @myXml AS XML
SET @myXml =
‘<ArrayOfProduct>
        <Product id="1">
                <Description>test1</Description>
        </Product>
        <Product id="2">
                <Description>test2</Description>
        </Product>     
</ArrayOfProduct>

SELECT
      [...]