chapter31

development in a land far far away…

at the moment

History is not what happened. History is what was written down.

Archive for the 'Databases' Category

Returning random results with MySQL

Friday, March 21st, 2008

Selecting random query results is something we often need to do, whether it be a single row or a small record set. You may want to display a random list of “tips” or “facts”, a random “user” or “related product” etc.
The simplest and most common solution you find uses the MySQL rand() function (which can [...]

Read the rest of this entry »

I was working on piece of code today which was sending an Ajax request to the server. The result of this request could have been 0 - 5 database UPDATE statements.
What I needed was a way to test my code to make sure the correct number of database statements were being executed based on the [...]

Read the rest of this entry »

Combining insert and update SQL logic

Wednesday, April 11th, 2007

*Note that this example is using MSSQL with an Identity set to generate the primary key automatically.
An all too common process developers go through when building database driven web applications is creating logic to INSERT a record when one doesn’t exist, and UPDATE a record when one does exist.
This often leads to conditional logic within [...]

Read the rest of this entry »

ColdFusion UUID and MSSQL newID()

Tuesday, January 30th, 2007

A lot of web applications these days use a UUID as the primary key instead of the int/identity combination (speaking for MSSQL that is).
Now there is a (valid) argument that UUID’s aren’t great for primary keys due to the fact that primary keys are clustered, meaning that integers would work much better if the [...]

Read the rest of this entry »

To delete or not to delete

Thursday, January 11th, 2007

As a web developer you are constantly faced with building functionality to remove an object from an application. The object could be anything from a web page in a CMS to a user in a CRM, but generally involves a record(s) stored in a database.
For a user ‘using’ the application whenever they access the functionality [...]

Read the rest of this entry »