2 Ways to Check the Default Fill Factor in SQL Server

Fillfactor is an option that allows us to fine tune index data storage and performance in SQL Server. It determines the percentage of space on each leaf-level page to be filled with data, therefore reserving the remainder on each page as free space for future growth.

The default fillfactor can be set as a configuration option. SQL Server sets this value to 0, and so this is what’s used when we create an index without specifying a fillfactor. However, it’s possible to change this value, and so at some stage we might want to check to see what the current value is.

Below are two ways to check the fill factor configuration option.

Continue reading

Fixing Error 258 “Cannot call methods on nvarchar(max)” When a Subquery Uses FOR XML in SQL Server

If you’re running a subquery that uses FOR XML to produce XML in SQL Server, but you’re getting error 258, which reads “Cannot call methods on nvarchar(max)” it might be that you’re trying to query the XML in the outer query, but your inner query isn’t outputting the XML as an actual xml type.

The FOR XML result must be an xml type in order to process the result on the server.

To fix this issue, make sure the subquery outputs the result using the xml data type.

Continue reading

Fix Error “The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions…” in SQL Server (Error 1033)

If you’re getting an error that reads “The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified” in SQL Server, it appears that you’re using the ORDER BY clause in a place that it must also be accompanied by a TOP, OFFSET or FOR XML clause, but you’re not including one of those clauses.

To fix this issue, be sure to include one of those clauses in your query if you need to use the ORDER BY clause.

Continue reading

Using ON UPDATE SET DEFAULT in SQL Server

In SQL Server, foreign keys are essential for maintaining referential integrity between tables. When creating foreign keys, we have a number options available to us when it comes to defining what should happen in the event that the related data in the parent table changes. One such option is ON UPDATE SET DEFAULT.

This article will explain what this option does, provide an example of its usage, and offer a practical scenario where this feature can be useful.

Continue reading

Fix “The correlation name … is specified multiple times in a FROM clause” in SQL Server (Error 1011)

If you’re getting an error that reads something like “The correlation name ‘a’ is specified multiple times in a FROM clause’” in SQL Server, it could be that you’re doing a join on two tables, but you’re assigning them the same aliases.

Each table’s alias must be unique.

To fix this issue, be sure to use unique table aliases in your query.

Continue reading

Indexes on Expressions in PostgreSQL: A Quick Overview

In PostgreSQL, indexes on expressions (also known as “functional indexes”) allow you to create an index not just on a column but on the result of an expression or function applied to a column (or multiple columns). This can significantly improve query performance when the same expression is used frequently in queries, especially for complex calculations or transformations.

Continue reading

Fix “Cannot create index on view because the view is not schema bound” in SQL Server (Error 1939)

If you’re getting an error that reads something like “Cannot create index on view ‘MyView’ because the view is not schema bound” in SQL Server, it sounds like you’re trying to create an index on a view that’s not schema bound.

Indexes can only be created on schema bound views.

To fix this issue, define the view as schema bound before creating the index.

Continue reading