15
NOSQL VS SQL DIFFERENCE BETWEEN NOSQL & SQL @MOHAMMED FAZULUDDIN

NOSQL vs SQL

Embed Size (px)

Citation preview

Page 1: NOSQL vs SQL

NOSQL VS SQLDIFFERENCE BETWEEN NOSQL & SQL

@MOHAMMED FAZULUDDIN

Page 2: NOSQL vs SQL

OVERVIEW• NoSQL is a category of databases distinctly different from SQL databases.

• SQL Server and relational databases (RDBMS) have been the go-to databases for over 20 years.

• NoSQL databases that enable storing unstructured and heterogeneous data at scale have gained in popularity.

• There are a number of technologies in the NoSQL category, including document databases, key value stores, column family stores, and graph databases, which are popular with gaming and social.

• SQL databases are primarily called as Relational Databases (RDBMS); whereas NoSQL database are primarily called as non-relational or distributed database.

• SQL databases have predefined schema whereas NoSQL databases have dynamic schema for unstructured data.

• SQL databases are not best fit for hierarchical data storage. But, NoSQL database fits better for the hierarchical data storage as it follows the key-value pair way of storing data similar to JSON data.

Page 3: NOSQL vs SQL

OVERVIEW

Page 4: NOSQL vs SQL

NOSQL VS MYSQL

• Model:

• NoSQL:

• Non-relational data model.

• Stores Data in JSON documents, key/value pairs, wide column stores or graphs.

• SQL:

• Relational data model.

• Stores data in table.

Page 5: NOSQL vs SQL

NOSQL VS MYSQL• Data:

• NoSQL:

• Offers flexibility as not every record needs to store the same properties.

• New properties can be added on the fly.

• Good for semi structure, complex and nested data.

• Relation captured by denormalizing data and presenting data in single object in a single record.

• SQL:

• Used where the solution for every record has same property.

• Adding properties may require altering schema or backfilling of data.

• Good for structured data.

• Relations are captured in normalized model using joins to resolve reference across the tables.

Page 6: NOSQL vs SQL

NOSQL VS MYSQL• Schema:

• NoSQL:

• In a NoSQL database, data can be added anywhere and at any time, dynamic or flexible schema.

• Database is schema-agnostic and the schema is dictated by the application. This allows for agility and highly iterative development.

• SQL:

• Strict Schema, it’s impossible to add data until you define tables and field types in what’s referred to as a schema.

• Your data schema must be designed and implemented before any business logic can be developed to manipulate data. It’s possible to make updates later, but large changes can be complicated.

• Schema must be maintained and kept in sync between application and database.

Page 7: NOSQL vs SQL

NOSQL VS MYSQL• Consistence and Availability:

• NoSQL:

• Eventual to strong consistency supported, depending on solution.

• CAP(Consistence, Availability and Performance) theorem be traded to meet the needs of the application.

• SQL:

• Strong consistency enforced.

• Consistency is prioritized on the availability and performance.

Page 8: NOSQL vs SQL

NOSQL VS MYSQL• Performance:

• NoSQL:

• Performance can be increase by reducing the consistency, if needed.

• All information related to the entity is typically in a single record, so an update can happen in one operation.

• SQL:

• Insert and update performance is depending upon how fast write is committed, as string consistence is enforced. Performance can be increased by scaling up available resources and using in-memory structure.

• Information about entity may be spread across many tables and rows, requiring many joins to complete an update or a query.

Page 9: NOSQL vs SQL

NOSQL VS MYSQL• Transactions:

• NoSQL:

• ACID transactions support varies per solution.

• SQL:

• Supports ACID transactions.

• Scale:

• NoSQL:

• Scaling is typically achieved horizontally with data partitioning to span servers.

• SQL:

• Scaling is typically achieved vertically with more server resources.

Page 10: NOSQL vs SQL

NOSQL VS MYSQL

• Support:• NoSQL:

• NoSQL database you still have to rely on community support, and only limited outside experts are available for you to setup and deploy your large scale NoSQL deployments.

• SQL:

• Excellent support are available for all SQL database from their vendors.

• There are also lot of independent consultations who can help you with SQL database for a very large scale deployments.

Page 11: NOSQL vs SQL

NOSQL VS MYSQL• Data Integrity:

• NoSQL:

• The same data integrity options are not available in NoSQL databases; you can store what you want regardless of any other documents. Ideally, a single document will be the sole source of all information about an item.

• SQL:

• Most SQL databases allow you to enforce data integrity rules using foreign key constraints (unless you’re still using the older, defunct MyISAM storage engine in MySQL).

• The schema enforces these rules for the database to follow. It’s impossible for developers or users to add, edit or remove records, which could result in invalid data or orphan records.

Page 12: NOSQL vs SQL

NOSQL VS MYSQL

• Joins:• NoSQL:

• NoSQL has no equivalent of JOIN, and this can shock those with SQL experience. If we used normalized collections as described above, we would need to fetch all book documents, retrieve all associated publisher documents, and manually link the two in our program logic. This is one reason denormalization is often essential.

• SQL:

• SQL queries offer a powerful JOIN clause. We can obtain related data in multiple tables using a single SQL statement.

Page 13: NOSQL vs SQL

SAMPLE QUERY SYNTAX OF SQL & NOSQLSQL NoSQL

insert a new book recordINSERT INTO book ( `ISBN`, `title`, `author` )

VALUES ( '9780992461256', 'Full Stack JavaScript', 'Colin Ihrig & Adam Bretz' );

db.book.insert({ ISBN: "9780992461256", title: "Full Stack JavaScript", author: "Colin Ihrig &

Adam Bretz" });

update a book record

UPDATE book SET price = 19.99 WHERE ISBN = '9780992461256'

db.book.update( { ISBN: '9780992461256' }, { $set: { price: 19.99 } } );

Page 14: NOSQL vs SQL

SUMMARY• Projects where SQL is ideal:

• Logical related discrete data requirements which can be identified up-front.

• Data integrity is essential.

• Standards-based proven technology with good developer experience and support.

• Projects where NoSQL is ideal:• Unrelated, indeterminate or evolving data requirements.

• Simpler or looser project objectives, able to start coding immediately.

• Speed and scalability is imperative.

Page 15: NOSQL vs SQL

THANK YOU