Sunday 11 May 2014

How to troubleshoot when all Login Removed No Admin Rights

No Admin right for User and sa is disable
1) sa is disable
2) Windows user [Domainname\ashish.malwal] don’t have access to create any table or database it has public role.














How to get backup sys admin right and how to give sys admin right to user?
Steps:-

1.       net stop "SQL Server (MSSQLSERVER)"
2.       net start "SQL Server (MSSQLSERVER)" /m  ---single user mode
1.       sp_addsrvrolemember [Domainname\ashish.malwal],sysadmin ----Give sys admin right existing user
2.       alter login sa enable ---enable sa  login if disable




Now check SSMS and try to create table:-




Sunday 4 May 2014

Get MDF and LDF File Statistics Using fn_virtualfilestats


You can get what is the size of the file as well how many times the reads and writes are done for each file. It also displays the read/write data in bytes with the following script.

SELECT DB_NAME(vfs.DbId) DatabaseName,
       mf.name,
       mf.physical_name,
       vfs.BytesRead,
       vfs.BytesWritten,
       vfs.IoStallMS,
       vfs.IoStallReadMS,
       vfs.IoStallWriteMS,
       vfs.NumberReads,
       vfs.NumberWrites,
       (cast(SIZE AS bigint)*8)/1024 Size_MB
FROM ::fn_virtualfilestats(NULL,NULL) vfs
INNER JOIN sys.master_files mf ON mf.database_id = vfs.DbId
AND mf.FILE_ID = vfs.FileId