SQL Server: MERGE (AKA UPSERT) =(INSERT / UPDATE / DELETE) – All In One

MERGE statement does INSERT/UPDATE/DELETE For the longest time Oracle and SQL Server users have written code like this (pseudo code) This is great but this is such a common construct that everyone has also been long craving for built in support in the database for what people commonly call UPSERT (UPDATE if key exists else INSERT). … Continue reading SQL Server: MERGE (AKA UPSERT) =(INSERT / UPDATE / DELETE) – All In One

Advertisements

Oracle UNDO – A Basic Explanation

You might have heard the terms UNDO and REDO thrown around in conversations around space usage. In this tip, let us get a basic idea of what UNDO (formerly called ROLLBACK) is in Oracle. I promise you that this will be an interesting read and you will be happy you read this. Unlike SQL Server … Continue reading Oracle UNDO – A Basic Explanation

SQL Server Dynamic SQL – Use Bind Variables

Dynamic SQL – SQL that is constructed by putting together strings to form executable code that gets parsed for the first time by the compiler at run-time. Justification for Dynamic SQL? There should be relatively few instances where dynamic SQL is the only option. Generally, regular SQL whose syntax can be checked by the compiler … Continue reading SQL Server Dynamic SQL – Use Bind Variables

Oracle/SQL Server – RANK, DENSE_RANK and ROW_NUMBER Analytic Functions – Basic Examples

Note: The illustrations on this post are done with Oracle. However, by making minor changes, you should be able to run it on SQL Server and the concepts remain the same. Please refer this post for changes needed. RANK, DENSE_RANK and ROW_NUMBER are three powerful analytic functions that every database developer should be thoroughly familiar … Continue reading Oracle/SQL Server – RANK, DENSE_RANK and ROW_NUMBER Analytic Functions – Basic Examples

Oracle – LAG & LEAD – Usage Examples + Interesting Use-case

LAG and LEAD are a couple of analytic functions that come in handy in some interesting situations. I am not really sure why I wrote this post but at least it gives you a a few queries to play with LEAD and LAG. I am not completely happy with how this post turned out. Nothing … Continue reading Oracle – LAG & LEAD – Usage Examples + Interesting Use-case