Skip to main content

176 posts tagged with "Database"

Databases, Data Modeling, and Data Access

View All Tags

How to Count Rows in a MySQL Table

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

SELECT COUNT(*) FROM table tells you how many rows a table has. Add WHERE to count only some of them, or GROUP BY to count per category. There's one trap: COUNT(column) skips NULLs, so it can give a smaller number than you expect. All of it is run here on MySQL 9.7.

How to Update Rows in a MySQL Table Safely

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

An UPDATE with the wrong WHERE, or no WHERE at all, can change every row in a table, and there's no undo afterwards. A few habits make it safe: check the rows with a SELECT first, read what MySQL reports, and use a transaction when it matters. This guide does all of those on MySQL 9.7.

Fixed: MySQL Rounds a Decimal Like 9.999 to 10.00 Without an Error (Note 1265: Data truncated for column)

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

I sent a product price of 9.999 to my API, and it answered 201 Created with a price of 10.00. No error, no warning: MySQL rounded the amount to fit its DECIMAL(12,2) column, even in strict mode, and raised only a note that EF Core never shows. For money, silently changing the number isn't acceptable, so the API now refuses it.

Fixed: "Data too long for column 'Name' at row 1" When Saving with EF Core and MySQL

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A long category name made my API answer 500, with Data too long for column 'Name' at row 1 in the log. MySQL was right to refuse it: the column is varchar(100), and the name had 101 characters. The problem was that the request got as far as MySQL at all. A validation attribute stops it first, and the client gets an answer it can act on.