Showing entries 91 to 100 of 1180
« 10 Newer Entries | 10 Older Entries »
Displaying posts with tag: sql (reset)
MySQL INSERT-SET

I found myself explaining the nuances of INSERT statements and whether you should use named or positional notation. While the class was on Zoom, I could imagine the blank stares in the silence of my headphones. Then, I had to remind them about mandatory (NOT NULL constrained) and optional (nullable) columns in tables and how an INSERT statement requires an explicit NULL value for optional columns when the INSERT statement isn’t inserting a value into that column.

Then, I asked if somebody could qualify the different types of INSERT statements; and what would happen if a table with a first_name and last_name column order evolves when a new DBA decides to restructure the table and uses a last_name and first_name column order in the new table structure. Only a couple of the students recalled using a column-list …

[Read more]
MySQL Searched CASE Expression – with examples

During many decision-making phases in programming code (conditional logic), there are times execution depends on several different factors. Multiple conditional tests are powerful and constraining, oftentimes requiring more than one test to be passed in order for program flow to proceed. For MySQL (and standard SQL in general) the CASE expression is used for IF/THEN/ELSE conditional logic. The post, MySQL Simple CASE Expression – with examples, covered Simple CASE queries which are essentially equality tests. MySQL Simple CASE is but one variant of 2, with the other being a MySQL Searched CASE Expression.  A MySQL Searched CASE Expression can have multiple conditional tests in each WHEN

[Read more]
How to index JSON columns using MySQL

Introduction In this article, I’m going to explain how we can index JSON columns when using MySQL. While other relational database systems provide GIN (Generalized Inverted Index) indexes, MySQL allows you to index a virtual column that mirrors the JSON path expression you are interested in indexing. Database table Let’s assume we have the following database book table: The properties column type is json, so we can store JSON objects as book properties. Querying MySQL JSON columns without an index If we try to filter one record by its associated title attribute... Read More

The post How to index JSON columns using MySQL appeared first on Vlad Mihalcea.

MySQL Simple CASE Expression – with examples

Programming logic is foundational in any application or piece of software. Without it, software wouldn’t really do much of anything. Everything happens off of choice. In the end, some truthy or falsy value is what makes stuff work. For IF/THEN/ELSE logic in standard SQL, there is the CASE expression. There are 2 variations of the CASE Expression: Simple and Searched. In this post, I cover the Simple MySQL CASE expression with example queries…

Image by Nika Akin from …

[Read more]
MySQL Column Aliases using the AS keyword

Be it running reports or displaying data in some other visualization, SQL SELECT column expressions should be meaningful and understandable. To provide those valuable query results, SQL Developers, use a multitude of available functions, adjacent columns, or other means not readily apparent to end-users. All that being said, the column names often suffer the most as far as readability is concerned, taking on long function call names or other combined expressions. But, as luck would be on our side, there is an easy fix and that is aliasing columns using the AS keyword. Although AS is optional – in this particular context – I err on the side of readability and use it when aliasing SELECT column expressions.

Image by …

[Read more]
MySQL Count Weekday occurrences

Each SQL dialect is different in some way, shape, form, or fashion from the next flavor. Some dialects have this function, while others have that function. In this post, I cover porting over Oracle SQL to MySQL in order to count the number of occurrences of a specific weekday found in the current given month (at the time of writing) purely as a learning exercise focused on MySQL DATE functions and the WITH clause…

Image by tigerlily713 from Pixabay

[Read more]
MySQL COUNT() aggregate function – Medium cross post

I recently published a blog post over on Medium about the differences in 2 versions of the MySQL COUNT() aggregate function: COUNT(*) and COUNT(column_name or expression). I wanted to share the post here with any readers who may be interested so continue reading for more on this post…

Image by anncapictures from Pixabay

Self-Promotion:

If you enjoy the content written here, by …

[Read more]
MySQL Aggregate Query using CodeIgniter’s Query Builder

CodeIgniter’s Query Builder ORM has class methods for nearly any kind of database access/operation you can think of. In this post, I’ll cover some of the available methods for retrieving aggregate-level query results. The examples in this post map out Query Builder method chaining to produce results you would get from a raw MySQL query. Continue reading to see more…

Image by Clker-Free-Vector-Images from Pixabay

Self-Promotion:

If you enjoy the content written here, by …

[Read more]
MySQL Transaction Scope

The idea of ACID transactions are a basic feature of SQL’s individual Data Manipulation Language (DML) commands, like the INSERT, UPDATE, and DELETE statements. Transactions across two or more tables are a natural extension of ACID compliance features provided by DML commands. However, they require a structured programming approach, like a store procedure or like API implemented in an imperative language.

Surprisingly, transaction management wasn’t covered well in Alan Beaulieu’s Learning SQL because he only provided pseudo code logic. While I thought troubleshoot some broken MySQL SQL/PSM logic would be a good learning experience for students, it wasn’t. So, I wrote this sample code to show how to achieve an all or nothing transaction across four tables.

The code for this example on transaction management lets you perform the important tasks necessary to effect transaction …

[Read more]
MySQL Query Profiling Using Performance Schema

Introduction In this article, I’m going to explain how to do query profiling using the MySQL Performance Schema. The Performance Schema has been available since MySQL 5.5.3 and allows MySQL to instrument SQL queries and store their trace information in various tables that you can later inspect in order to determine why a given SQL statement is slow. On older versions of MySQL, you might have used the SHOW PROFILE command, but since this feature has been deprecated, you should now use the Performance Schema for SQL query profiling. Enabling the MySQL... Read More

The post MySQL Query Profiling Using Performance Schema appeared first on Vlad Mihalcea.

Showing entries 91 to 100 of 1180
« 10 Newer Entries | 10 Older Entries »