Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Vivek's SQL Notes

Vivek johari is currently a Analyst and have more that 5.5 yeras of experience in database. He has Master degree in Computer and also he is Microsoft certified Sql DBA (MCTS)& Microsoft certified SQl BI professional(MCTS). He is also Oracle certified profession(OCP)DBA in ORACLE 10g and ORACLE 9i.He has the experience of working in PL/SQL, T-SQL and SSIS/SSRS. His work basically involved designing and optimization of the Database.He has also published many database articles on his blog Technologies with Vivek Johari.

SQL Script to find the list of all the jobs failed yesterday

One of the important task of any DBA is to find out all the jobs which are failed yesterday. Below SQL Script can be used to find out all the jobs which are failed yesterday.

SELECT DISTINCT
CAST(CONVERT(datetime,CAST(run_date AS char(8)),101) AS char(11)) AS 'Failure Date',
SUBSTRING(T2.name,1,40) AS 'Job Name',
T1.step_id…

Read more

0 comments, 1,016 reads

Posted in Vivek's SQL Notes on 20 January 2015

SQL Script to search stored procedures containing a given text

Sometimes we need to find out how many stored procedures contains a given text. Below SQL query can be used to find out the list of all the stored procedures which contains a  particular given text as input.

SELECT OBJECT_NAME(object_id), OBJECT_DEFINITION(object_id)
FROM sys.procedures
WHERE OBJECT_DEFINITION(object_id) LIKE '%Given text%'

Read more

0 comments, 91 reads

Posted in Vivek's SQL Notes on 20 January 2015

SQL Script to find the tables created from a given date

Below is the SQL query which can be used to find out the tables which are created or modified on or from a given date.

SELECT
        [name] as Tablename
       ,create_date
       ,modify_date
FROM
        sys.tables where cast(create_date as…

Read more

0 comments, 161 reads

Posted in Vivek's SQL Notes on 20 January 2015

SQL Script to find the databases size

Sometimes we need to find out the size of the database on a server. Below SQL Scripts can be used to find out the size of all the databases created on the server. 

;WITH DBSize (SqlServerInstanceName, DatabaseName, DatabaseSize, DBLogSize, TotalDBSize)
AS
(
  SELECT      @@SERVERNAME SqlServerInstanceName,
 …

Read more

0 comments, 83 reads

Posted in Vivek's SQL Notes on 20 January 2015

T-SQL script to find the growth size of database files

Below query can be used to see the growth size of database files.

DECLARE @filename NVARCHAR(1000);
DECLARE @bc INT;
DECLARE @ec INT;
DECLARE @bfn VARCHAR(1000);
DECLARE @efn VARCHAR(10);

-- Get the name of the current default trace
SELECT @filename = CAST(value AS NVARCHAR(1000))
FROM ::fn_trace_getinfo(DEFAULT)
WHERE traceid = 1 AND…

Read more

0 comments, 209 reads

Posted in Vivek's SQL Notes on 9 January 2015

T-SQL script to find the highly populated tables in database

Sometimes we need to check which tables of our database is highly populated. Below is the T-SQL Script which we can use to find out that.

SELECT 
    t.NAME AS TableName,
    i.name as indexName,
    sum(p.rows) as RowCounts,
    sum(a.total_pages) as TotalPages, 
    sum(a.used_pages)…

Read more

0 comments, 196 reads

Posted in Vivek's SQL Notes on 9 January 2015

SQL Script to find the last executed commands on the SQl Server

Sometimes we needs to find out the last executed commands on the database server. 
Below is the SQL script share by one of my friend Ken Watson to find out the last executed queries.

SELECT usecounts, cacheobjtype, objtype, text 
FROM sys.dm_exec_cached_plans 
CROSS APPLY sys.dm_exec_sql_text(plan_handle) 
WHERE usecounts > 1 
ORDER BY…

Read more

0 comments, 200 reads

Posted in Vivek's SQL Notes on 8 January 2015

Script to find the Fragmentation of indexes

Below is the script to find the fragmentation of the indexes created on a database.


SELECT OBJECT_NAME(OBJECT_ID), index_id,index_type_desc,index_level,
avg_fragmentation_in_percent,avg_page_space_used_in_percent,page_count
FROM sys.dm_db_index_physical_stats (DB_ID( N'Database name') , NULL, NULL, NULL , 'SAMPLED') ORDER BY avg_fragmentation_in_percent DESC

avg_fragmentation_in_percent represents  logical fragmentation.

If this value is higher than 5% and less than 30%,…

Read more

3 comments, 5,470 reads

Posted in Vivek's SQL Notes on 4 January 2015

Script to find all the running queries/jobs on the Database Server

Below is the query to find out all the Queries and their details like SSID etc. running on the SQL Server from all databases. It helps in finding out which queries/jobs running on the server. It can be helpful in detecting the blocking queries also.


USE Master
SET NOCOUNT ON…

Read more

0 comments, 182 reads

Posted in Vivek's SQL Notes on 4 January 2015

How to pass Microsoft Certification Exams

Many times I was asked how to pass Microsoft certifications and how difficult it is. In my point of view, it simple to crack Microsoft certification exams if you have worked hard on basic concepts and implemented most of the questions and scenarios mention in your study books/blogs on your…

Read more

0 comments, 239 reads

Posted in Vivek's SQL Notes on 3 January 2015

Interview questions for database developer

Technical Round Database Interview Questions

1) What are the different types of Trace flags which we used for detecting the Deadlock?
2) What are the different types of database backups?
3) How do you perform the Error handling in SQL Server?
4) What is the ACID property in SQL Server?

Read more

2 comments, 334 reads

Posted in Vivek's SQL Notes on 3 November 2014

My Best Technical Sites and Blogs

Many times my friends ask me which technical sites they should refers for finding the solutions, so below is the list of tech sites which I used to refer most of the times for learning technologies and finding the solutions

Mssqltips.com:- I like this site because I find here…

Read more

0 comments, 567 reads

Posted in Vivek's SQL Notes on 12 October 2014

SQLTea - New SQL tutorial app in Google play store

SQLTea - Our new SQL Tutorial App on Google Play Store
 
We are happy to announce our new SQL tutorial app SQLTea  ( Native android app) for SQL learning which includes articles from this blog.


This application includes 

1) Articles for basic concepts like Normalization, Constrains, Joins, SQL Functions,…

Read more

6 comments, 814 reads

Posted in Vivek's SQL Notes on 18 August 2014

How to restore database backup in SQL SERVER

In this article, I am going to explain the process of  Database restoration using the SQL Server Management Studio. In this article, I will try to explain this process in a simple way so that a database developer having little knowledge of DBA can restore that database using the database…

Read more

0 comments, 218 reads

Posted in Vivek's SQL Notes on 17 August 2014

How to take Database backup in SQL SERVER

This article explain the simple way to take up the backup of a database which can be easily understandable by the database programmer having little knowledge of DBA. For taking the database backup, we need to follow the given step.

Step 1:- Open the SQL Sever Management Studio. For this…

Read more

0 comments, 158 reads

Posted in Vivek's SQL Notes on 17 August 2014

Database Creation using SQL Sever Management Studio (SSMS)

In the previous article (Database Creation using Create Database command), I explained the database creation using the Create database command. In this article, I am going to explain the steps of creation a database using SQL Sever Management Studio (SSMS) using SQL Server 2008 R2. These below database creation…

Read more

0 comments, 277 reads

Posted in Vivek's SQL Notes on 17 August 2014

Database Creation using Create Database command

In SQL Server, database can be created by 2 ways:-
  1.  Using Create Database command
  2.  Using SQL Sever Management Studio (SSMS).

In this article, I am going to explain the database creation using the command CREATE DATABASE.

Syntax for creating a database through Create database command is given below:-

CREATE DATABASE…

Read more

0 comments, 6,689 reads

Posted in Vivek's SQL Notes on 17 August 2014

IN clause in SQL Server

With IN clause, we can specify multiple values in a WHERE clause.

For example, in case of "IN", one can use the subquery to get the multiple values in the IN clause or we can have predefined values.


In this article, we are going to use the following table for…

Read more

0 comments, 332 reads

Posted in Vivek's SQL Notes on 14 August 2014

UPPER() function in SQL Server

UPPER():- This function is used to convert the value of a column to upper case.

 Syntax:

   SELECT UPPER(string)

OR

Select UPPER(Column name) from tablename

For example,

  SELECT UPPER('Vivek')

Result:


   VIVEK



Read more

0 comments, 484 reads

Posted in Vivek's SQL Notes on 14 August 2014

Older posts