Wednesday, November 27, 2013

Quick check : What is running on my server at the moment

You can quickly run SP_Who2 to see what is running on your server at the moment. Of course it will give you  current transactions and pending (currently processing) transactions also called as open transactions.

If you use SP_Who2 Active, you will just get Current transactions.

Apart from these commands you can get interesting information with dmv's, introduced in sql 2005 and also applicable for later versions of 2005.

DECLARE @TimeStamp DATETIME
SET @TimeStamp = DATEADD(MINUTE,-10,getdate())  -- You can pass your own string here

SELECT login_time
        ,last_request_start_time
        ,last_request_end_time
        ,DATEDIFF(millisecond,last_request_start_time,last_request_end_time) AS 'Milli'  -- Dynamic column
        ,host_name
        ,PROGRAM_NAME
        ,host_process_id
        ,client_interface_name
        ,login_name
        ,nt_user_name
        ,total_scheduled_time
        ,total_elapsed_time
        ,reads
        ,writes
        ,logical_reads
        ,original_login_name
    FROM sys.dm_exec_sessions WHERE
    last_request_end_time > @timeStamp
    ORDER BY login_time

SQL Server Versions History

The glance you can find the version history of the sql server as released...
Version Year Release Name Codename
1.0
(OS/2)
1989 SQL Server 1.0
(16 bit)
-
1.1
(OS/2)
1991 SQL Server 1.1
(16 bit)
-
4.21
(WinNT)
1993 SQL Server 4.21 SQLNT
6.0 1995 SQL Server 6.0 SQL95
6.5 1996 SQL Server 6.5 Hydra
7.0 1998 SQL Server 7.0 Sphinx
- 1999 SQL Server 7.0
OLAP Tools
Palato mania
8.0 2000 SQL Server 2000 Shiloh
8.0 2003 SQL Server 2000
64-bit Edition
Liberty
9.0 2005 SQL Server 2005 Yukon
10.0 2008 SQL Server 2008 Katmai
10.25 2010 SQL Azure DB CloudDatabase
10.5 2010 SQL Server 2008 R2 Kilimanjaro (aka KJ)
11.0 2012 SQL Server 2012 Denali
12.0 2014 SQL Server 2014 Not Named Yet.....

Do you know this? (Smallest VLF in size) / (Minimum Size of Transactional Log)

VLF: Virtual Log File.

The smallest size of VLF is 256 KB.

The minimum size of the transactional log 512KB.

 Please check at My Previous VLF related Post to know little more about VLF's.

Thursday, November 21, 2013

How to find Foreign Keys from the database

--      Find all Foreign key on the database with TableName and Referenced TableName
  
    SELECT Name AS ForeignKeyName, OBJECT_NAME(parent_object_id) AS BaseTableName,
            OBJECT_NAME(referenced_object_id) AS ReferecedTableName --, *
    FROM sys.foreign_keys order by BaseTableName

--     TableName And Number of Foreign keys on each table on the database.
    SELECT OBJECT_NAME(parent_object_id) AS TableName ,COUNT(*) AS foreingKey_Count
    FROM sys.foreign_keys
    GROUP BY OBJECT_NAME(parent_object_id)
    ORDER BY TableName

Monday, November 4, 2013

Orphans users


> Find list of the Orphans in the database

                                    sp_change_users_login 'report'

> Fix them Automatically in real fast :)

                                    sp_change_users_login 'auto_fix','loginName'
If it still not fix yet, the following may helpful..

> You can create newLogin same as the 'OrphonUser' which by running the report..Then run the following
                                    exec sp_change_users_login 'update_one' , 'OrphonUser', 'NewLogin';