Monday, January 31, 2011

Last Activity - SQL Server Objects

The Dynamic Management View (DMV) sys.dm_db_index_usage_stats can be used to find out the counts of different types of index operations and the time each type of operation was last performed. This view counts every individual seek, scan, lookup or update on the specified object caused by user-submitted queires or by internally generated queries, such as scan for gathering statistics. The counters are initialized to empty whenever the SQL Server (MSSQLSERVER) service is started. In addition, whenever a database is detached or is shut down (for example, because AUTO_CLOSE is set to ON), all rows associated with the database are removed.

Permissions : Requires VIEW SERVER STATE permission.

USE [Test]

/* Cretate Test Table */
    Id    INT,
    Val VARCHAR(100)

/* Insert data into test table - This will refect in DMV counter */
SELECT 1, 'First'
SELECT 2, 'Second'

/* Query to Find out Last Activity on SQL Objects (such as Tables, Views) */
        ,DB_NAME(DATABASE_ID) AS DatabaseName
FROM    sys.dm_db_index_usage_stats
        AND OBJECT_ID = OBJECT_ID('SampleTest')

Tuesday, January 18, 2011

Life As a C++/MFC Programmer

One vast improvement over raw C/API development is the use of the C++ programming language. In many ways, C++ can be thought of as an object-oriented layer on top of C. Thus, even though C++ programmers benefit from the famed “pillars of OOP” (encapsulation, inheritance, and polymorphism), they are still at the mercy of the painful aspects of the C language (e.g., manual memory management, ugly pointer arithmetic, and ugly syntactical constructs).
Despite its complexity, many C++ frameworks exist today. For example, the Microsoft Foundation Classes (MFC) provide the developer with a set of C++ classes that facilitate the construction of Win32 applications. The main role of MFC is to wrap a “sane subset” of the raw Win32 API behind a number of classes, magic macros, and numerous code-generation tools (a.k.a. wizards). Regardless of the helpful assistance offered by the MFC framework (as well as many other C++-based windowing toolkits), the fact of the matter is that C++ programming remains a difficult and error-prone experience, given its historical roots in C.
Source : Pro C# 2008 and the .NET 3.5 Platform - Andrew Troelsen