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:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg

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 :)

SQL

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…!!! :)

SQL Server

Check foreign key constraints in SQL Server Database

While searching for how to find Primary Key and Foreign Key relationship using INFORMATION_SCHEMA in SQL Server Database, I came across following query which works for me.

SELECT RC.CONSTRAINT_NAME AS ‘FK_Name’
,KF.TABLE_SCHEMA AS ‘FK_Schema’
,KF.TABLE_NAME AS ‘FK_Table’
,KF.COLUMN_NAME AS ‘FK_Column’
,RC.UNIQUE_CONSTRAINT_NAME AS ‘PK_Name’
,KP.TABLE_SCHEMA AS ‘PK_Schema’
,KP.TABLE_NAME AS ‘PK_Table’
,KP.COLUMN_NAME AS ‘PK_Column’
,RC.MATCH_OPTION AS ‘MatchOption’
,RC.UPDATE_RULE AS ‘UpdateRule’
,RC.DELETE_RULE AS ‘DeleteRule’
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC
JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KF ON RC.CONSTRAINT_NAME = KF.CONSTRAINT_NAME
JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KP ON RC.UNIQUE_CONSTRAINT_NAME = KP.CONSTRAINT_NAME
WHERE KF.COLUMN_NAME LIKE ‘%<Column Name>%’


You can also find Foreign Key using EXEC sp_fkeys ‘<TABLE NAME>’


Happy Coding :)

To get the next identity value from SQL Server

If you have table with no. of rows and you want to find out next id, following query can be used to identify:

SELECT IDENT_CURRENT(‘<Table Name>’) + IDENT_INCR(‘<Table Name>’)

You cannot reliably find out the next identity value – until you’ve actually inserted a new row into the table.

From the IDENT_CURRENT documentation:

When the IDENT_CURRENT value is NULL (because the table has never contained rows or has been truncated), the IDENT_CURRENT function returns the seed value.

Happy Coding :)

SQL

Rename SQL Table

You can rename a table in SQL Server in following way:

sp_rename OLD_TABLE_NAME, NEW_TABLE_NAME

You must require alteration permission.

Renaming table will not rename stored procedures user-defined functions or programs refer to that table. You must manually modify all object which refer renamed table.

Note: Think twice before you rename a table. If existing stored procedures user-defined functions or programs refer to that table, the name modification will give you an error.