background preloader

Sql

Facebook Twitter

Sqlserver

Database Normalization and Table Structures. Unfortunately, this is not quite correct.

Database Normalization and Table Structures

To give a quick summary, the normal forms are as follows: 1NF: Every row must be an identifiable relation. This means that, in a table, no row may be an exact duplicate of another row, and nor may the row be completely filled with NULL. 2NF All non-key attributes of the table must depend on the entire key. This means that, when a table has a compound key, attributes which depend only on a subset of the key columns should be moved out of the table. For example, take the comment above which mentions a compound primary key of OrderID and LineNo; if the application wants to use invoice_bgcolor to alternate the background color of rows on an invoice, it should go outside of this table, because it depends on LineNo but not on OrderID 3NF You have 3NF pretty much correct above.

Finally, as stated above, a table must meet all previous normal forms, ie: 2NF implies 1NF, 5NF implies 4NF, 3NF, BCNF, 2NF, 1NF, etc. A database is normalized if it is in 5NF. History Tables. A history table allows you to use one table to track changes in another table.

History Tables

While the basic idea is simple, a naive implementation will lead to bloat and will be difficult to query. A more sophisticated approach allows easier queries and can produce not just information about single rows, but can also support aggregrate company-wide queries. This week in the Database Programmer Blog we return to table design patterns with an essay on history tables. The basic premise of this blog is that good coding skills do not lead magically to good database skills -- you can only make optimal use of a database by understanding it on its own terms. There is a new essay each Monday, and there is a Complete Table of Contents and a List of Table Design Patterns.

What to Put Into A History Table Naive approaches to history tables usually involve making a complete copy of the original (or new) row when something changes in the source table. Next we ask which columns we will definitely not need. Getting Small: Building Lightweight Web Applications with Small- F you've done any open-source database development recently, you probably already know that when it comes to selecting a database for your application, you have a plethora of choices.

Getting Small: Building Lightweight Web Applications with Small-

You are no longer limited to commercial products such as Microsoft SQL Server or Oracle; open-source products such as MySQL and PostgreSQL are viable alternatives, offering similar features at a fraction of the cost. However, while these products have rich, robust feature sets and reduce costs, they're not small—the latest downloadable versions of PostgreSQL and MySQL weigh in at 12 MB and 57 MB respectively. For small-scale applications that have minimal database needs, using any large feature-rich database products is often overkill; it's often more appropriate to use a small-footprint database instead. But what small-footprint databases are available, and how do you use them in a project? Choosing A Database Here's a quick overview of six small-footprint database choices available.