The query to find who created or dropped or altered object in database – SQL

— read all available traces.

DECLARE @current VARCHAR(500);

DECLARE @start VARCHAR(500);


SELECT @current = path

FROM sys.traces

WHERE is_default = 1;

SET @current = REVERSE(@current)

SELECT @indx = PATINDEX(‘%\%’, @current)

SET @current = REVERSE(@current)

SET @start = LEFT(@current, LEN(@current) – @indx) + ‘\log.trc’;




THEN ‘Object:Created’


THEN ‘Object:Deleted’

WHEN 164

THEN ‘Object:Altered’








FROM::fn_trace_gettable(@start, DEFAULT)

WHERE EventClass IN (





AND EventSubclass = 0

AND DatabaseID <> 2


Reference:- http://goo.gl/JHLVLo

Happy Querying :)


Increment a value in the SET clause of an UPDATE Statement in SQL

I was working on a task in which I have to add one new column in my existing table and set its value given by the client which is incremental value to previous records.

For e.g.

Id         fname              lname               No

1          user 1              user 1              5

2          user 1              user 1              6

3          user 1              user 1              7

I was looking for some solution and ended up with following solution which works well for me.

-- Create Table
CREATE TABLE usermaster (
fname VARCHAR(20)
,lname VARCHAR(20)
-- Insert 100 Records
INSERT usermaster
'user fname'
,'user lname'
) GO 100 -- You can specify any no. of records
-- Add one more column called id using ALTER statement
ALTER TABLE usermaster ADD id INT
-- Update Id column with Increment value
SET @id = 0 -- you can specify any no. I set it 0 so it start with 1.
UPDATE usermaster
SET @id = id = @id + 1
-- check updated table records
FROM usermaster

Happy Querying :)

Microsoft Introduce ASP.Net WebHooks

Microsoft Introduce ASP.Net WebHooks. In the MSDN blog article you will get an overview of how to work with Microsoft ASP.NET WebHooks. Microsoft ASP.Net Webhooks make it easy to send and receive webhooks from web application.

MSDN Blog:

Introducing Microsoft ASP.NET WebHooks Preview

Sending WebHooks with ASP.NET WebHooks Preview

Happy Coding :)

Using Youtube Thumbnails on your Websites

YouTube takes screenshots of the videos you upload. Here is a quick reference of how you do this on your webpage. Each YouTube video has 4 generated images. The first is a full size cover image and the rest are thumbnail images:

480×360: http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg

120×90: http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg

120×90: http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg

120×90: http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg

The default thumbnail image (i.e. one of 0.jpg, 1.jpg, 2.jpg, 3.jpg) is:

120×90: http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg

For the high quality version and medium quality version of the thumbnail:

480×360: http://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg

320×180: http://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg

For the maximum resolution version of the thumbnail, the size depends on the video quality:


All of the above urls are available over https too. Just change http to https in any of the above urls.

Alternatively, you can use the YouTube API to get thumbnail images.

Happy Coding :)


SSMS Tip: What happened to my keyboard shortcuts? Ctrl+R (Show/Hide Result)

Ctrl+R is a good friend of mine. It is very handy to use this command not only to hide the results pane away and focus on the query, but to also be able to bring the results back just as quickly – without having to run the query again

In SSMS 2014 when I press Ctrl+R to show/hide my result pane, I was getting below message in the left bottom of SSMS.

“(Ctrl+R) was pressed. Waiting for second key of chord…”

Pressing Ctrl+R again I get message as “The key combination (Ctrl+R, Ctrl+R) is not a command”

Here is what I did to make my shortcut work again.

  1. Go to Tools Menu in SSSMS
  2. Click on Option
  3. Go to Keyboard and expand the menu
  4. Click on option Keyboard again
  5. Enter “Window.ShowResultsPane” in Show commands containing: search box
  6. Select “Window.ShowResultsPane”
  7. Change the “Use new shortcut in:” dropdown to “SQL Query Editor“
  8. Put your cursor in the “Press shortcut keys:” box and hit Ctrl+R
  9. Click on “Assign” button before hitting OK

Unlike some other changes that still require an SQL Management Studio restart to take effect, the change takes effect immediately, and CTRL + R should start working again.

Hope this helps! Please write comment and let me know your feedback.

Happy Coding…!!! :)