Database – Why are SQL databases still used with ORM

databaseorm

ORMs and persistence ignorance make perfect sense: if I am programming in a language, then I want to use the language's native implementation of objects and data structures to drive my program. I shouldn't need to worry about SQL or a database, and I always thought that inline SQL strings in a program was very cumbersome.

Why is SQL still used as a backend? Why doesn't the ORM just persist objects to XML or a binary file(s) and avoid all the overheads and difficulties of administering a database server?

Best Answer

The answer presented here is a quick answer and is not comprehensive, since the subject is rather big. Your question is about 3 things (at least):

1- Databases

2- SQL

3- ORM Concept

A database is any repository of data. You can store your data wherever is appropriate for your application. SQL is a way to access this data when the data usually, SQL is used to access and manipulate RDBMS. ORM represents a way to access data from within applications using SQL or other means.

My question is: why are we even keeping SQL...

If your database is not a relational database or does not beinfit from what relational database systems, you may not have to use SQL. In the past 30 years relational database have answered so many business needs and it has grown to be robust, efficient and reliable. The conceptual strength has kept this system alive. It has been used in almost all types of applications with great success. Developers have proved that the concept is possible to digest and grown up accustomed to this standard specifically for procedural programming. As a result of this history, relational database systems are where most enterprise data ends up to be. If you are building an application that does not need to integrate with this data, feel free to use a different database model.

Why doesn't the ORM just persist objects to XML or a binary file(s)?

This may work for small databases when concurrent access to data is not required. A relational database allows concurrent access to data, locking, indexing (fast search), as well as many other features that are not in XML file. Take your bank's customer accounts database. If you go to withdraw $20 dollars, the system will need to search for your account quickly and find it among 4 million accounts. If you try to do this sequentially with a file, you will need to read about ((4 million+1)/2) records before you find a match - This is a lot of reads. Also, to update your account after you have done the withdrawal, you will have to write back the entire 4 million rows. Imagine this happening for every customer, then imagine this happening on 300 teller machines at the same time.

The following may be useful reads:

1-Relational Database Components

2-Benefits of Relational Data Model (see the bottom of the page)

3-Is The Relational Database Doomed

Related Topic