|By Jeffry Houser||
|April 13, 2005 12:00 AM EDT||
You won't get very far while building ColdFusion applications without the need for a relational database. Since ColdFusion is so easy to use, many developers come from non-programming based backgrounds, and proper database design remains a mystery.
Perhaps you've worked on other applications, such as a spreadsheet application in Microsoft Excel or used an Access database with a single table to store data. Both of these options serve their purpose, however they are not the best choice for web applications. In this architecture focus issue, I wanted to take some time to introduce you to relational database concepts.
Understanding the Terms
Before I start blabbing about database this and database that, I want to make sure you understand what I'm saying. So let's start by defining some common terms that you should be familiar with.
- Database: A database is any collection of related data. It could be as simple as a grocery list or as complex as a full Enterprise Resource Planning application. The database is made up of many elements, starting with...
- Tables: A table is similar to a single spreadsheet. A relational database is made of multiple tables. Tables are made up of columns and rows. A column represents a single piece of data, such as a name, zip code, or street address. A row represents a single set of all columns. No two rows within a table can be identical. You can relate tables together using ...
- Keys: There are two types of keys in a relational database. A primary key is a column, or group of columns, that can uniquely identify a single row in the table. A foreign key is a column in one table that can be used to uniquely identify the row from another table. It is through the use of primary and foreign keys that you define relations between tables.
Normal forms are a way to check that your database structure is correct. There are seven different levels of normal forms and each normal form exists to avoid a certain anomalies, that will not allow you to insert, or delete, data without also inserting or deleting a piece of unrelated data. You probably don't need to know specifics about the each level of normal forms. When developing a database, you just want to think about storing each piece of data only one time. You don't want duplicates. In your table structure, have you duplicated data somewhere? If so, you may want to re-work your structure so that you don't.
This will probably make more sense with an example. Suppose you were writing a program to catalog your CDs. You might start with a list of sample data, maybe something like Table 1. This is a table with four columns: Artist, Album Name, Genre, and AlbumID. The AlbumID is intended to be the primary key of this table. In a real application, you'll probably have a lot more data, such as a song list for each album, release dates, or the names of band members. We'll keep it simple for this example, though. If you examine the data, you'll notice some places where the data is duplicated. The artist name, Guster appears twice. The genres Grunge, and Alternative appear twice. If you were building an on-line record store, you would not want to store the genre or artist name a lot of times.
This table also exhibits insertion and deletion anomalies, which were discussed earlier. What happens if you want to delete the Bishop Allen album? You will also inadvertently delete the "Rock" genre. That is a deletion anomaly. What if you wanted to create a genre for blues? You wouldn't be able to do so without also entering an album. That is an insertion anomaly. You want to build your tables to avoid these sorts of issues. So, how do you do it?
Well, in this situation, you may first want to separate the Genre into its own table. You can see the genre table in Table 2. I added a GenreID column to the table. This is an integer column intended to be the primary key of the table. We can also split out the artist information into a separate table, as shown in Table 3. The table has two columns, a primary key named ArtistID and an artist column. With the artist and genre information moved into their own tables, what does your original album table look like? There isn't much left, just a primary key and an album name. However, you'll still want to preserve the relationships between the album, genre, and artist tables. How do you do this? You take the primary key of the genre and artist tables and put then in the album table. Our updated album table is shown in Table 4.
Why is this different? Well, it takes less disk space to store an integer than it does text. While you probably won't notice any problems in tables with just a few rows, the difference becomes much greater when you are dealing with larger amounts of data, such as a song database with a thousand records, such as iTunes. Each little bit starts to add up.
There are really three different types of relationships that come into play when putting your data into tables. The first type is called a one-to-one relationship. This means that for any single piece of data A, there will only be a single piece of data B. If A, were a username, then B might be a password. For every username, there must be only one password and for every password there must be only one username. In most one to one relationships the data is stored in the same table. If for some reason you are splitting the data between two tables, you can represent the relationship by moving the primary key from either table into the other table as a foreign key.
The next type of relationship is a one-to-many relationship. This means for every piece of data A, there will be multiple pieces of data B. For every piece of data B, there will only be one piece of a data A. A good example of this is the artist/album, which we described above. For every artist, there may be multiple albums. But, each album only has a single artist. (For the sake of this example we are ignoring multi band compilations). You can represent one-to-many relationships by taking the primary key of the "one" side and put it into the table of the "many" side as a foreign key. This is what we did to split up the album and artist tables. Our example, above, created the genres and albums relationship as one-to-many.
The third type of relationship is a many-to-many relationship. This means that for every piece of A data there will be multiple pieces of B data, and for every piece of B data there will be multiple pieces of A data. Perhaps, you've got the Aerosmith album. It's rock. It's blues. Where do you categorize it? The Genre relationship to an album could be a many-to-many relationship. To implement this type of relationship in the database, we create a special type of table, often called an intersection or linking table. This table does not usually contain any data, only the primary keys of the two tables that it is linking. To implement a many-to-many relationship between genres and albums, we would use the GenreID from the albums table and create a new table, as shown in Table 5.
I know it looks like a table of numbers, and that's what it is. The primary key of intersection tables is usually made up of all the columns in it.
Common Database Design Mistakes
Before wrapping up this column, I want to finish off by pointing out some mistakes I often see beginner developers making. All of these are obvious in hindsight, but you probably don't realize you did it "wrong" until you have a problem and the light bulb inside in your head brightens up, and "Uh-oh" escape from your lips.
- Names: You have a site registration, or an address book application, or something that requires you to collect and store the names of your users. Make sure that you store the first name and last name as separate columns in a database table, do not combine them. If the data is being collected, at some point you are going to be asked to do a mail merge. When you do that, it'll be a lot easier to do if you have the first and last names separate, so you can address people as "Mr Houser" instead of "Mr Jeff Houser."
- Deleting Data: It's easy to write a delete statement in SQL, but what happens when your client or boss calls up to ask where their data went? If the data is truly deleted, you have no way to restore it. If you're lucky you have backup tapes, from which you can restore yesterday's data, but that can get messy. A better way is to not ever allow users to directly delete data. Create a Boolean field in your database table called Deleted. If set to 1, the record is flagged for deletion. If set to zero, the record is fine. You can run batch scripts on a routine basis to delete the data, as needed. When the user calls up to find out where their data is located, you can just flip that flag to restore it for them.
- Store the Date: At some point, someone is going to want to look at the data you've been collecting through the web site. When are people registering on the site? When was the last time they modified their information? On most tables, I will add a "DateCreated" field to store the time that the record in the database was created, and a "DateLastModified" field to store the time the data was last modified. On some projects, I've had a few "higher ups" quite shocked that this data was not being collected.
- Define Relationships: You should always make sure you use the built-in facilities of your database to specify keys, and define relationships between tables. In addition to helping you protect your data from inadvertent corruption, the database engine can often use these relationships and keys to automatically optimize queries. I've had quite a few sleepless nights trying to fix the invalid data that had resulted from deleting one piece of data, without deleting data that relates to it. For example, what if we deleted a genre, but did not delete the entries in our intersection table that related to that genre? Something is going to break somewhere.
The relational database is the center of most advanced applications, web-based or otherwise. Some of the more common databases used in ColdFusion development are SQL Server, MySQL, and PostgreSQL. Oracle often shows up on sites with larger load, and Access will sometimes show up on smaller sites. I would recommend putting aside some time to learn about the database of your choice, because many of the skills you learn can easily be transferred to all database platforms.
SYS-CON Events announced today that Vicom Computer Services, Inc., a provider of technology and service solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. They are located at booth #427. Vicom Computer Services, Inc. is a progressive leader in the technology industry for over 30 years. Headquartered in the NY Metropolitan area. Vicom provides products and services based on today’s requirements around Unified Networks, Cloud Computing strategies, Virtualization around Software defined Data Ce...
Apr. 18, 2015 02:00 PM EDT Reads: 1,349
SYS-CON Events announced today that Tufin, the market-leading provider of Security Policy Orchestration Solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. As the market leader of Security Policy Orchestration, Tufin automates and accelerates network configuration changes while maintaining security and compliance. Tufin's award-winning Orchestration Suite™ gives IT organizations the power and agility to enforce security policy across complex, multi-vendor enterprise networks. With more than 1...
Apr. 18, 2015 01:45 PM EDT Reads: 3,245
SYS-CON Events announced today that Optimal Design, an Internet of Things solution provider, will exhibit at SYS-CON's Internet of @ThingsExpo, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Optimal Design is an award winning product development firm offering industrial design and engineering services to the consumer, medical, and defense markets.
Apr. 18, 2015 01:45 PM EDT Reads: 1,579
SYS-CON Events announced today that MangoApps will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY., and the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. MangoApps provides private all-in-one social intranets allowing workers to securely collaborate from anywhere in the world and from any device. Social, mobile, and easy to use. MangoApps has been named a "Market Leader" by Ovum Research and a "Cool Vendor" by Gartner...
Apr. 18, 2015 01:15 PM EDT Reads: 3,533
SYS-CON Events announced today that Cloudian, Inc., the leading provider of hybrid cloud storage solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Cloudian, Inc., is a Foster City, California - based software company specializing in cloud storage software. The main product is Cloudian, an Amazon S3-compliant cloud object storage platform, the bedrock of cloud computing systems, that enables cloud service providers and enterprises to build reliable, affordable and scalable cloud storage solu...
Apr. 18, 2015 01:00 PM EDT Reads: 2,313
SYS-CON Events announced today that Gridstore™, the leader in hyper-converged infrastructure purpose-built to optimize Microsoft workloads, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Gridstore™ is the leader in hyper-converged infrastructure purpose-built for Microsoft workloads and designed to accelerate applications in virtualized environments. Gridstore’s hyper-converged infrastructure is the industry’s first all flash version of HyperConverged Appliances that include both compute and storag...
Apr. 18, 2015 12:45 PM EDT Reads: 4,178
SYS-CON Events announced today that Creative Business Solutions will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Creative Business Solutions is the top stocking authorized HP Renew Distributor in the U.S. Based out of Long Island, NY, Creative Business Solutions offers a one-stop shop for a diverse range of products including Proliant, Blade and Industry Standard Servers, Networking, Server Options and Care Packs. As a trusted supplier, CBS guarantees quality controlled stock levels thanks to an Auto...
Apr. 18, 2015 12:30 PM EDT Reads: 4,232
How is unified communications transforming the way businesses operate? In his session at WebRTC Summit, Arvind Rangarajan, Director of Product Marketing at BroadSoft, will discuss how to extend unified communications experience outside the enterprise through WebRTC. He will also review use cases across different industry verticals. Arvind Rangarajan is Director, Product Marketing at BroadSoft. He has over 19 years of experience in the telecommunications industry in various roles such as Software Development, Product Management and Product Marketing, applied across Wireless, Unified Communic...
Apr. 18, 2015 12:30 PM EDT Reads: 1,570
What exactly is a cognitive application? In her session at 16th Cloud Expo, Ashley Hathaway, Product Manager at IBM Watson, will look at the services being offered by the IBM Watson Developer Cloud and what that means for developers and Big Data. She'll explore how IBM Watson and its partnerships will continue to grow and help define what it means to be a cognitive service, as well as take a look at the offerings on Bluemix. She will also check out how Watson and the Alchemy API team up to offer disruptive APIs to developers.
Apr. 18, 2015 12:00 PM EDT Reads: 1,422
The IoT Bootcamp is coming to Cloud Expo | @ThingsExpo on June 9-10 at the Javits Center in New York. Instructor. Registration is now available at http://iotbootcamp.sys-con.com/ Instructor Janakiram MSV previously taught the famously successful Multi-Cloud Bootcamp at Cloud Expo | @ThingsExpo in November in Santa Clara. Now he is expanding the focus to Janakiram is the founder and CTO of Get Cloud Ready Consulting, a niche Cloud Migration and Cloud Operations firm that recently got acquired by Aditi Technologies. He is a Microsoft Regional Director for Hyderabad, India, and one of the f...
Apr. 18, 2015 12:00 PM EDT Reads: 934
The 17th International Cloud Expo has announced that its Call for Papers is open. 17th International Cloud Expo, to be held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, APM, APIs, Microservices, Security, Big Data, Internet of Things, DevOps and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal today!
Apr. 18, 2015 12:00 PM EDT Reads: 2,051
SYS-CON Events announced today that IDenticard will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. IDenticard™ is the security division of Brady Corp (NYSE: BRC), a $1.5 billion manufacturer of identification products. We have small-company values with the strength and stability of a major corporation. IDenticard offers local sales, support and service to our customers across the United States and Canada. Our partner network encompasses some 300 of the world's leading systems integrators and security s...
Apr. 18, 2015 12:00 PM EDT Reads: 4,878
With IoT exploding, massive data will transform businesses with opportunities to monetize almost anything that can be measured. In this C-Level Roundtable Discussion at @ThingsExpo, Brendan O’Brien, Aria Systems Co-founder and Chief Evangelist, will lead an expert panel of consultants, thought leaders and practitioners who will look at these new monetization trends, discuss the implications, and detail lessons learned from their collective experience. Finally, the panel will point the way forward for enterprises who wish to leverage the resulting complex recurring revenue models, adding valu...
Apr. 18, 2015 11:00 AM EDT Reads: 1,409
SYS-CON Events announced today that Ciqada will exhibit at SYS-CON's @ThingsExpo, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Ciqada™ makes it easy to connect your products to the Internet. By integrating key components - hardware, servers, dashboards, and mobile apps - into an easy-to-use, configurable system, your products can quickly and securely join the internet of things. With remote monitoring, control, and alert messaging capability, you will meet your customers' needs of tomorrow - today! Ciqada. Let your products take flight. For more inform...
Apr. 18, 2015 07:00 AM EDT Reads: 1,567
SYS-CON Events announced today that GENBAND, a leading developer of real time communications software solutions, has been named “Silver Sponsor” of SYS-CON's WebRTC Summit, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. The GENBAND team will be on hand to demonstrate their newest product, Kandy. Kandy is a communications Platform-as-a-Service (PaaS) that enables companies to seamlessly integrate more human communications into their Web and mobile applications - creating more engaging experiences for their customers and boosting collaboration and productiv...
Apr. 18, 2015 06:00 AM EDT Reads: 2,240
SYS-CON Events announced today that BroadSoft, the leading global provider of Unified Communications and Collaboration (UCC) services to operators worldwide, has been named “Gold Sponsor” of SYS-CON's WebRTC Summit, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. BroadSoft is the leading provider of software and services that enable mobile, fixed-line and cable service providers to offer Unified Communications over their Internet Protocol networks. The Company’s core communications platform enables the delivery of a range of enterprise and consumer calling...
Apr. 18, 2015 05:30 AM EDT Reads: 2,169
VoxImplant has announced full WebRTC support in the newest versions of its Android SDK and iOS SDK. The updated SDKs, which enable audio and video calls on mobile devices, are now compatible with the WebRTC standard to allow any mobile app to communicate with WebRTC-enabled browsers, including Google Chrome, Mozilla Firefox, Opera, and, when available, Microsoft Spartan. The WebRTC-updated SDKs represent VoxImplant's continued leadership in simplifying the development of real-time communications (RTC) services for app developers. VoxImplant (built by Zingaya, the real-time communication servi...
Apr. 18, 2015 02:45 AM EDT Reads: 1,794
SYS-CON Events announced today that AIC, a leading provider of OEM/ODM server and storage solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. AIC is a leading provider of both standard OTS, off-the-shelf, and OEM/ODM server and storage solutions. With expert in-house design capabilities, validation, manufacturing and production, AIC's broad selection of products are highly flexible and are configurable to any form factor or custom configuration. AIC leads the industry with nearly 20 years of ...
Apr. 18, 2015 12:15 AM EDT Reads: 4,663
Buzzword alert: Microservices and IoT at a DevOps conference? What could possibly go wrong? Join this panel of experts as they peel away the buzz and discuss the important architectural principles behind implementing IoT solutions for the enterprise. As remote IoT devices and sensors become increasingly intelligent, they become part of our distributed cloud environment, and we must architect and code accordingly. At the very least, you’ll have no problem filling in your buzzword bingo cards.
Apr. 16, 2015 05:30 PM EDT Reads: 2,101
Internet of Things (IoT) will be a hybrid ecosystem of diverse devices and sensors collaborating with operational and enterprise systems to create the next big application. In their session at @ThingsExpo, Bramh Gupta, founder and CEO of robomq.io, and Fred Yatzeck, principal architect leading product development at robomq.io, will discuss how choosing the right middleware and integration strategy from the get-go will enable IoT solution developers to adapt and grow with the industry, while at the same time reduce Time to Market (TTM) by using plug and play capabilities offered by a robust I...
Apr. 13, 2015 12:15 PM EDT Reads: 1,875