Thursday, May 26, 2011

Database Table Size

If you want to know the size of your database table in bytes, use the below command. 

sp_spaceused <your_table_name>

Saturday, April 23, 2011

T-SQL for finding SQL Server Version

SELECT
    CAST(SERVERPROPERTY('ProductVersion') AS varchar(100)) + ' ' +
    CAST(SERVERPROPERTY('Edition') AS varchar(100)) + ' ' +
    CAST(SERVERPROPERTY('ProductLevel') AS varchar(100));

Friday, March 25, 2011

GETDATE() to get only date in sql

To get only the date from T-SQL GETDATE() function (excluding the time part)

Example Query:

Select * From Employee Where JoinDate = Convert(Date, GETDATE())

Thursday, March 10, 2011

Code Formatter

Excellent online code formatter for C#, VB, T-Sql. Yes, it's FREE http://www.manoli.net/csharpformat/

Size of the database tables

I came across this wonderful t-sql script which displays the size of all the tables in a SQL Server Database. Thanks to Vidhya Sagar


SELECT 'Database Name: ', Db_name()  
SET nocount ON 
 
IF EXISTS(SELECT name 
FROM   tempdb..sysobjects 
WHERE  name = '##tmp') 
DROP TABLE ##tmp 
 
CREATE TABLE ##tmp 
( 
nam     VARCHAR(50), 
ROWS    INT, 
res     VARCHAR(15), 
data    VARCHAR(15), 
ind_sze VARCHAR(15), 
unsed   VARCHAR(15) 
) 
 
GO 
 
DECLARE @tblname VARCHAR(50) 
DECLARE tblname CURSOR FOR 
SELECT name 
FROM   sysobjects 
WHERE  xtype = 'U' 
 
OPEN tblname 
 
FETCH NEXT FROM tblname INTO @tblname 
 
WHILE @@FETCH_STATUS = 0 
BEGIN 
INSERT INTO ##tmp 
EXEC Sp_spaceused @tblname 
 
FETCH NEXT FROM tblname INTO @tblname 
END 
 
CLOSE tblname 
 
DEALLOCATE tblname 
 
GO 
 
SELECT nam     table_name, 
ROWS    total_rows, 
res     total_table_size, 
data    data_size, 
ind_sze index_size, 
unsed   unused_space 
FROM   ##tmp 
 
DROP TABLE ##tmp 

Saturday, January 8, 2011

Secure your web.config file

ScottGu has an excellent article on the latest ASP.NET Security vulnerability and a hacker could download your web.config file which may contain sensitive data. Solution is to include a simple "CustomError" section. Read more

NTFS Permission using Command Prompt and .NET Framework Class Library

To provide NTFS Permission to any file using the Command Prompt, here is the command

CACLS "C:\test.bat" /e /p EveryOne:f

The above command gives "Full" permission to the file "test.bat" for "EveryOne" user

For more info, visit http://technet.microsoft.com/en-us/library/bb490872.aspx


VB.NET code for the same,

Imports System.IO

Imports System.Security.AccessControl

Dim fSecurity As FileSecurity

fSecurity = File.GetAccessControl(fileName)

fSecurity.AddAccessRule(New FileSystemAccessRule("EveryOne", FileSystemRights.Write, AccessControlType.Allow))

File.SetAccessControl(fileName, fSecurity)

AZ-104

Microsoft Azure is huge and it has hundreds of services underneath its umbrella It's actually going to be quite difficult to comprehend ...