If you’re getting an error that reads something like “Cannot create index on view “demo.dbo.SalesSummary” because it uses the aggregate COUNT. Use COUNT_BIG instead” in SQL Server, it’s because you’re trying to create an index on a view that uses the COUNT()
function.
Author: Ian
Clustered vs Nonclustered Index: What’s the Difference?
Indexes can play a crucial role in optimizing SQL query performance. A well designed index can help a query perform much faster than it otherwise might. While there are many types of indexes, two common index types are clustered and nonclustered indexes.
Understanding the difference between clustered and nonclustered indexes can have a significant impact on our database design and query optimization strategies.
In this article, we’ll take a look at clustered and nonclustered indexes as implemented in SQL Server, explore their characteristics, and examine when to use each type.
Continue readingWhat is an ER Diagram?
An entity relationship (ER) diagram (also known as an ERD for Entity-Relationship Diagram) is a visual representation of the relationships between entities within a system. ER Diagrams are often used when designing relational databases. An ERD serves as a blueprint for designing a database by depicting entities, their attributes, and the relationships between them.
ER diagrams help in conceptualizing the structure of a database and serve as a communication tool between database designers, developers, and stakeholders.
Continue reading4 Functions that Trim a String in PostgreSQL
PostgreSQL provides us with various string functions, including some that allow us to trim a given string on both sides or a given side.
Below are four functions that we can use to trim strings in PostgreSQL.
Continue readingFix “Cannot DROP TABLE because it is being referenced by object” in SQL Server (Error 3729)
If you’re getting an error that reads something like “Cannot DROP TABLE ‘dbo.t1’ because it is being referenced by object ‘v1’” in SQL Server, it looks like you’re trying to drop a table that’s referenced by a schema-bound object (such as a schema-bound view).
Continue readingUnderstanding the CONTINUE Keyword in SQL Server WHILE Loops
WHILE
loops are a fundamental construct in T-SQL (and in programming in general) for executing repetitive tasks. Within these loops, the CONTINUE
keyword serves as a powerful control flow tool, allowing developers to skip iterations and optimise loop execution.
This article explores the usage and benefits of the CONTINUE
keyword in SQL Server WHILE
loops.
Fix “Computed column … in table … is not allowed to be used in another computed-column definition” (Error 1759)
If you’re getting an error that reads something like “Computed column ‘c2’ in table ‘t1’ is not allowed to be used in another computed-column definition” in SQL Server, it appears that you’re trying to create a computed column that uses another computed column.
We can’t use other computed columns in our computed column definitions.
Continue readingIndexed Views in SQL Server: A Complete Guide
Indexed views can significantly enhance the performance of complex queries in SQL Server. However, they come with several prerequisites and considerations that need to be carefully understood before implementation.
In this article, I provide an overview of indexed views, discussing their utility, prerequisites, and best practices, along with performance considerations and a simple example.
Continue readingWhat Does Deterministic Mean in SQL?
In SQL, a deterministic expression or function always returns the same result when given the same input. Conversely, a nondeterministic expression or function may return different results even with the same input due to factors like system time, randomization, or external data changes.
Below is a quick overview of the differences between deterministic and nondeterministic functions/expressions.
Continue readingFix “ALTER TABLE DROP COLUMN failed because one or more objects access this column” in SQL Server (Error 4922)
If you’re getting an error that reads something like “ALTER TABLE DROP COLUMN c2 failed because one or more objects access this column” in SQL Server, it looks like you’re trying to drop a column that’s accessed by another object.
This can happen when we try to drop a column that’s referenced by a schema-bound view. It can happen even when we only try to alter the columns too.
Continue reading