SQL SERVER DBA, Linux and Azure

How to display execution plans present in procedure cache in SQL Server

SELECT cp.objtype AS PlanType,
       OBJECT_NAME(st.objectid,st.dbid) AS ObjectName,
       cp.refcounts AS ReferenceCounts,cp.usecounts AS UseCounts,
       st.text AS SQLBatch,qp.query_plan AS QueryPlan
    FROM sys.dm_exec_cached_plans AS cp
    CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) AS qp
    CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) AS st;

    GO

How to get the complete backups information of a particular database in SQL Server

SELECT s.database_name,
m.physical_device_name,
cast(s.backup_size/1000000 as varchar(14))+' '+'MB' as bkSize,
CAST (DATEDIFF(second,s.backup_start_date , s.backup_finish_date)AS VARCHAR(4))+' '+'Seconds' TimeTaken,
s.backup_start_date,
CASE s.[type]
WHEN 'D' THEN 'Full'
WHEN 'I' THEN 'Differential'
WHEN 'L' THEN 'Transaction Log'
END as BackupType,
s.server_name, s.recovery_model
FROM msdb.dbo.backupset s
inner join msdb.dbo.backupmediafamily m
ON s.media_set_id = m.media_set_id
WHERE s.database_name = 'AdventureWorks' -- Need to change the database name
ORDER BY database_name, backup_start_date, backup_finish_date

Dump a specific table or few rows in MySQL Server

The 'mysqldump' command is used to dump databases managed by MySQL. Let's consider three the most useful cases of MySQL database dumping.

The simplest case is the whole database dumping:

mysqldump -u username -ppassword database_name  > the_whole_database_dump.sql

Sometimes, there's a need to dump a single table from your database. You can do it in the next way:

mysqldump -u username -ppassword database_name table_name > single_table_dump.sql

You can also specify several tables separated by whitespace to dump these tables only.

If you want to dump only rows that meet a specific criteria, you can add 'where' option to your mysqldump command. For example, dump only rows where date_created is today:

mysqldump -u username -ppassword database_name table_name --where="date_created='2013-06-25'" > few_rows_dump.sql


                                                                                             

                                                                                                                 Prepared by Ajeyudu Bandaru