SQL SERVER – Cursor, Log File and More – Memory Lane #004

SQL
1 Comment

SQL SERVER - Cursor, Log File and More - Memory Lane #004 memorylane This is the 4th episode of memory lane. Here is the list of selected articles of SQLAuthority.com across all these years. Instead of just listing all the articles I have selected a few of my most favorite articles and have listed them here with additional notes below it. My favorite article this week is an article discussing cursor and log file. Let me know which one of the following is your favorite article from memory lane.


2006

Auto Generate Script to Delete Deprecated Fields in Current Database
In early career everytime I have to drop a column, I had hard time doing it because I was scared what if that column was needed somewhere in the code. Due to this fear I never dropped any column. I just renamed the column. If the column which I renamed was needed afterwards it was very easy to rename it back again. However, it is not recommended to keep the deleted column renamed in the database. At every interval I used to drop the columns which was prefixed with specific word. This script is 6 years old but still works. Give it a look, I am open for improvements.

2007

Shrinking Truncate Log File – Log Full – Part 2
Shrinking database or mdf file is indeed bad thing and it creates lots of problems. However, once in a while there is legit requirement to shrink the log file – a very rare one. In the rare occasion shrinking or truncating the log file may be the only solution. However, one should make sure to take backup before and after the truncate or shrink as in case of a disaster they can be very useful. Remember that truncating log file will break the log chain and while restore it can create major issue. Anyway, use this feature with caution.

2008

Simple Use of Cursor to Print All Stored Procedures of Database Including Schema
This is a very interesting requirement I used to face in my early career days, I needed to print all the Stored procedures of my database. Interesting enough I had written a cursor to do so. Today when I look back at this stored procedure, I believe there will be a much cleaner way to do the same task, however, I still use this SP quite often when I have to document all the stored procedures of my database.

Interesting Observation about Order of Resultset without ORDER BY
In industry many developers avoid using ORDER BY clause to display the result in particular order thinking that Index is enforcing the order. In this interesting example, I demonstrate that without using ORDER BY, same table and similar query can return different results. Query optimizer always returns results using any method which is optimized for performance. The learning is There is no order unless ORDER BY is used.

2009

Size of Index Table – A Puzzle to Find Index Size for Each Index on Table
I asked this puzzle earlier where I asked how to find the Index size for each of the tables. The puzzle was very well received and lots of interesting answers were received. To answer this question I have written following blog posts. I suggest this weekend you try to solve this problem and see if you can come up with a better solution. If not, well here are the solutions.

Solution 1 | Solution 2 | Solution 3

Understanding Table Hints with Examples
Hints are options and strong suggestions specified for enforcement by the SQL Server query processor on DML statements. The hints override any execution plan the query optimizer might select for a query. The SQL Server Query optimizer is a very smart tool and it makes a better selection of execution plan. Suggesting hints to the Query Optimizer should be attempted when absolutely necessary and by experienced developers who know exactly what they are doing (or in development as a way to experiment and learn).

Interesting Observation – TOP 100 PERCENT and ORDER BY
I have seen developers and DBAs using TOP very causally when they have to use the ORDER BY clause. Theoretically, there is no need of ORDER BY in the view at all. All the ordering should be done outside the view and view should just have the SELECT statement in it. It was quite common that to save this extra typing by including ordering inside of the view. At several instances developers want a complete resultset and for the same they include TOP 100 PERCENT along with ORDER BY, assuming that this will simulate the SELECT statement with ORDER BY.

2010

SQLPASS Nov 8-11, 2010-Seattle – An Alternative Look at Experience
In year 2010 I attended most prestigious SQL Server event SQLPASS between Nov 8-11, 2010 at Seattle. I have only one expression for the event – Best Summit Ever. Instead of writing about my usual routine or the event, I wrote about the interesting things I did and how I felt about it! When I go back and read it, I feel that this is the best event I attended in year 2010.

Change Database Access to Single User Mode Using SSMS
Image says all.

SQL SERVER - Cursor, Log File and More - Memory Lane #004 singleuser1

2011

SQL Server 2012 has introduced new analytic functions. These functions were long awaited and I am glad that they are now here. Before when any of this function was needed, people used to write long T-SQL code to simulate these functions. But now there’s no need of doing so. Having available native function also helps performance as well readability.

FunctionSQLAuthorityMSDN
CUME_DISTCUME_DISTCUME_DIST
FIRST_VALUEFIRST_VALUEFIRST_VALUE
LAST_VALUELAST_VALUELAST_VALUE
LEADLEADLEAD
LAGLAGLAG
PERCENTILE_CONTPERCENTILE_CONTPERCENTILE_CONT
PERCENTILE_DISCPERCENTILE_DISCPERCENTILE_DISC
PERCENT_RANKPERCENT_RANKPERCENT_RANK

Reference: Pinal Dave (https://blog.sqlauthority.com)

 

,
Previous Post
SQLAuthority News – Android Efficiency Tips and Tricks – Personal Technology Tip
Next Post
SQL SERVER – Sends backups to a Network Folder, FTP Server, Dropbox, Google Drive or Amazon S3

Related Posts

Leave a Reply

Menu