FAQ about Dates in SQL Server

December 22, 2016 by

Introduction In this article, I compiled a list of FAQs and Answers about dates. Which function should I use to get the current date in SQL Server? How can I get the current time in the format hh:mm:ss? How can I calculate my age in SQL Server with a birth date? How can I insert […]

Why is my CTE so slow?

December 22, 2016 by

Introduction Have you ever written up a complex query using Common Table Expressions (CTEs) only to be disappointed by the performance? Have you been blaming the CTE? This article looks at that problem to show that it is a little deeper than a particular syntax choice and offers some tips on how to improve performance.

SQL Server performance myth busters

December 21, 2016 by

Introduction In this article, we will verify if the following statements are true or they are just myths: Truncate is faster than a delete and it consumes less space in the logs Do not use cursors to Create or drop multiple objects because it is very slow Do not use cursors to convert or process […]

Creating a “smart” trigger based audit trail for SQL Server

December 12, 2016 by

Introduction Audit tables are used to track transactions for a particular table or tables. For every important transaction table, it’s important to create an audit table. Auditing can be helpful if you need to track who is Inserting/Updating and Deleting data on a sensitive table and/or view before and after data change information.

Understanding the SQL Server Proportional fill algorithm

November 22, 2016 by

When creating a database, SQL Server maps this database with minimum two operating system files; the database data file MDF and the database log file LDF. Logically, the database data files are created under a collection set of files that simplifies the database administration, this logical file container is called the Filegroup. Database data files […]

3 ways to improve T-SQL performance

November 22, 2016 by

Introduction When customers used to ask for advice to solve some T-SQL Problem, they would show me their scripts, stored procedures and cursors. I saw horrible things doing that job, some things I do not want to remember, and even some I cannot tell you about 😉 In this article, we will talk about performance […]

PowerShell: Get a daily database status email

November 22, 2016 by

The need for this script came about when I took a new job as a DBA. One of my responsibilities was to make sure all databases were available after the maintenance window which ran during the weekend. Rather than log into each database server and check that the databases were online, I had a script […]

SQL Server Partitioned Views

November 18, 2016 by

SQL Server table partitioning is a great feature that can be used to split large tables into multiple smaller tables, transparently. It allows you to store your data in many filegroups and keep the database files in different disk drives, with the ability to move the data in and out the partitioned tables easily. A […]

How to create and manage T-SQL code snippets

October 28, 2016 by

Introduction Transact-SQL (T-SQL) snippets were first introduced in SQL Server 2012 Management Studio. T-SQL snippets are templates containing one or more T-SQL statements which you can easily use them when you develop T-SQL scripts. The main concept behind code snippets is code reuse. With code reuse you develop faster, easier and with less syntax errors. […]