SQL

Ordering Tricks in SQL
Reader Level: Reader Level

A database is like a book with no index--you store information in it, but unless you know how to get it out in a particular order, it's not going to be very useful. Ordering is one of the most often used aspects of SQL, yet one of the most under-used parts of SQL language at the same time. You can often do some really cool things through simple ordering of your data, and present the data in a different way.

Quickshot - Using Subqueries and Count to Display Membership Counts Per Region Free!
Reader Level: Reader Level

In this quick shot, I'll show you how to take a list of locations and provide a count of members per location.

Expiring Time Sensitive Records in MySQL Driven Content Management Systems
Reader Level: Reader Level

Have you ever left a voicemail and their outgoing message referred to some specific event last Wednesday? You wanted to let them know about the outdated message, but you didn't want to embarrass them? Ever pull up a web page and see a similarly embarrassingly outdated notice which now makes the web page look neglected and untrustworthy? Now ask yourself, "How many of your colleagues or friends would tell you that you had this problem?"

This tutorial is all about avoiding that embarrassing and compromising situation. It all started when I was recently working on a training catalog which I constructed as a dynamic content management system. Over the year of building these I've come to realize that just because anyone technically can keep the content updated doesn't mean they will. While the CMS contained a field to write upcoming schedule information, I knew that updating that information when it was no longer current wasn't going to be at the top of anyone's calendar. To prevent this scenario, I added an expiration date to the content table so that a date could be set after which the content would no longer be displayed.

In this tutorial, you will learn how to add an expiration date field to any content table. You will also see how to make record selections which which not include expired records (and thus eliminating the need for server-side scripting logic to not display expired records.) I've already mentioned one use case, training catalog schedule information, but this approach is great for many other uses as well. These might include time-sensitive blog posts, employment offers, news scroller entries, service notices or time-limited coupon code and sale offers.

How to Report Non-Calendar Years in PHP and MySQL
Reader Level: Reader Level

Calendar years make reporting easy. The calendar year 2010 is simply distinguished from 2009. What could be easier than selecting all records from the current calendar year?

SELECT * FROM `records` WHERE YEAR(`record_date`) = YEAR(NOW())

Some organizations, however, maintain reporting calendars which do not start on January 1 and end on December 31. Businesses maintain a fiscal year, educational institutions keep an academic year and even sports leagues keep seasons which begin in one calendar year and end in the next. In these cases, assessing the current year is not as simple as looking at the calendar. For example, the fiscal year for many countries around the world begins July 1 and ends on the following June 30. The Government of the US has a fiscal year which starts on October 1. In the UK, the fiscal year for personal taxation reporting begins on April 6.

This article will show you how to use both PHP and MySQL to define a custom reporting year and determine the current reporting year at any date. These functions will allow you to easily include the start and end points of the year as well as create reporting queries based on these defined temporal end points.

What If MySQL Could Eliminate PHP?
Reader Level: Reader Level

The hallmark of a successful programmer can be measured in economy of code. Being proficient means doing more work with less code. In working with MySQL data in PHP scripts, one can eliminate a lot of heavy lifting in PHP with some simple MySQL functions. In today's example, we'll look at MySQL's IF() function as a way to supply data already interpreted so we don't have to do the work in PHP.

Quickshot - Working with NULL and Empty Values in MySQL
Reader Level: Reader Level

You have a database with NULL values in a column and empty values in a column and you need to test against both conditions and return records that have neither null or empty values or that replace these values with something.

Audit a MySQL Data Table - Part 3
Reader Level: Reader Level

When you have a database table that gets updated or changed, it makes sense to keep track of those updates. A relational database table is like a snapshot in time. It contains your data in its most recent form. When you update it, the previous data is lost. For example, a product might have a price. When you change that price, the previous price is lost. Many times it can be retrieved from a log, but another way to make sure you have an audit trail of your data is to create dedicated audit tables for each table that you want to keep track of.

This first two parts of the series showed a simple way to create an audit table and related functionality in MySQL without needing to modify your web application much at all. The third and final part will show a simple report on the web of the audit results. For the article, I'll assume you know how to set up PHP sites, work with basic database operations in PHP (listing, inserting, updating data), and working with session variables.

The Audit a MySQL Data Table Series:
Audit a MySQL Data Table - Part 1
Audit a MySQL Data Table - Part 2
Audit a MySQL Data Table - Part 3

Using Cartesian SQL Queries
Reader Level: Reader Level

What is a Cartesian query? It is a query that returns every row in two (or more) tables. Generally, these are to be avoided since the require a lot of system resources and don't seem to return useful information, however, the returned information can be manipulated to have some nice results.

Get the Time of Day as a MySQL Developer - Part 7: Date and Time Cookbook
Reader Level: Reader Level

Throughout this series, you have learned over 50 date and time functions which allow you to get the time and date, format its appearance, convert to another unit of measure or to perform calculations on elapsed time. Now that you know how to manage dates and times, it is time to put that knowledge into practice.

Included in this article is list of recipes for your MySQL cookbook ready to use in your projects. These recipes also serve as examples of the power of MySQL- especially when compated to the programmatic effort required, in some cases, by PHP or another scripting language.

The Get the Time of Day using MySQL Series:
Get the Time of Day as a MySQL Developer - Part 1: Data Types
Get the Time of Day as a MySQL Developer - Part 2: Automatically Updated Timestamp
Get the Time of Day as a MySQL Developer - Part 3: Query Functions for Dates and Times
Get the Time of Day as a MySQL Developer - Part 4: Formatting Functions for Dates and Times
Get the Time of Day as a MySQL Developer - Part 5: Conversion Functions for Dates and Times
Get the Time of Day as a MySQL Developer - Part 6: Date and Time Math Functions
Get the Time of Day as a MySQL Developer - Part 7: Date and Time Cookbook

Get the Time of Day as a MySQL Developer, Part 6 - Date and Time Math Functions
Reader Level: Reader Level

As of version 5, MySQL has over 50 date and time functions which allow you to get the time and date, format its appearance, convert to another unit of measure or to perform calculations on elapsed time. While the MySQL manual details the functions altogether on one page, I will cover these functions by their specific purpose.

There are four types of date and time functions within MySQL. By covering these numerous functions within these four categories, I hope to make learning easier for you. I have divided these into the following categories:

  • QueriesGet a time or date value from the server.
  • Formatting – Change the appearance of a date or time value.
  • Conversions – Change the date or time from one unit of measure to another.
  • Math – Calculate the elapsed time between two dates or calculate the time to or from a specific date.

In this part, we will cover the MySQL functions for performing calculations on dates and times. These functions will provide you with a date and time before or after a certain amount of time as passed from a specified value or will calculate the elapsed

The Get the Time of Day using MySQL Series:
Get the Time of Day as a MySQL Developer - Part 1: Data Types
Get the Time of Day as a MySQL Developer - Part 2: Automatically Updated Timestamp
Get the Time of Day as a MySQL Developer - Part 3: Query Functions for Dates and Times
Get the Time of Day as a MySQL Developer - Part 4: Formatting Functions for Dates and Times
Get the Time of Day as a MySQL Developer - Part 5: Conversion Functions for Dates and Times
Get the Time of Day as a MySQL Developer - Part 6: Date and Time Math Functions
Get the Time of Day as a MySQL Developer - Part 7: Date and Time Cookbook



Audit a MySQL Data Table - Part 1
Reader Level: Reader Level

When you have a database table that gets updated or changed, it makes sense to keep track of those updates. A relational database table is like a snapshot in time. It contains your data in its most recent form. When you update it, the previous data is lost. For example, a product might have a price. When you change that price, the previous price is lost. Many times it can be retrieved from a log, but another way to make sure you have an audit trail of your data is to create dedicated audit tables for each table that you want to keep track of.

This first two parts of the series showed a simple way to create an audit table and related functionality in MySQL without needing to modify your web application much at all. The third and final part will show a simple report on the web of the audit results. For the article, I'll assume you know how to set up PHP sites, work with basic database operations in PHP (listing, inserting, updating data), and working with session variables.

The Audit a MySQL Data Table Series:
Audit a MySQL Data Table - Part 1

Get the Time of Day as a MySQL Developer, Part 5 - Conversion Functions for Dates and Times
Reader Level: Reader Level

As of version 5, MySQL has over 50 date and time functions which allow you to get the time and date, format its appearance, convert to another unit of measure or to perform calculations on elapsed time. While the MySQL manual details the functions altogether on one page, I will cover these functions by their specific purpose.

There are four types of date and time functions within MySQL. By covering these numerous functions within these four categories, I hope to make learning easier for you. I have divided these into the following categories:

Queries -- Get a time or date value from the server.
Formatting -- Change the appearance of a date or time value.
Conversions -- Change the date or time from one unit of measure to another.
Math -- Calculate the elapsed time between two dates or calculate the time to or from a specific date.

This installment will cover conversion functions which are used for converting a temporal value of one unit of measure to another.

Audit a SQL Server Data Table - Part 3
Reader Level: Reader Level

When you have a database table that gets updated or changed, it makes sense to keep track of those updates. A relational database table is like a snapshot in time. It contains your data in its most recent form. When you update it, the previous data is lost. For example, a product might have a price. When you change that price, the previous price is lost. Many times it can be retrieved from a log, but another way to make sure you have an audit trail of your data is to create dedicated audit tables for each table that you want to keep track of.

This first two parts of the series showed a simple way to create an audit table and related functionality in SQL Server without needing to modify your web application much at all. The third and final part will show a simple report on the web of the audit results. For the article, I'll assume you know how to set up ColdFusion sites, work with basic database operations in ColdFusion (listing, inserting, updating data), and working with session variables.

The Auditing a SQL Server Data Table Series:
Audit a SQL Server Data Table - Part 1
Audit a SQL Server Data Table - Part 2
Audit a SQL Server Data Table - Part 3

Get the Time of Day as a MySQL Developer - Part 4 - Formatting Functions for Dates and Times
Reader Level: Reader Level

As of version 5, MySQL has over 50 date and time functions which allow you to get the time and date, format its appearance, convert to another unit of measure or to perform calculations on elapsed time. While the MySQL manual details the functions altogether on one page, I will cover these functions by their specific purpose.

There are four types of date and time functions within MySQL. By covering these numerous functions within these four categories, I hope to make learning easier for you. I have divided these into the following categories:

Queries -- Get a time or date value from the server.
Formatting -- Change the appearance of a date or time value.
Conversions -- Change the date or time from one unit of measure to another.
Math -- Calculate the elapsed time between two dates or calculate the time to or from a specific date.

This installment will cover functions for formatting dates and times to give them the appearance that you wish to display.

The Get the Time of Day using MySQL Series:
Get the Time of Day as a MySQL Developer - Part 1: Data Types
Get the Time of Day as a MySQL Developer - Part 2: Automatically Updated Timestamp
Get the Time of Day as a MySQL Developer - Part 3: Query Functions for Dates and Times
Get the Time of Day as a MySQL Developer - Part 4: Formatting Functions for Dates and Times

Audit a SQL Server Data Table - Part 2
Reader Level: Reader Level

When you have a database table that gets updated or changed, it makes sense to keep track of those updates. A relational database table is like a snapshot in time. It contains your data in its most recent form. When you update it, the previous data is lost. For example, a product might have a price. When you change that price, the previous price is lost. Many times it can be retrieved from a log, but another way to make sure you have an audit trail of your data is to create dedicated audit tables for each table that you want to keep track of.

This article will show one simple way to create an audit table and related functionality in SQL Server without needing to modify your web application much at all. This first part of the series set up a sample application. This part will create the SQL Server functionality to handle the audit. For the article, I'll assume you know how to set up ColdFusion sites, work with basic database operations in ColdFusion (listing, inserting, updating data), and working with session variables. The series will focus on the auditing of the table.

The Auditing a SQL Server Data Table Series:
Audit a SQL Server Data Table - Part 1
Audit a SQL Server Data Table - Part 2
Audit a SQL Server Data Table - Part 3

Get the Time of Day as a MySQL Developer, Part 3 - Query Functions for Dates and Times
Reader Level: Reader Level

As of version 5, MySQL has over 50 date and time functions which allow you to get the time and date, format its appearance, convert to another unit of measure or to perform calculations on elapsed time. While the MySQL manual details the functions altogether on one page, I will cover these functions by their specific purpose.

There are four types of date and time functions within MySQL. By covering these numerous functions within these four categories, I hope to make learning easier for you. I have divided these into the following categories:

Queries -- Get a time or date value from the server.
Formatting -- Change the appearance of a date or time value.
Conversions -- Change the date or time from one unit of measure to another.
Math -- Calculate the elapsed time between two dates or calculate the time to or from a specific date.

This installment will cover query functions which are use to access the current date and time.

The Get the Time of Day using MySQL Series:
Get the Time of Day as a MySQL Developer - Part 1: Data Types
Get the Time of Day as a MySQL Developer - Part 2: Automatically Updated Timestamp
Get the Time of Day as a MySQL Developer - Part 3: Query Functions for Dates and Times
Get the Time of Day as a MySQL Developer - Part 4: Formatting Functions for Dates and Times

Audit a SQL Server Data Table - Part 1 Free!
Reader Level: Reader Level

When you have a database table that gets updated or changed, it makes sense to keep track of those updates. A relational database table is like a snapshot in time. It contains your data in its most recent form. When you update it, the previous data is lost. For example, a product might have a price. When you change that price, the previous price is lost. Many times it can be retrieved from a log, but another way to make sure you have an audit trail of your data is to create dedicated audit tables for each table that you want to keep track of.

This article will show one simple way to create an audit table and related functionality in SQL Server without needing to modify your web application much at all. This first part of the series will set up a sample table and give a little background preparation for the functionality. For the article, I'll assume you know how to set up ColdFusion sites, work with basic database operations in ColdFusion (listing, inserting, updating data), and working with session variables. The series will focus on the auditing of the table.

The Auditing a SQL Server Data Table Series:
Audit a SQL Server Data Table - Part 1
Audit a SQL Server Data Table - Part 2
Audit a SQL Server Data Table - Part 3

Get the Time of Day as a MySQL Developer - Part 2: Automatically Updated Timestamp
Reader Level: Reader Level

The first part of this article covered MySQL date and time data types and their usage. Introduced was the TIMESTAMP type which, like the DATETIME type stores the date and time, but is used primarily for the purpose of tracking table modifications. Timestamps can be configured such that they automatically update themselves when a table record is modified.

This part of the series will go into more detail on the utilization of TIMESTAMPs in your tables. We'll then explore a bit of advanced configuration which in effect makes it possible to have two auto_updating TIMESTAMPs: one updating on creation and one updated on update. This will allow you convenience in automatically tracking additions to your tables.

The Get the Time of Day using MySQL Series:
Get the Time of Day as a MySQL Developer - Part 1: Data Types
Get the Time of Day as a MySQL Developer - Part 2: Automatically Updated Timestamp
Get the Time of Day as a MySQL Developer - Part 3: Query Functions for Dates and Times
Get the Time of Day as a MySQL Developer - Part 4: Formatting Functions for Dates and Times

Get the Time of Day as a MySQL Developer - Part 1: Data Types Free!
Reader Level: Reader Level

You won't have to wait long, as a web developer, before needing to store and retrieve dates and times in MySQL. A mastery of the date and time data types as well as familiarity with the many date and time functions is essential for any MySQL developer in order to maintain integrity in the temporal values that you manage.

This article will cover MySQL date and time data types and their usage. Firstly, we'll look at the options for storing temporal data and later we'll look at important functions for retrieving and using this data. This series is designed to provide the fundamental working knowledge necessary for managing temporal data in MySQL and is designed for beginners as well as experienced users who did not receive formal training in MySQL.

The Get the Time of Day using MySQL Series:
Get the Time of Day as a MySQL Developer - Part 1: Data Types
Get the Time of Day as a MySQL Developer - Part 2: Automatically Updated Timestamp
Get the Time of Day as a MySQL Developer - Part 3: Query Functions for Dates and Times
Get the Time of Day as a MySQL Developer - Part 4: Formatting Functions for Dates and Times

Getting Information Out of Your mySQL Database
Reader Level: Reader Level

You've just landed a new client, you've got a lot of work to do and they have over their FTP information - and wish you well. You ask for their control panel or phpmyadmin login and they look at you funny - like you're speaking in unknown language to them. You need their existing database information, what are you to do?

Formatting Dates in SQL Server
Reader Level: Reader Level

Whether because of a national standard or a particular file format, a common issue in SQL is how to retrieve a date value in a certain date format. As we have discussed before, SQL Server in particular stores dates as a number of seconds (and ractions of a second) since the epoch. So, in reality, dates almost always come out of SQL Server formatted differently than they are stored. If you want something other than the standard 2009-08-02 16:10:11.620 (YYYY-MM-DD hh:mm:ss.mmm) have to tell SQL Server in your query how you want the date formatted. Since SQL Server does not really have a date format function (like you might find in ColdFusion) you will need to use the convert function to accomplish this.

Checking Against Data In Multiple Columns
Reader Level: Reader Level

I am amazed every day by the complicated ways that people need to look at the data in their databases. On a fairly regular basis, I am asked to run queries and reports in ways that were never anticipated when the database was designed or that the original designer did not take into consideration. It often takes some creative work to get to the desired goal.

Quickshot: Enforcing Case Sensitivity in SQL Server Free!
Reader Level: Reader Level

If you are paying attention to security in your online applications, then you are likely encouraging your users to select strong passwords that contain numbers, special characters and letters that are both upper and lower case. Without special attention to your database settings, however, SQL Server will treat upper and lower case characters as equivalent to one another, causing you to loose a significant part of the strength of your passwords.

In this article, we will show a quick and simple way to have SQL Server enforce case sensitivity.

Dealing with NULL Values in SQL Server - Part 2
Reader Level: Reader Level

In SQL, there is data, no data, and NULLs. A NULL is a unique concept, and is often misunderstood by programmers. A field can contain data, or it can be blank, but it can also be NULL, which is not the same as blank.

The first part of this series introduced the concept of NULLs. In this part will show how to deal with NULLs for your inserts and updates.

The Dealing with NULL Values in SQL Server Series
Dealing with NULL Values in SQL Server - Part 1
Dealing with NULL Values in SQL Server - Part 2

Dealing with NULL Values in SQL Server - Part 1
Reader Level: Reader Level

In SQL, there is data, no data, and NULLs. A NULL is a unique concept, and is often misunderstood by programmers. A field can contain data, or it can be blank, but it can also be NULL, which is not the same as blank.

This article will introduce the concept of NULLs. A second part will show how to deal with NULLs for your inserts and updates, and creating tables that do not accept NULL values.

The Dealing with NULL Values in SQL Server Series
Dealing with NULL Values in SQL Server - Part 1
Dealing with NULL Values in SQL Server - Part 2

Doing Calculations with SQL - Part 2
Reader Level: Reader Level

In the last article in this series I talked about calculations on a web page. There are two ways that this can be done—in your scripting language on the web page (PHP, ColdFusion, C#, or other languages) or in the SQL statement that retrieves the results from the database. For displaying data, it is almost always a better idea to create the calculations in your SQL statement, to keep the business logic out of the web page and take advantage of the data processing speed in the database.

This second, and last, part will show a few simple examples of doing calculations directly in INSERT and UPDATE statements, and when not to use the technique. The article is intended as a basic introduction to doing calculations in SQL and to get the reader thinking about alternative ways of doing things.

The Doing Calculations with SQL Series:
Doing Calculations with SQL - Part 1
Doing Calculations with SQL - Part 2

Using Table Aliases
Reader Level: Reader Level

When writing SQL statements, using the table names in the code is often necesary to avoid confusion in the database server. For example, if you have a Customers table with a customerid field, and an Orders table with a customerid field, if you are joining both tables, you will need to use the table name on the customerid field in order to differentiate between the two tables. This can turn your queries into much longer, hard to read statements -- especially if you are using proper naming conventions and your table names are long and descriptive.

Using a table alias in the code is a beneficial way to increase readability and performance. Readers of this article should understand basic SQL coding, including joins. It will apply to most databases (SQL Server, MySQL, Access, etc).

Win, Lose or Tie - mySQL Scoreboard
Reader Level: Reader Level

Manipulating data in mySQL can be tricky at times. In this tutorial, we will go over how to use a sport team's win/loss record, entered in to one column, to show how versatile mySQL can be. We will also address handling inconsistent data by introducing a win/lose/tie record and cover the ramifications from that as well.

Creating MySQL Logins for a Web Site
Reader Level: Reader Level

MySQL is a popular database to use for your web site, allowing the power of a server-based database management system to be used for free. With the added power comes added danger—MySQL is frequently targeted by hackers. My article on preventing SQL injection attacks mentioned database login security briefly.

In this article, I will expand on how to actually create users for your web site, which is vital knowledge when you are acting as a database administrator. If you have a PHP site using MySQL and you don't have a database administrator—you are it.

Setting up a Multi-level Category Table in SQL
Reader Level: Reader Level

You have a multiple level category list that you need to maintain. You have nested queries, complex deletes and inserts and it all seems to be a mess? Well, this handy little SQL process will make quick work of your category table.

Comparing Timestamps in MySQL Free!
Reader Level: Reader Level

In a recent article, we looked at comparing timestamp columns in SQL Server in order to pull records that occurred on a date or series of dates without regard to the time, and the question came up about how to do the same thing in MYSql.

Comparing Timestamps in SQL
Reader Level: Reader Level

If your web application tracks user registrations, or sales transactions, or anything that you might need to pinpoint to the time it occurred, you probably use timestamps to mark a record as entered or updated in your database table. You might do this using Now() in ColdFusion and pass the date into the database or you might use getdate() in SQL Server as a default field value so that you capture exactly when a record is created or updated at the database level.

Quick Shot: SQL Zip Code Radius Search
Reader Level: Reader Level

Do you need to do a United States Zip Code radius search? Want to do the search by the zip code or by the city? This tutorial will show you the SQL to get it done!

Calculating Percentile Rankings
Reader Level: Reader Level

Percentile rank is a use for statistical measure for comparative data analysis. You may recall the use of percentile from school in which your grade average resulted in your percentile rank amongst your class. If your grade average placed you in the 87th percentile, it meant that your grades were better than 87% of your classmates.

Percentile has some interesting business usages and can be used to indicate popularity as well as success. For example, it can be used to indicate the popularity of a product in its category or someone's achievement within a group. I was recently called to create percentile rankings from athletic evaluation data to better indicate an athlete's overall skill level among a myriad of tests. I used PHP and MySQL to calculate and display the percentiles, but you can use any scripting language and database.

A more common method of indicating rank is to use a natural set of ordinals (1, 2, 3, ...) This method is popular and gives instant recognition of high achievement, but loses perspective once you leave the highest end of the scale. For example, I was just shopping for digital video cassettes on amazon.com and reviewed a product which had a 5-star customer rating. I noticed on that page that the product had an Amazon.com Sales Rank of #59 in the category of blank media.

So how good is #59 in the category? The answer depends on how many other products are in the category. If there are hundreds in the category, then 59 is good, right? I clicked on the link to show the category and the listings only go through 100. If there are only 100 items in the category then 59 is a slightly less than average performer.

The benefit of percentile ranking over ordinal ranking is that you don't have to know how many items are being compared to understand its relative position among the set. With percentile rank you always know where you stand.

From Create a Site to Connecting to a Database
Reader Level: Reader Level

If a picture is worth a thousand words - then a video should be worth millions (if, of course, you account for the 15 frames per second)! In my first video tutorial for Community MX, I am going to show how to set up a new Dreamweaver site using the basic site set up, set up a database on a Linux based server utilizing CPanel and then how to connect to the database.

Approximate download size: 26MB

mySQL Groupies and Subcategories
Reader Level: Reader Level

You need to get all of the categories for each product listed in a report - doing the heavy lifting in PHP seems to take the server extra time to get the work done. Learn about using the GROUP_CONCAT command in mySQL to make quick work of this problem.

Copy a Record in PHP Using Dreamweaver
Reader Level: Reader Level

A quick and easy way to copy a record, edit the record contents and insert it as a new record in to your database. By using Dreamweaver server behaviors, this process is a snap!

Indexing Your Database
Reader Level: Reader Level

In a previous article we looked at ways to make your SQL Server stored procedures more efficient, thereby contributing to the overall performance of your application. In this article, let's look at another database level optimization: the proper indexing of your tables.

Indexing can be a complex topic, and we will not try to cover it all here, but there are a few things to know about indexing that can vastly improve the performance of your database as it grows. There are three types of indexes that we will consider in this article: Column Indexes, Clustered Indexes and Compound Indexes.

Save Time with MySQL Temporary Tables
Reader Level: Reader Level

What happens when you try to work with data from multiple sources? How do you sort through the data and avoid duplicate records? A manual approach will be time consuming and resource intensive. A faster and easier solution is to let MySQL do the work for us.

Quick Shot - Reset the Root mySQL Password Free!
Reader Level: Reader Level

You have lost the root password, or the password is corrupt, to your mySQL server and you need to get it back as quickly as possible. Read this tutorial to get the instructions on how!

Getting the Date In and Out of Your MySQL Database
Reader Level: Reader Level

Very often, it is the case that the date in which the user wishes to enter their information on the form is not the same date format that the database understands. Likewise, getting the date out in the format the database stores it in is not very friendly or readable. We will go over two functions which will assist in getting the date data in the database correctly and displaying it on the web page correctly as well.

Is it read yet?
Reader Level: Reader Level

When you browse the Community MX articles, have you noticed the details where it tells you if you've read it before or not? Do you want to do that on your site? Read on...

Create a Simple Database Web Search - Part 1
Reader Level: Reader Level

Putting together a simple database search is a piece of cake using built-in Dreamweaver tools -- no coding required. We'll show a simple Master/Detail Page Set behavior and how to add a simple search form to it. This tutorial will work with any Dreamweaver server model. Part 2 will focus on PHP and show a more advanced search.

The Creating A Simple Database Web Search Series:
Creating a Simple Database Web Search - Part 1
Creating a Simple Database Web Search - Part 2: PHP
Creating a Simple Database Web Search - Part 2: ColdFusion

The SQL CASE Statement
Reader Level: Reader Level

If you are using SQL, you are no doubt familiar with SELECT, INSERT, UPDATE, and DELETE, as well as a few functions that are useful. I've found that not many people are making active use of the CASE statement, although it is one of the most useful SQL keywords in existence. Typically a web application developer will use this type of conditional logic in his page code (using PHP, ColdFusion, or another language) making the business logic part of the presentation of the page. It is more efficient and better programming practice to put this logic in the database using a stored procedure or in the SQL statement so that the presentation of the data can be as clean and unencumbered by business logic as possible.

This article will show a few simple uses of the statement and how you can use it to simply web applications. These examples should work in SQL Server or MySQL. I will be using the Northwind database that comes free with SQL Server. Anyone using mySQL can download a Northwind creation script at my site.

SQL JOINS: The RIGHT JOIN
Reader Level: Reader Level

In this tutorial we will learn how to utilise the SQL RIGHT JOIN to gather information from two different tables.

The SQL Joins Series:
SQL Joins: The INNER JOIN
SQL Joins: The LEFT JOIN
SQL Joins: The RIGHT JOIN

SQL Joins: The LEFT JOIN
Reader Level: Reader Level

In this tutorial we will learn how to utilise the SQL LEFT JOIN to gather information from two different tables.

The SQL Joins Series:
SQL Joins: The INNER JOIN
SQL Joins: The LEFT JOIN
SQL Joins: The RIGHT JOIN

SQL Joins: The INNER JOIN Free!
Reader Level: Reader Level

In this article we will begin to look at what is meant by a JOIN in SQL. I'm sure you have all heard of joins but what exactly are they and why do we need them? This article will be the first in a series of articles that look at the mystical world of SQL joins. I'll begin with the INNER JOIN, which is likely the most common of all the joins.

The SQL Joins Series:
SQL Joins: The INNER JOIN
SQL Joins: The LEFT JOIN
SQL Joins: The RIGHT JOIN

Multiple Insert/Update in PHP - Part 2
Reader Level: Reader Level

Dreamweaver has some built-in tools for doing database inserts and updates, but they only handle basic inserts/updates of one record. What if you want to insert multiple records at a time, or update multiple records? Dreamweaver is no help in this case, but using PHP the process is simple. The first part of this tutorial showed two often-used methods for doing multiple inserts. Part 2 will show how to do a multiple update using these two techniques.

The Multiple Insert/Update in PHP Series:
Multiple Insert/Update in PHP - Part 1
Multiple Insert/Update in PHP - Part 2

Generating ATOM feeds with PHP
Reader Level: Reader Level

Web site content syndication is a very commonly used method of sending new content updates via desktop software that is able to read and make sense of the XML languages used in RSS and ATOM. These XML files are generically known as "feeds". They are prevalent in most blogging applications and some forums, but recently they have started to appear on almost every site that is updated on a regular basis.

In this tutorial we will look at generating an RSS feed from a very simple MySQL table using PHP.

Multiple Insert/Update in PHP - Part 1
Reader Level: Reader Level

Dreamweaver has some built-in tools for doing database inserts and updates, but they only handle basic inserts/updates of one record. What if you want to insert multiple records at a time, or update multiple records? Dreamweaver is no help in this case, but using PHP the process is simple.

This tutorial will show two often-used methods for doing multiple inserts and multiple update. The files testinsert.php and testinsert2.php are included in the download package showing the final code for both methods. Part 1 of this series will show how to do inserts and Part 2 will show how to do a multiple update using these two techniques.

The Multiple Insert/Update in PHP Series:
Multiple Insert/Update in PHP - Part 1
Multiple Insert/Update in PHP - Part 2

Deconstructing MySpace.com Part 1 - Social Networking Database Free!
Reader Level: Reader Level

MySpace is the social networking phenomenon that is sweeping the nation. Having recently been sold for US$580 Million, it is plain to see that the format has a value, and indeed, just about everyone I know below the age of 25 has a MySpace account. The reason MySpace works is because it puts the control of the content in the hands of the users, and by catering to the social aspects of the human condition has found itself in an enviable position of mass appeal despite some criticism.

The purpose of this, first of many articles is to deconstruct the application -- in this case, MySpace.com -- and show you how to build your own. I believe that the lessons that can be gleaned from learning how a successful site is constructed are plentiful and valuable. Namely, the ability for the users of your site to connect to each other.

The first thing we will look at is what database structure would be required to implement the social networking aspect of MySpace.com. The examples will be in the context of SQL Server 2005, but the knowledge should be transferable to other RDBMSs.

Searching for Data Using Wildcards in a Stored Procedure
Reader Level: Reader Level

This tutorial demonstrates how to create an ASP.NET page that searches for data in specific columns of a table. The technique described has the added advantage that the user can enter just a fragment corresponding to the data that resides in the table. You'll learn how to use the LIKE keyword and % wildcard in a stored procedure. And you'll see how the use of three Dreamweaver server behaviors nearly eliminates the need for you to write any code yourself!

SQL Tricks with UNION
Reader Level: Reader Level

The SQL UNION keyword is one of those features that goes unused for long periods of time. But when the opportunity presents itself you will find that knowing when, how, and why to use it will provide many benefits. This article will present two examples of when this construct might be useful.
  1. Record Replacement: Substitute records in one table with data from another table. Useful in situations where you don't have a lot of control over the data.
  2. Record Insertion: Insert custom rows in a resultset to make displaying lists easier


Loading Database Tables Into a Query Dynamically
Reader Level: Reader Level

In this tutorial we will look at how we can query a database to discover the names of the tables it contains. Once we have gleaned that information we'll loop through the tables and extract the ones that we need to include in our search facility.

Understanding SQL - Part 6: The SELECT Statement - The LIKE Operator and Wildcards
Reader Level: Reader Level

In this the sixth tutorial in this series we will be taking a look at the LIKE operator and the wildcards that we can use alongside it. The LIKE operator is a very powerful tool, and can be an ideal operator to use when providing users with the ability to search your web site.

The Understanding SQL Series
Understanding SQL - Part 1: The SELECT Statement
Understanding SQL - Part 2: The SELECT Statement - Comparison Operators
Understanding SQL - Part 3: The SELECT Statement - Logical Operators & Clauses
Understanding SQL - Part 4: The SELECT Statement - Evaluation Ordering
Understanding SQL - Part 5: The SELECT Statement - Utilizing the IN & BETWEEN Operators
Understanding SQL - Part 6: The SELECT Statement - The LIKE Operator and Wildcards

Understanding SQL - Part 5: The SELECT Statement - Utilising the IN & BETWEEN Operators
Reader Level: Reader Level

In part five of this series we will further explore the SELECT statement and the WHERE clause, and we will be paying particular attention to the the IN and BETWEEN operators.

We will also take our first look at the DISTINCT keyword and we'll see how it can be used to filter the records our queries return and how it can be used in conjunction with the COUNT() function.

The Understanding SQL Series
Understanding SQL - Part 1: The SELECT Statement
Understanding SQL - Part 2: The SELECT Statement - Comparison Operators
Understanding SQL - Part 3: The SELECT Statement - Logical Operators & Clauses
Understanding SQL - Part 4: The SELECT Statement - Evaluation Ordering
Understanding SQL - Part 5: The SELECT Statement - Utilizing the IN & BETWEEN Operators
Understanding SQL - Part 6: The SELECT Statement - The LIKE Operator and Wildcards

Understanding SQL - Part 4: The Select Statement - Evaluation Ordering
Reader Level: Reader Level

In this tutorial we will see how accepting the default evaluation of SQL operators can lead to unexpected results being returned to the client. We will see how the default evaluation order of logical operators can be overriden using parentheses and nested parentheses.

The Understanding SQL Series
Understanding SQL - Part 1: The SELECT Statement
Understanding SQL - Part 2: The SELECT Statement - Comparison Operators
Understanding SQL - Part 3: The SELECT Statement - Logical Operators & Clauses
Understanding SQL - Part 4: The SELECT Statement - Evaluation Ordering
Understanding SQL - Part 5: The SELECT Statement - Utilizing the IN & BETWEEN Operators
Understanding SQL - Part 6: The SELECT Statement - The LIKE Operator and Wildcards

Creating a Search Engine with iSearch
Reader Level: Reader Level

If you have always wanted to add a search engine to your site, and didn't know how to program one yourself, you might want to download and install iSearch, a ready-made PHP and MySQL driven application that performs searches right on your own server. This tutorial will take you through the installation and the customization (of the style sheet and header and footer includes) of iSearch.

Understanding SQL - Part 3: The Select Statement - Logical Operators & Clauses
Reader Level: Reader Level

In this tutorial we will continue building on the knowledge we have gained on the SELECT in Parts 1 & 2.

We will be looking at how we can use the TOP, WITH TIES and PERCENT clauses and we will also look at logical operators and how we can use the SQL syntax to return the same data using different types of queries.

The Understanding SQL Series
Understanding SQL - Part 1: The SELECT Statement
Understanding SQL - Part 2: The SELECT Statement - Comparison Operators
Understanding SQL - Part 3: The SELECT Statement - Logical Operators & Clauses
Understanding SQL - Part 4: The SELECT Statement - Evaluation Ordering
Understanding SQL - Part 5: The SELECT Statement - Utilizing the IN & BETWEEN Operators
Understanding SQL - Part 6: The SELECT Statement - The LIKE Operator and Wildcards

Understanding SQL - Part 2: The Select Statement & Comparison Operators
Reader Level: Reader Level

In part 2 of this series we will be working with the Northwind database and Microsoft's Query Analyser.

We will be looking further into select statements and the use of comparison operators. We will also touch on logical operators and see the count function at work. We will look at how we can optimise our SQL statements to get better performance and explore when and when not to use the * wildcard.

The Understanding SQL Series
Understanding SQL - Part 1: The SELECT Statement
Understanding SQL - Part 2: The SELECT Statement - Comparison Operators
Understanding SQL - Part 3: The SELECT Statement - Logical Operators & Clauses
Understanding SQL - Part 4: The SELECT Statement - Evaluation Ordering
Understanding SQL - Part 5: The SELECT Statement - Utilizing the IN & BETWEEN Operators
Understanding SQL - Part 6: The SELECT Statement - The LIKE Operator and Wildcards

Working With SQL Server Part 5: Setting Constraints and Defining Diagrams
Reader Level: Reader Level

In this tutorial, we will begin by looking at how you can set up a database diagram within Enterprise Manager. We will then move on and look at how we can set constraints to manage the data we allow to be inserted into our database - both by good table design and using constraint expressions.

Previous and Next Links for Details Page Stored Procedure
Reader Level: Reader Level

If you have used Dreamweaver to create dynamic pages, you are probably familiar with the Repeat Region and the concept of Next/Previous records. You are probably familiar with the Master/Detail pageset concept -- the Master page contains a table listing your records with links that allow you to drill down into a Details page. The Details page gives you the details about a particular record. Unfortunately, the Details page does not allow you to create the Previous/Next links easily. This is often desirable in a site, such as in a photo album, real estate listing, or other type of list where the user might want to remain on a Detail page and simply cycle through the records rather than go back to the Master page again. This tutorial will show how to create a SQL stored procedure that will supply Previous/Next links to any ColdFusion or ASP page.

Indexing a Database Table
Reader Level: Reader Level

Indexes are one of the most important aspects of database design, yet one of the most underused in web applications. A database index can speed up a query by hundreds or thousands of times. Imagine, for example, if the phone book was not alphabetized and you had to find a name. It would takes hours or days to find a name. This is exactly the kind of inefficiency that a database with no index has to contend with. The article will show where to put indexes.

Working With SQL Server - Part 4: Relationships and Foreign Keys
Reader Level: Reader Level

In this tutorial, we will learn more about the Enterprise Manager interface. We will be looking at setting a foreign key and creating a relationship between two tables. We will also look at maintaining data integrity and checking data is suitable for the relationship. This tutorial also contains two videos to help illustrate the process.

Working With SQL Server - Part 3: Making a Remote Connection and Creating Our First Database Table
Reader Level: Reader Level

In this tutorial, we will look at how we can create a new SQL Server group and how we can connect to a remote instance of SQL Server. We'll also design our first database table in Enterprise Manager and investigate the properties we set within that table.

Working With SQL Server Part 2: Exploring the EM and Tables
Reader Level: Reader Level

The aim of this tutorial is to understand the flow of the dynamic data in our web development projects. We'll begin by looking at where the database fits into the grand scheme of things, and then look into how the data is handled and processed by our applications.

Once we have achieved these goals we'll move on to explore what a database is and look at the tables it contains. We'll also begin to explore the Enterprise Manager GUI.

Working With SQL Server Part 1: Installation and Service Access
Reader Level: Reader Level

A walk through installing a local instance of SQL Server 2000 for development work. We'll also look at the Properties dialogue box and see what options we have for how we interact with the server instance.

Dynamic Duo: JSP and MySQL
Reader Level: Reader Level

These days, no one would argue that a dynamic site is far more powerful, flexible, and scalable than a static site. But if you have a lot of static pages in your existing site, you might not know how to convert them in order to take advantage of the benefits of a dynamic site. This tutorial will show you how to do just that, by taking some existing static HTML pages, and converting them to Java Server Pages (JSP) using Dreamweaver MX 2004 and a MySQL database.

Get That Code Into The Database Where It Belongs
Reader Level: Reader Level

This article will show how you can take some complex scripting logic out of your web pages, and put it into the database. Why would you want to do this? There are several advantages: the code will usually execute faster, the page code will be easier to read and maintain, and there will be a clearer separation between business logic and presentation logic. The concepts in the article will apply equally to all types of server languages.

Working with Microsoft's Query Analyser
Reader Level: Reader Level

In this tutorial, we will take a look at Microsoft's Query Analyser and Enterprise Manager. We will use the Query Analyzer to create a database, and then to create and relate tables. We will also look at the different start-up options we can use with our instance of SQL Server. This tutorial contains video demos.

Database Design: Introducing Relationships and Queries
Reader Level: Reader Level

In this tutorial, we will look at some of the problems we may encounter when designing our database, we will investigate primary keys, foreign keys and how we can avoid NULL values. We will also look at the WHERE clause and see how we can filter our information by using variables. We will use the repeat region server behavior and look at how we can use and set up dynamic list menus. Further to this we will also look at the ColdFusion isdefined function to ensure that information is only displayed to our end user at the appropriate time. This tutorial contains written and video instruction.

Working with MySQL
Reader Level: Reader Level

Learn some helpful pointers for working with MySQL, including creating databases, managing data, and migrating from server to server.

Comparison Shopping, using the IN statement in SQL
Reader Level: Reader Level

Your client has seen it when looking for their next computer, or next car depending on what has broken down most recently. You know those types of pages where you are presented with a number of options and you want to narrow down their search a little more, so you check the boxes next to the items you're interested in and then off to the next page listing only those items as perhaps a little more information on each item. And now your client wants this same functionality on their site. After you work through this tutorial, you'll be able to tell them it'll take about 5 minutes. That's right. In Dreamweaver you can have both pages described above working in 5 minuets or less (of course, not counting the 40+ things the clients wants to change about that shade of blue you chose for the menu background while you're at it). Read on…

Porting Pollster to SQL Server Free!
Reader Level: Reader Level

One of the most popular widgets in Macromedia's DevNet Resource Kit Volume 4 (DRK 4) is Pollster. This tutorial includes everything you need to migrate Pollster to SQL Server, including a SQL script and instructions on revising the application's ColdFusion components.

Check for duplicate database entries
Reader Level: Reader Level

You may have a database in which you have duplicate entries in a particular column. This may be by design, or possibly by accident. If you've inherited the site from someone else, you may not be aware of this duplicate data. Or perhaps you are aware, but you'd like to see what or where this data is. This tutorial will allow you to build a page that lists only duplicate entries from a column in your database.