Tuesday, November 29, 2011

Monday, October 10, 2011

Automate Windows Server defragmentation

E drive is the drive you wish to defragment

Put this in a bat file and run a scheuled task pointing the bat file.
defrag.exe -v e: >c:\temp\logfile.txt

To check the status you can look how long, etc in the log file under the Advanced /  View Log of the scheduled task  menu window.

Monday, October 3, 2011

Spaced Used by a table in a specific database.

Shows you how to get the SQL Server database table size
EXEC SP_SPACEUSED 'TABLE NAME'

Shows you how to get the size of a database
EXEC SP_SPACEUSED

Shows you how to get the all tables size from database
EXEC sp_MSforeachtable @command1="EXEC sp_spaceused '?'"

–--create temp table to store the result
CREATE TABLE #temptable
  (
     tablename    VARCHAR(100),
     numberofrows VARCHAR(100),
     reservedsize VARCHAR(50),
     datasize     VARCHAR(50),
     indexsize    VARCHAR(50),
     unusedsize   VARCHAR(50)
  )
---Inserting into temp table
INSERT INTO #temptable
            (tablename,
             numberofrows,
             reservedsize,
             datasize,
             indexsize,
             unusedsize)

EXEC sp_MSforeachtable @command1="EXEC sp_spaceused '?'"

SELECT *
FROM   #temptable
---drop the temporary table
DROP TABLE #temptable

Tuesday, September 27, 2011

How to get RDL information from Reporting Services Report.

--FROM http://blogs.netconnex.com/2011/05/extracting-ssrs-report-rdl-xml-from.html
--The first CTE gets the content as a varbinary(max)
--as well as the other important columns for all reports,
--data sources and shared datasets.
WITH ItemContentBinaries AS
(
  SELECT
     ItemID,Name,[Type]
   ,CASE Type
      WHEN 2 THEN 'Report'
      WHEN 5 THEN 'Data Source'
      WHEN 7 THEN 'Report Part'
      WHEN 8 THEN 'Shared Dataset'
      ELSE 'Other'
     END AS TypeDescription
   ,CONVERT(varbinary(max),Content) AS Content   
   FROM ReportServer.dbo.Catalog
   WHERE Type IN (2,5,8)
),
--The second CTE strips off the BOM if it exists...
ItemContentNoBOM AS
(
  SELECT
     ItemID,Name,[Type],TypeDescription
    ,CASE
      WHEN LEFT(Content,3) = 0xEFBBBF
        THEN CONVERT(varbinary(max),SUBSTRING(Content,4,LEN(Content)))
      ELSE
        Content
    END AS Content
  FROM ItemContentBinaries
)
--The old outer query is now a CTE to get the content in its xml form only...
,ItemContentXML AS
(
  SELECT
    ItemID,Name,[Type],TypeDescription
   ,CONVERT(xml,Content) AS ContentXML
  FROM ItemContentNoBOM
)
--now use the XML data type to extract the queries, and their command types and text....
SELECT
   ItemID,Name,[Type],TypeDescription,ContentXML
  ,ISNULL(Query.value('(./*:CommandType/text())[1]','nvarchar(1024)'),'Query') AS CommandType
  ,Query.value('(./*:CommandText/text())[1]','nvarchar(max)') AS CommandText
FROM ItemContentXML 
--Get all the Query elements (The "*:" ignores any xml namespaces)
CROSS APPLY ItemContentXML.ContentXML.nodes('//*:Query') Queries(Query

Monday, August 22, 2011

Disk System

What kind of database?
------------------------
OLAP - Sequential I/O,  Read intensive
OLTP - Random I/O, Read /Write intensive

Calculating the number of disks required
----------------------------------------
1. the required disk I/O per second
2. I/O per second capacity (IOPS) of the individual disks included

Required # Disks = (Reads/sec + (Writes/sec * RAID adjuster)) / Disk IOPS

Remember to separate the transaction log and data files.

RAID = Redundant Array of Independent Disks

RAID0 - zero redundancy RAID (not recommended)
RAID1 -  disk mirroring,  50% disk utilization level, write medium, read high
RAID5 - disk utilization  equals 1 - (1/N), write low, read high, minimum three drives

SAN - Storage Area Network
------------------------------------
*Multiple servers can connect to a SAN via special host bus adapter (HBA) cards
installed in each connecter server.
*Disks within the SAN are grouped together into logical unit numbers (LUNs)
and presented as required to connected servers. The server sees the LUN as a locally attached disk.
*Major benefits of a SAN is sharing disks among many servers to maximize usage.
*To get best performance dedicate the entire SAN to a single, mission critical database.

If your organization decides on a SAN storage system have a good working relationship with your SAN administrator.

Each physical disk in a SAN can be carved up into parts and used in the creation of separate LUNs.
As a result, LUNs from many servers can all be using different parts of the same physical disks.














Sunday, July 31, 2011

Remotely Log Off Remote Desktop Users

How to query for users on a machine

qwinsta /server:<serverName>  OR  quser /server:<serverName>

How to log a user off of a machine

logoff <sessionId> /server:<serverName>

Friday, July 1, 2011

Dependency information on my table

To find out what depends on the table you are about to alter or drop.

SELECT
referencing_schema_name, referencing_entity_name
FROM sys.dm_sql_referencing_entities(' schema_name.referenced_entity_name ' , ' <referenced_class> ' )

additional information<
{
referenced_class> ::=OBJECT| TYPE
| XML_SCHEMA_COLLECTION| PARTITION_FUNCTION}