Archive for the ‘Database Administrator’ Category

Sometimes it’s happened, a developer try to access a database but he/she could not get succeed and after few R&D he/she came to know that he/she has no access right for that particular DB. For same, a very useful SQL Server’s function HAS_DBACCESS can be used to get the list of all Databases having access details of currently logged user. Here is a simple script to get the details as

Select Namecase HAS_DBACCESS(namewhen 0 then ‘No Access’ else ‘Access’end AS DB_Access_Status from sys.databases

Note : if any Database is in RECOVERY Mode, it will shows as NO Access for that DB.

Hi Guys,

After a little bit long time I am back on my blog, Here is my observation towards many Developers and DBA, in SSMS(SQL Server Management Studio) if they are working with multiple servers sometimes they got confused , on which server they are running particular query/queries, for this, SSMS provide a very attractive features where we can easily identified servers using setting of server’s color, Commonly Developer or DBA registered servers in SSMS as per their day to day regular work which frequently use or directly provide server name/IP then user name/password to connect any particular server.

A) In case of registering server we can set color as

1) Click on Your Server Groupà New Server Registration…

2) In New Server Registration… à Click on Connection Properties à Check on Use Custom Color and Select your desire color.

B) In case of, connecting any server directly

1)Click on Connect Server

2) Click on Options à Click on Connection Properties à Check on Use Custom Color and Select your desire color.

Now, when you will connect your server, its Query window’s Status bar color will be as your selected color, and you can easily identifies your server when you are working on multiple server and frequently changing query windows.

SSMS has a lot of customization features. By default when we copy query result it’s not include columns header. To enable this feature, just set the SSMS setting as

  1. From Tools menu, select “Options…”
  2. From left, Select “Query Results” and expand it
  3. Select “SQL Server” and Click on “Result to Grid”
  4. Now from right, Click on “Include columns header when copying or saving results”

Yesterday my one team guy came to me with an error as

SPID:         XX
Process ID:   XXXX
Msg 3624, Level 20, State 1, Line 1
A system assertion check has failed. Check the SQL Server error log for details. Typically, an assertion failure is caused by a software bug or data corruption. To check for database corruption, consider running DBCC CHECKDB. If you agreed to send dumps to Microsoft during setup, a mini dump will be sent to Microsoft. An update might be available from Microsoft in the latest Service Pack or in a QFE from Technical Support.

When we checked DBCC CHECKDB, results were as
DBCC CHECKDB WITH NO_INFOMSGS – reported no problems.
DBCC CHECKDB, report 0 errors, 0 consistency errors.

After analyzing queries which he was using, we came to know there was 4-5 joins were used and in two tables a comparing columns was different data types as INT and BIGINT. After changing INT to BIGINT our problem got resolved.

2012 in review

Posted: December 31, 2012 by Virendra Yaduvanshi in Database Administrator

The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.

Here’s an excerpt:

600 people reached the top of Mt. Everest in 2012. This blog got about 2,100 views in 2012. If every person who reached the top of Mt. Everest viewed this blog, it would have taken 4 years to get that many views.

Click here to see the complete report.

As per my personal observation/suggestion, Its much better reinstall server again with new name and then detached DBs from OLD instance and Attach with NEW Instance, because a instance name is associated so many things like performance counters, local groups for service start and file ACLs, service names for SQL and related (agent, full text) services, SQL browser visibility, service master key encryption, various full-text settings, registry keys, ‘local’ linked server etc. Although, we can change Name as following the below steps,

— For default instance

sp_dropserver ‘old_name’
go

sp_addserver ‘new_name’,‘local’
go

— For named instance

sp_dropserver ‘Server Name\old_Instance_name’
go

sp_addserver ‘ServerName\New Instance Name’,‘local’
go

Verify sql server instance configuration by running below queries

sp_helpserver

Select @@SERVERNAME

and then restarted the SQL server with following command at command prompt J

net stop MSSQLServerServiceName
net start MSSQLServerServiceName

Here is a script from which we can easily find the Spaceused on MDF and LDF files.

Select DB_NAME() as [DATABASE NAME],
       fileid 
as FILEID,
       CASE WHEN groupid = 0 then ‘LOG FILE’ else ‘DATA FILE’ END as FILE_TYPE,
       Name as PHYSICAL_NAME,
       Filename as PHYSICAL_PATH,
       Convert(int,round((sysfiles.size*1.000)/128.000,0)) 
as FILE_SIZE,
       Convert(int,round(fileproperty(sysfiles.name,‘SpaceUsed’)/128.000,0)) as SPACE_USED,
       Convert(int,round((sysfiles.sizefileproperty(sysfiles.name,‘SpaceUsed’))/128.000,0)) as SPACE_LEFT
From 
sysfiles;

In case of following

  • Adding a new column to the middle of the table
  • Dropping a column
  • Changing column nullability
  • Changing the order of the columns
  • Changing the data type of a column

SSMS’s table designer may throw following error,

Saving changes is not permitted. The changes that you have made require the following tables to be dropped and re-created. You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created.

This message problem occurs when the Prevent saving changes that require the table re-creation option is enabled, to resolve this, follow the steps as

Click the Tools menu, click Options, expand Designers, and then click Table and Database Designers. Select or clear the Prevent saving changes that require the table to be re-created check box.

122612_2258_SSMSErrorSa1.png

Its general understanding that @@SERVERNAME and SERVERPROPERTY(‘SERVERNAME’) will return same values. But once I get a different values for both means both

Select @@SERVERNAME
Select 
SERVERPROPERTY(‘SERVERNAME’)
were returning different name, 
I got answer @ BOL as 

@@SERVERNAME function and the SERVERNAME property of SERVERPROPERTY function may return strings with similar formats, the information can be different. The SERVERNAME property automatically reports changes in the network name of the computer.In contrast, @@SERVERNAME does not report such changes. @@SERVERNAME reports changes made to the local server name using the sp_addserver or sp_dropserver stored procedure.

To resolve the issue, Just follow below steps,

— To see Servername

sp_helpserver

— Removes server from the list of known servers on the local instance of SQL Server.

sp_dropserver ‘WRON_SERVER_NAME’null

— Add server to the local instance of SQL Server.

sp_addserver ‘REAL_SERVER_NAME’,‘LOCAL’