Latest articles under Database category

How to grant create database for non-root users

Introduction So here’s a recent requirement that I’ve just encountered. I have a shared MySQL database I have several users that I want them to be able to create new databases However, I don’t want them to see each other’s databases And just to be absolutely clear, I obviously don’t want to give them all […]

Posted on June 6th, 2014 under Database, MySQL  •  1 Comment

Swap values in 2 rows SQL

I encountered a situation at work that I feel would be a good brain teaser. I was working on a project and needed a way to swap values from 2 different rows in a SQL table. Obviously I can do it on client side (like PHP) to do it; but that wouldn’t be a good […]

Posted on October 11th, 2009 under General SQL, MySQL, PostgreSQL  •  16 Comments

Solving sudoku using PostgreSQL PL/pgSQL

I have no idea why I would want to solve sudoku in PostgreSQL PL/pgSQL. My guess would be just for the fun of it. I’m also hoping that it can serve as a tutorial example in programming PostgreSQL PL/pgSQL. So what is sudoku? It is basically a number puzzle where the objective is to fill […]

Posted on August 19th, 2009 under General / Algorithm, PostgreSQL  •  4 Comments

Use EXISTS() instead of COUNT(*)

A lot of times, I saw programmers use COUNT(*) and check if the result is greater than 0 to see if a particular record exits in a table. If your only purpose is to know if a record exists or not and you don’t really care about how many matched records are there, the better […]

Posted on June 30th, 2009 under General SQL  •  3 Comments

Bulk alter schema in MySQL.

There are times when you want to alter schema for all tables in the database. For example, let’s say in your project you have multiple databases with multiple tables on each of them. Suppose that you have columns within that table defined as DECIMAL(11,6). What it means is that the column will have 11 digits […]

Posted on April 20th, 2009 under MySQL  •  1 Comment

Page 1 of 3123