background preloader

Database Design

Facebook Twitter

Database Normalization Basics. If you've been working with databases for a while, chances are you've heard the term normalization. Perhaps someone's asked you "Is that database normalized? " or "Is that in BCNF? " All too often, the reply is "Uh, yeah. " Normalization is often brushed aside as a luxury that only academics have time for. However, knowing the principles of normalization and applying them to your daily database design tasks really isn't all that complicated and it could drastically improve the performance of your DBMS. In this article, we'll introduce the concept of normalization and take a brief look at the most common normal forms. What is Normalization?

Normalization is the process of efficiently organizing data in a database. The Normal Forms The database community has developed a series of guidelines for ensuring that databases are normalized. Before we begin our discussion of the normal forms, it's important to point out that they are guidelines and guidelines only. SQL For Dummies Cheat Sheet. Cheat Sheet This Cheat Sheet consists of several helpful tables and lists, containing information that comes up repeatedly when working with SQL.

SQL For Dummies Cheat Sheet

In one place, you can get a quick answer to a number of different questions that frequently arise during an SQL development effort. SQL Criteria for Normal Forms To ensure that database tables are designed in such a way that they will hold your data reliably, you need to be sure that they are not subject to modification anomalies. Normalizing your databases will give you that assurance. First Normal Form (1NF): Table must be two-dimensional, with rows and columns. Second Normal Form (2NF): Table must be in first normal form (1NF).

Third Normal Form (3NF): Table must be in second normal form (2NF). Domain-Key Normal Form (DK/NF): Every constraint on the table is a logical consequence of the definition of keys and domains. SQL Data Types Here’s a list of all the formal data types that ISO/IEC standard SQL recognizes. The only thing I miss from the ER language. The Entity-relationship was (well, still is in the database domain) a popular modeling language to define the (static) conceptual schema of your system.

The only thing I miss from the ER language

UML class diagrams (with a little bit of help from OCL) can be regarded as a superset of the ER language, which explains why ER is slowly disappearing (e.g. some years ago, Extended ER was still taught in database courses while UML was taught in software engineering courses, while now most universities are shifting towards using UML in both kinds of courses).

Nevertheless there is one thing I do miss from my times of ER modeler. The simplicity of defining external identifiers for each type/class by just underscoring the name of the attribute/s that can be used to identify a single instance of the class. You could argue that UML is object-oriented so each instance of a class has its own internal identifier. True, but “humans” don’t work with internal identifiers but with external ones. RISE to Bloome Software - Model Driven Development. FabFORCE.net. 8 Reasons Why MySQL's ENUM Data Type Is Evil - Chris Komlenic. MySQL's ENUM data-type is a hot spot that sometimes generates strong opinions among developers.

8 Reasons Why MySQL's ENUM Data Type Is Evil - Chris Komlenic

At first glance it seems like an efficient solution for declaring a set of permitted values from which only one can be chosen for each record. A good example is a having a table of countries with a 'continent' column: every country belongs to a continent and the seven continents aren't likely to change anytime soon. Yes, one day North America may collide with Asia to form Noramersia, but if your database somehow survives that long at least you won't be around for the meeting on how to restructure your tables.

That will be some new guy's problem. Now, If using ENUM were our only option for representing what continent a country belonged to, we could all move on to debating the merits of NoSQL or whether Git was better than SVN, or why your favorite framework sucks. Wikipedia describes a reference table as: 1. 2. 3. 4. Select color: Now consider the evil ENUM: how do you extract the member list? Database Best Practices. There are things which some believe are wise to do with databases.

Database Best Practices

As with every set of so-called "best practices", there will be disagreement. Some of these tips are subject to considerable debate, and every side of these debates has a wealth of evidence to support it. Therefore, the best advice to the working database practitioner is to be aware of the controversies surrounding each tip, and to apply rational judgement and scientific evaluation to every real-world case. These tips are generally intended to apply to a SQL database, which is typically (and perhaps erroneously) called a RelationalDatabase. They may or may not apply to other paradigms. Creation Scripts For example: To version a database, a person can make SQL scripts and store them under VersionControl (such as SubVersion, sccs, ConcurrentVersionsSystem, StarTeam and so on).

Too Many Small Tables I am bothered by (1:1)-to-(0:1) relationships. SELECT * FROM Customer NATURAL JOIN Order WHERE CustomerID = 23. One (mandatory) to Many [recursive] - db4u.