Monday, November 7, 2011

SqlServer, Oracle or NoSql?

PROBLEM:
What to choose, SqlServer, Oracle or NoSql?

SOLUTION:
A traditional relational database stores data in rows and columns, in recent years engineers have learned to stretch such databases across multiple servers with varying success. By contrast, a NoSQL database provides a more flexible data model, and it’s specifically built to scale across a vast number of machines.

The rub is that you can’t always slice and dice the data as easily as you can with a relational database. Generally, the “transactional semantics” of a NoSQL database are somewhat limited, and you can’t do database “joins,” where you merge data from two or more database tables.

NoSQL is a broad term, and by some counts, over 100 different outfits offer a database along these lines. Some, such as MongoDB, store data as “objects” — essentially documents — of varying sizes, while others, such as the open-source Cassandra database, developed at Facebook, store data as “key-value” pairs — i.e. “color” and “red” or “name” and “Bob.” But most of these databases are open source, and all are designed to run across a large number of low-cost machines.

Having had experience with both SQL and NoSQL, I can fairly say that they each have their strengths. For software development in general, NoSQL is hands-down the easiest to work with since there is a direct translation between programming objects and NoSQL objects (no need for custom coding of a data layer or an ORM, which is a HUGE time saver). Plus, it's easier to add in data without breaking or affecting anything or having to re-deploy the database or run scripts. it scales very easily, and requires no administration. Because NoSQL uses encapsulation in place of joins, NoSQL is generally faster. Ad-hoc reporting and data warehousing is probably the biggest downside of NoSQL DBs.

I might also add that it's very easy to get started with NoSql... In my smaller projects, I use MongoDB with C# in Windows. Here are the steps I generally take:
  1. Go to www.mongodb.org and download the appropriate version (32-bit/64-bit)
  2. Create a folder on your C: Drive called "data". Then create a folder under that called "db" (this is where MongoDB stores database files by default)
  3. Extract the downloaded MongoDB zip file to c:\data\MongoDB
  4. Install it by opening the command line (in administrator mode), and typing the following: c:\data\mongodb\bin\mongod --install --logpath c:\data\db\log.txt 
  5. Type this to get the service running: net start mongodb
  6. In your .NET project, use NuGet to add a reference to the 10Gen Mongo driver and you're good to go! The driver is documented at http://www.mongodb.org/display...

Your database files will be stored in C:\data\db. (You can change this during install.. just type c:\data\mongodb\bin\mongod --help for more options)

To backup the database: c:\data\MongoDB\bin\mongodump
To restore a database c:\data\mongoDB\bin\mongorestore

There is also a great GUI for exploring a MongoDB database called "MongoVue" available at http://www.mongovue.com/

Other noSql DBs for .NET
  1. RavenDB: Provides HTTP/JSON access. LINQ queries & sharding support.
  2. Sones Graph DB: API: .NET, Protocol: .NET embedded, REST, WebServices, query method: graph query language, LINQ.
  3. Starcounter: API: C# (.NET languages), schema: native language class model, query method: SQL, concurrency: fully ACID compliant, storage: in-memory with transactions secured on disk, reliability: full checkpoint recovery.
  4. Sterling: is a lightweight object-oriented database for .NET with support for Silverlight and Windows Phone 7. It features in-memory keys and indexes, triggers, and support for compressing and encrypting the underlying data.
  5. Morantex: Stores .NET classes in a datapool. Build for speed. SQL Server integration. LINQ support.
  6. FileDB: Mainly targeted to Silverlight/Windows Phone developers but its also great for any .NET application where a simple local database is required, extremely Lightweight - less than 50K, stores one table per file, including index, compiled versions for Windows Phone 7, Silverlight and .NET, fast, free to use in your applications.

If you find this solution useful, you are welcome to press one of the ads in this page.. Thanks!

No comments:

Post a Comment