Thursday, April 25, 2013

get Transaction Log size SQL Server 2008

Here is quick way to get Transaction Log size

DBCC SQLPERF(LOGSPACE)

Wednesday, April 10, 2013

Generate Row number


This method will only work when you do "select into from "

Syntax is :
select identity(int,1,1) as RowNumber, *
into newtable
from oldtable

Monday, March 4, 2013

Table Size / Count Rows in SQL Server Table

Here is quick way to get table size / rows in sql server tables:

SELECT t.NAME AS TableName, p.rows AS RowCounts
, SUM(a.total_pages) * 8 AS TotalSpaceKB
, SUM(a.used_pages) * 8 AS UsedSpaceKB
, (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM sys.tables t
INNER JOIN sys.indexes i
ON t.OBJECT_ID = i.object_id
INNER JOIN sys.partitions p
ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN sys.allocation_units a
ON p.partition_id = a.container_id
WHERE t.NAME NOT LIKE 'dt%'
AND t.is_ms_shipped = 0 AND i.OBJECT_ID > 255
GROUP BY t.Name, p.Rows
ORDER BY t.Name    

Friday, March 1, 2013

Register 32 bit DLL on 64 bit machine


To register 32 bit dll, we should go C:\Windows\Syswow64 and issue regsvr32 command.
Please see following screen to register and unregister dll.




Friday, January 4, 2013

Procedure or function has too many arguments specified

This is the error I got when I had Gridview bind with SqlDataSource.
Very hard to track this error if u dont have mismatch parameters.

Things to check when get this error:
  1. Check all spellings for all parameters.
  2. Check parameters defined in Stored Procedure
  3. If DataKeyNames parameter is set for Gridview, then the Stored Procedure must have the same parameter in its parameter list.
Thanks,

Thursday, December 27, 2012

Set DropDownList Value from Codebehind

To set value of dropdownlist (assuming you have the list populated), do following:

DropDownList1.SelectedValue = "your item value"

 

Monday, December 24, 2012

SQL Index Drop and Create Order


Always drop the Non Cluster Index first as it has reference to Cluster Index.
If Cluster Index was removed first, non Cluster Index would have to be updated on cluster index removal.
When you build index, first build the Cluster Index and then Non Cluster.

Note: All NON Cluster Indices can be build simultaneously once Cluster Index is created.