Author Archives: vivekjohari

About vivekjohari

Database Consultant with more than 11.5 years of experience in database designing & programming and DBA related activities.  Had good experience on different databases like SQL Server, MySQL & Oracle, Azure SQL &  Big Data.

SQL Script to find the database & their files details on a SQL Server

By | March 30, 2018

SQL Script to find database details Sometimes we need a SQL Script which can give the below information about the databases created on a SQL Server for house keeping purpose: -1) Database Name 2) Database ID 3) Database Files name with their physical location 4) Database Creation Time 5) Users access type for Database 6)… Read More »

SQL Script: – How to find the database restoring history of SQL Server databases

By | March 30, 2018

SQL Script to find database restoring history Sometime we need to find out the history of database restoration to get the answers of following questions: -1) Do we need to restore the database again as there is a possibility that it is restored recently? 2) Which backup file (with location information) is used for database restoration?… Read More »

SQL Script: – How to find the last access date of a database

By | March 29, 2018

SQL Script to find database last access date Sometime we create databases on Test/ Development database servers for temporary uses for short duration and  forgot to delete them after the work got completed. As a part of house keeping activity, we need to find out when a database is last accessed in order to find… Read More »

SQL Script to find all the triggers defined on a database or on a single table

By | August 14, 2015

SQL Script to find triggers in SQL Database Sometime we need to find all the triggers defined on the database. So in this case, we can use the below SQL Query:-SELECT tbl.name as [Table Name] , trig.name as [Trigger Name] , trig.is_disabled FROM [sys].[triggers] as trig INNER JOIN sys.tables as tbl ON trig.parent_id = tbl.object_idIn… Read More »

Interview question – Is Clustered index on column with duplicate values possible?

By | August 13, 2015

Through this article, we are going to discuss three important interview questions of SQL which are given below:-  1) Can we create clustered index on a column containing duplicate values?  2) Can we create a Primary Key on a table on which a clustered index is already defined? 3) If a clustered index is already defined on a… Read More »

Question of the Month (July)

By | August 3, 2015

Question of the Month Suppose we have a table emp_plan  which contains 4 columns “Empid” (employeeid), Planid (Projectid), Startdate(Allocation Start date) and Enddate (Allocation Enddate). Its structure is given below:-4  Create table emp_plan (empid nvarchar(200),planid nvarchar(20),startdate datetime, enddate datetime) Also below is the script to enter sample data into the table:- insert into emp_plan(empid,planid,startdate,enddate) select ‘001’,’planA’,’2015-05-15′,’2015-05-30′… Read More »

Do you know about Whatsapp web?

By | July 11, 2015

Whatsapp claims that they currently have 500 million users worldwide. That is pretty impressive looking at the good amount of distinctively decent competitors they have within the space of Social Networking communication. Viber, Line, Google Hangout,Facebook Messenger & Hike (Commonly in India). While all these products are growing inch by inch and including new set of features into their product, whatsapp… Read More »

Script to find complete months between two given dates

By | July 10, 2015

Complete months between two given dates Below script will help in finding the complete months within the 2 given dates. In the below script we takes below dates as exampleStartdate =2015-07-05 Enddate =2016-01-06 /**********************Script Start**************************/ IF (object_id(‘tempdb..#month’) is not null) DROP TABLE #month CREATE TABLE #month (id int identity(1,1),MonthStartDate DATETIME,MonthEndDate DATETIME) DECLARE @startdate AS DATETIME… Read More »

Script to find the complete weeks within two given dates

By | July 10, 2015

Complete weeks within two given dates Sometimes we need to find out the complete weeks within two given dates. Below script will help in finding the complete weeks within 2 given dates. In this script, I have used below dates as exampleStartdate=2015-04-12 Enddate=2015-06-10 SET DATEFORMAT YMD if (object_id(‘tempdb..#weekdays’) is not null) drop table #weekdays Declare… Read More »