Preparing for SQL DBA Interview

Preparing for SQL DBA Interview

Preparing for SQL DBA Interview

This article list out few tips on “Preparing for SQL DBA Interview” If you are reading this article which means you must be a Database Administrator/professional or getting ready for entering into DBA world. In today’s corporate world attending or taking a technical interview is mandatory whether it’s for a new role in current organization, new customer/client or for a new organization. Preparing for SQL DBA Interview is always a challenge. We have randomly chosen SQL Server database professionals from three different experience levels and had a deep discussion on “Preparing for SQL DBA Interview”.

  • Fresher/Junior – Should know the basics of process and technology
  • Mid-Level – Should be able to expertise in one or two areas and know the process
  • Senior Level – Should be expertise in technology and able to drive the process

There are few points everyone should follow to get succeed in an interview. Below are the key points which can be helpful in “Preparing for SQL DBA Interview”

    • Profile

    • Preparation

    • Communication

    • Interview Process

  • Preparing a Topic

Profile

This is the first piece of information that tells about you so please be careful in preparing your profile:

  • Don’t add the generic skill-set: Include only the topics that you are experienced or learned.
  • Add your professional experience, key skills, education details, your achievements, certifications, training and projects.
  • Number of pages should be restricted to 3 or 4.
  • Maintain a profile on professional network like LinkedIn and add a link to your profile (I have seen a lot of opportunities are hitting through professional networks)
  • Remember you should know / learn / prepare / experience each and everything you mentioned in your profile as the interview questions are always depends on summary points that you showcase in your profile.

Continue reading

Posted in Interview Q&A, Miscellaneous, SQL Server DBA | Tagged , , , , , | 18 Comments

Update Without Where Clause

Update Without Where Clause

Update Without Where Clause

Running Update Without Where Clause might causes a data damage when it is with the critical table that creates a lot of problems and escalations. Recently while working with one of the customer we had a situation where a DBA executed the release script on production and the script contains an update statement without where clause. He immediately realized that he executed an update statement without where clause and he reported us explaining the situation. There were few things we found:

  • The change request implemented on a premium database
  • Update statement provided from Pre-Prod team which is not having any control on that:
    No Where clause
    No Transaction control – Commit / Rollback
    No Validation on update – Validating and Reporting
  • As per the business requirement single record should be updated but in real it updates all records in that table.
  • Usually when a DBA implements a CR on prod server a backup or snapshot has to be taken prior to implementing the change. Since it was a small database (6 GB) he did take a full backup before implementing the CR.

Solution we have provided:

Continue reading

Posted in SQL Development, SQL Server DBA | Tagged , , , , , , , , , , , , | Leave a comment

Script to get row count for all tables in a SQL Server database

Script to get row count for all tables in a SQL Server database

Script to get row count for all tables in a SQL Server database

This post helps you in writing a Script to get row count for all tables in a SQL Server database. For any database developer or administrator the most common requirement is to identifying the larger tables based on data size, index size and row count. This script can quickly list out all tables in the given database and retrieves the below details:

  • Name: Table Name
  • Rows: Total row count
  • Reserved: Space reserved for the table – MB
  • Data: Total space allocated for data pages – MB
  • Index_size: Total space allocated for Index pages – MB
  • Unused: Unused space – MB

Here is the script to get row count for all tables in a SQL Server database:

SET NOCOUNT ON;
BEGIN TRY
	--Create a temparory table 
	CREATE TABLE #Tab (
			[Name]		 NVARCHAR(128),    
			[Rows]		 CHAR(11),    
			[Reserved]	 VARCHAR(18),  
			[Data]		 VARCHAR(18),     
			[Index_size] VARCHAR(18),    
			[Unused]	 VARCHAR(18)); 

	--Capture all tables data allocation information 
	INSERT #Tab 
	EXEC sp_msForEachTable 'EXEC sp_spaceused ''?''' ;

	--Alter Rows column datatype to BIGINT to get the result in sorted order
	ALTER TABLE #Tab ALTER COLUMN [ROWS] BIGINT  ;

	-- Get the final result: Remove KB and convert it into MB
	SELECT	Name,
		[Rows],
		CAST(LTRIM(RTRIM(REPLACE(Reserved,'KB',''))) AS BIGINT)/1024.0 AS 'Reserved MB',
		CAST(LTRIM(RTRIM(REPLACE(Data,'KB',''))) AS BIGINT)/1024.0 AS 'Data MB',
		CAST(LTRIM(RTRIM(REPLACE(Index_Size,'KB',''))) AS BIGINT)/1024.0 AS 'Index_Size MB',
		CAST(LTRIM(RTRIM(REPLACE(Unused,'KB',''))) AS BIGINT)/1024.0 AS 'Unused MB'
	FROM #Tab 
	ORDER BY [rows] DESC;

END TRY
BEGIN CATCH
	DROP TABLE #Tab; 
END CATCH
-- Drop the temparory table 
DROP TABLE #Tab; 

When you need to get the list of tables along with the row counts, connect to the database instance open a new query window, paste the above script and execute it. It shouldn’t take much time to execute the script as we are using “sp_spaceused”, for us it took maximum 6 sec on a 3.5 TB database.

Remember there are chances where sp_spaced might give the wrong row counts due to several reasons. There are mainly 3 reasons that cause sp_spaceused gives us the wrong counts:

  • When there are huge DDL changes
  • Statistics are not updated
  • Index maintenance is not being taken care

Here you will find more details and resolution.

Posted in SQL Development, SQL Scripts, SQL Server DBA | Tagged , , , | 5 Comments