Book: SQL Server 2014 Development Essentials

I am very happy to announce that my first book “SQL Server 2014 Development Essentials” has now been published by Packt Publishing.

SQL Server 2014 Development Essentials, ISBN: 9781782172550

SQL Server 2014 Development Essentials, ISBN: 9781782172550

SQL Server 2014 Development Essentials is an easy-to-follow yet comprehensive guide that is full of hands-on examples, which you can follow to successfully design, build, and deploy mission-critical database applications with SQL Server 2014. You can view and download the table of contents, sample chapter, code files and the preface of this title on Packt Publishing website here.

Who this book is for?

If you are a database developer, architect, or administrator who wants to learn how to design, implement, and deliver a successful database solution with SQL Server 2014, then this book is for you. This book will provide you with all the skills you need to successfully create, design, and deploy databases using SQL Server 2014. You will also learn how to add, modify, and delete data stored within a database. You will use Transact-SQL statements to create and manage advanced database objects that include scalar and table-valued functions, views, stored procedures, and triggers. Finally, you will learn about how SQL Server works, how indexes and statistics improve query performance, and the new SQL Server 2014 in-memory technologies.

From this book, you will learn:

  • Get introduced to SQL Server 2014’s new in-memory database engine
  • Understand SQL Server database architecture and relational database design
  • Use joins, subqueries, CTEs, and windowing functions to write advanced Transact-SQL queries
  • Learn about tools that let you monitor SQL Server database performance
  • Identify and troubleshoot blocks or deadlocks that might slow down a system
  • Design, create, and manage advanced database objects that include scalar and table-valued functions, views, stored procedures, and triggers
  • Use SQL Server 2014’s structured error handling blocks to handle errors that occur in the Transact-SQL batches and programmable objects

You can order it at Packt Publishing, Amazon UK, and Barnes & Noble. It will also be available at O’Reilly Media and Safari Books Online.

Please feel free to contact me via twitter (@BasitAali) or via email, if you have any questions or feedback about this book.


Implementing Checkpoints – To restart SQL Server Integration Services packages from the point of failure

An SQL Server Integration Services package often includes tasks that can take a long time to run. If the package fails in the middle of execution, you may need to repeat these tasks, which can be very slow and time-consuming. To address this problem, Integration Services supports the use of checkpoints.

Click here to read full article on

SQL Server 2005/2008/2008R2: HTTP endpoints

You can use an HTTP endpoint to allow access to data over HTTP and Secure Sockets Layer (HTTPS) without needing to install Internet Information Services (IIS).

Important Note: HTTP Endpoints feature has been deprecate in SQL Server 2012 and later versions.  For more information, see here

Click here to read full article on

Types of Join in SQL Server

You use a join to combine data from different tables into a single result set. Joins most commonly use foreign key relationships. Some important points about joins include:

  • Joins are created through instructions in the SELECT clause.
  • Joins connect two or more tables by using a join operator.
  • Joins exist only for the duration of that query.
  • Joins do not make changes to any database tables.

You use the JOIN keyword to specify the tables you want to join and how to join the tables. You use the ON keyword to specify the common columns between the two tables—the columns to use for the join. If the columns have the same names in both tables, you must specify the columns as table

Click here to read full article on

Database capacity planning and management

As part of the planning and research before implementing new SQL Server, you must determine the amount of space needed for your database and how it should be organized in the SQL Server. You also need to understand the properties of the database and how to manage the growth of the database after creating a database.

Click here to read full article on

Configuring SQL Server Database Mail Feature

You can send e-mail from within stored procedures, functions, and triggers by using SQL Server Database Mail. You can also configure SQL Server Agent Mail to use Database Mail. Some features of Database Mail include:

  • Uses Simple Mail Transport Protocol (SMTP)
  • Does not require Outlook or Extended Messaging Application Programming Interface (MAPI) support
  • Can use multiple SMTP servers
  • Can be used in a cluster server configuration
  • Supports asynchronous background delivery
  • Supports multiple profiles and accounts
  • Supports security features, included prohibited file extensions, a limit on attachment size, and auditing
  • Allows you to send messages formatted in HTML

Click here to read full article on

SQL Server 2014 Management tools

Management tools play a vital role in enterprise database management. This is because the well-integrated tools extend the administrator’s capabilities, whereas a random collection of tools can lead to confusion, operational mistakes, high training costs, and poor DBA productivity. To keep up with these demands of complex enterprise database management solutions, SQL Server 2014 includes updated management tools to make it easier for administrators to create, manage, and maintain SQL Server solutions.

Click here to read full article on

The database principal owns a schema in the database, and cannot be dropped


You are trying to drop a database user, but are getting the following error message:

The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)

This error is self-explanatory as it tells you that the database user you are trying to drop is the database schema owner.


To successfully drop the database user, you must find all the schemas that are owned by the database user, and then transfer their ownership to another user.

Here is the Transact-SQL script, which I wrote a while ago, to drop the database user. This script first transfer’s ownership of all database schemas associated with particular database user to the specified database user, and then drops that database user from the database.

To use this script, change the following two local variables of this script:

  • @SQLUser – Specify the name of the database user that you want to drop
  • @NewSchemaOwner – Specify the name of the database user that will be used as new schema owner for the schemas that is owned by the database user, which you are dropping

-- Ensure a USE database_name statement has been executed first.

DECLARE @ID [int] ,
		@CurrentCommand [nvarchar](MAX) ,
		@ErrorMessage   [nvarchar](2000) ,
		@SQLUser        [sysname] , --Specify the name of the database user that you want to drop
		@NewSchemaOwner [sysname];  --Specify the name of the database user that will be used as new schema
								    --owner for the schemas that is owned by the database user you are dropping

SET @SQLUser = N'Specify_Database_User_You_Want_To_Drop'; --Example: testuser
SET @NewSchemaOwner = N'Specify_Database_User_Who_Will_User_As_New_Schema_Owner'; --Example: liveuser

      [ID] [int] IDENTITY(1, 1)
                 PRIMARY KEY ,
      [TSQL_Text] [varchar](1024) ,
      [Completed] [bit]

        ( [TSQL_Text] ,
                + SPACE(1) + QUOTENAME(@NewSchemaOwner) ,
        FROM    [sys].[schemas]
        WHERE   [principal_id] = USER_ID(@SQLUser);

        ( [TSQL_Text] ,
        SELECT  N'DROP USER' + SPACE(1) + @SQLUser ,

FROM    @Work_To_Do
WHERE   [Completed] = 0;

        SELECT  @CurrentCommand = [TSQL_Text]
        FROM    @Work_To_Do
        WHERE   [ID] = @ID;

        BEGIN TRY
            EXEC [sys].[sp_executesql] @CurrentCommand
            PRINT @CurrentCommand
        END TRY

            SET @ErrorMessage = N'"Oops, an error occurred that could not be resolved. For more information, see below:'
                + CHAR(13) + ERROR_MESSAGE() 

            RAISERROR(@ErrorMessage,16,1) WITH NOWAIT

            GOTO ChooseNextCommand
        END CATCH


        UPDATE  @Work_To_Do
        SET     [Completed] = 1
        WHERE   [ID] = @ID

        SELECT  @ID = MIN([ID])
        FROM    @Work_To_Do
        WHERE   [Completed] = 0