Beruflich Dokumente
Kultur Dokumente
Start hiring
Login
Top 3%
Why
Clients
Partners
Community
Blog
About Us
Start hiring
Apply as a Developer
Login
Questions?
Contact Us
Search Topics
Hire a developer
#BadPractices #Database
447shares
You are faced normally with confusing tables, views, columns, values, stored procedures, functions, constraints, and triggers
that take a long time to make sense to you. And, once they do, you start noticing many ways to improve and take advantage
of the stored information.
If you are an experienced developer, chances are you will also notice things that could have been done better in the
beginning, i.e., design flaws.
In this article, you will learn about some of the common database design bad practices, why they are bad, and how you can
avoid them.
For example, an industrial information system where data is gathered manually every day will not have the same data model
as an industrial system where information is generated in real time. Why? Because it is very different handling a few
hundreds or thousands of records per month compared with managing millions of them in the same period. Special
considerations must be made by the designers in order to keep the efficiency and usability of the database, if data volumes
are to be big.
But, of course, data volume is not the only aspect to consider, since the purpose of the data also affects the level of
normalization, the data structure, the record size, and the general implementation of the whole system.
Therefore, thoroughly knowing the purpose of the data system you will create leads to considerations in the choice of the
database engine, the entities to design, the record size and format, and the database engine management policies.
Ignoring these goals will lead to designs that are flawed in their basics, although structurally and mathematically correct.
In spite of this, we are often faced with databases that were designed on the fly without following the most basic rules of
normalization. We have to be clear on that: Every database should, at least, be normalized to third normal form, since it is
the layout that will best represent your entities, and whose performance will be best balanced between querying and
inserting-updating-deleting records.
If you stumble with tables that do not comply with 3NF, 2NF, or even 1NF, consider redesigning these tables. The effort you
invest in doing so will pay off in the very short term.
Typical bad effects of redundancy are an unnecessary increase of database size, data being prone to inconsistency, and
decreases in the efficiency of the database, butmore importantlyit may lead to data corruption.
Views that provide a quick and efficient way to look at your data, typically de-normalizing it for query purposes
without losing data correctness.
Indexes that help speed up queries on tables.
Aggregate functions that help analyze information without programming.
Transactions or blocks of data-altering sentences that are all executed and committed or cancelled (rolled back) if
something unexpected occurs, thus keeping information in a perpetually correct state.
Locks that keep data safe and correct while transactions are being executed.
Stored procedures that provide programming features to allow complex data management tasks.
Functions that allow sophisticated calculations and data transformations.
Constraints that help guarantee data correctness and avoid errors.
Triggers that help automate actions when events occur on the data.
Command optimizer (execution planner) that runs under the hood, ensuring that every sentence is executed at its best
and keeping the execution plans for future occasions. This is one of the best reasons to use views, stored procedures,
and functions, since their execution plans are kept permanently in the DBE.
Not knowing or ignoring these capabilities will take development to an extremely uncertain path and surely to bugs and
future problems.
109shares
Bad Practice No. 6: Composite Primary Keys
This is sort of a controversial point, since many database designers talk nowadays about using an integer ID auto-generated
field as the primary key instead of a composite one defined by the combination of two or more fields. This is currently
defined as the best practice and, personally, I tend to agree with it.
However, this is just a convention and, of course, DBEs allow the definition of composite primary keys, which many
designers think are unavoidable. Therefore, as with redundancy, composite primary keys are a design decision.
Beware, though, if your table with a composite primary key is expected to have millions of rows, the index controlling the
composite key can grow up to a point where CRUD operation performance is very degraded. In that case, it is a lot better to
use a simple integer ID primary key whose index will be compact enough and establish the necessary DBE constraints to
maintain uniqueness.
On the other hand, having a table with no index on columns that are used to query it will, as we all know, lead to poor
performance on SELECTs.
Also, index efficiency depends sometimes on the column type; indexes on INT columns show the best possible performance,
but indexes on VARCHAR, DATE or DECIMAL (if it ever makes sense) are not as efficient. This consideration can even
lead to redesigning tables that need to be accessed with the best possible efficiency.
Therefore, indexing is always a delicate decision, as too much indexing can be as bad as too little and because the data type
of the columns to index on have a big influence on the final outcome.
The table name must describe what entity it holds, and each column name must describe what piece of information it
represents. This is easy, but it starts to be complicated when tables have to relate to each other. Names start to become messy
and, worse, if there are confusing naming conventions with illogical norms (like, for instance, column name must be 8
characters or less). The final consequence is that the database becomes unreadable.
Therefore, a naming convention is always necessary if the database is expected to last and evolve with the application it
supports, and here are some guidelines to establish a succinct, simple, and readable one:
No limitations on table or column name size. It is better to have a descriptive name than an acronym that no one
remembers or understands.
Names that are equal have the same meaning. Avoid having fields that have the same name but with different types or
meanings; this will be confusing sooner or later.
Unless necessary, dont be redundant. For example, in the table Item, there is no need to have columns like
ItemName, PriceOfItem, or similar names; Name and Price are enough.
Beware of DBE reserved words. If a column is to be called Index, which is a SQL reserved word, try to use a
different one like IndexNumber.
If sticking to the simple primary key rule (single integer auto generated), name it Id in every table.
If joining to another table, define the necessary foreign key as an integer, named Id followed by the name of the
joined table (e.g., IdItem).
If naming constraints, use a prefix describing the constraint (e.g., PK or FK), followed by the name of the table or
tables involved. Of course, using underscores (_) sparingly helps make things more readable.
To name indexes, use the prefix IDX followed by the table name and the column or columns of the index. Also, use
UNIQUE as a prefix or suffix if the index is unique, and underscores where necessary.
There are many database naming guidelines on the internet that will shine more light on this very important aspect of
database design, but with these basic ones, you can at least get to a readable database. What is important here is not the size
or the complexity of your naming guidelines but your consistency in following them!
There are good database design guidelines all over the internet as well as bad practices and things to avoid in database
design. Just take your pick and stick to it.
And, dont forget, it is only through experimentation, mistakes, and successes that you learn, so go ahead and start now.
109shares
Trending articles
Fastlane: iOS Automation on Cruise Control2 days agoMagento 2: Revision or Revolution?3 days agoGetting Started with
the Elm Programming Language9 days agoGraphQL vs. REST - A GraphQL Tutorial12 days agoTips to Attract, Manage,
and Retain Software Developers16 days agoGetting Started with TensorFlow: A Machine Learning Tutorial17 days
agoQuick Wins in the Enterprise With Salesforce AppExchange24 days agoFrom Solving Equations to Deep Learning: A
TensorFlow Python Tutorial25 days ago
Relevant Technologies
Database
SQL
MySQL
MSSQL
PostgreSQL
Fernando Martinez
SQL Developer
Fernando is a systems and computing engineer who graduated from the University of Los Andes in 1987 and has worked in
software development ever since. He started developing in C on UNIX operating system with ORACLE SQL database.
Fernando has kept his skills up-to-date and has developed in Java, C#, SQL Server, and more.
Toptal Developers
Android Developers
AngularJS Developers
Back-End Developers
C++ Developers
Data Scientists
DevOps Engineers
Ember.js Developers
Freelance Developers
Front-End Developers
Full Stack Developers
HTML5 Developers
iOS Developers
Java Developers
JavaScript Developers
Machine Learning Engineers
Magento Developers
Mobile App Developers
.NET Developers
Node.js Developers
PHP Developers
Python Developers
React.js Developers
Ruby Developers
Ruby on Rails Developers
Salesforce Developers
Scala Developers
Software Developers
Unity or Unity3D Developers
Web Developers
WordPress Developers
About
Top 3%
Clients
Freelance Developers
Freelance Designers
Freelance Finance Experts
About Us
Contact
Contact Us
Press Center
Careers
FAQ
Social
Facebook
Twitter
Google+
LinkedIn
Toptal
Privacy Policy
Website Terms
Home Blog Bad Practices in Database Design: Are You Making These Mistakes?
Hiring? Toptal handpicks top database developers to suit your needs.
Start hiring
Login