Database & NoSQL Notes

Clean HTML study notes — Database fundamentals, database types, NoSQL models and Apache Cassandra

Converted from: cj19-databaseintro.pdf
This is a clean study-notes HTML version. Original PDF pages are intentionally not included.

1. What is Data?

Data is information that is collected, stored, and processed. It may be represented as numbers, words, images, or other forms of information.

Data can describe people, places, things, or events. It is widely used in business, science, technology, and social sciences to understand patterns, trends, relationships, support decision-making, and drive innovation.

2. What is a Database?

A database is a collection of structured data or information stored in a computer system so that it can be accessed and managed efficiently.

A database is usually managed by a Database Management System (DBMS).

DataDatabaseDBMSAccess / Manage Data

3. What is NoSQL?

NoSQL refers to non-relational databases that store data in forms other than the traditional relational table structure. The term is commonly expanded as “Not only SQL.”

The notes classify major NoSQL models as:

  • Document-based
  • Key-value
  • Wide-column / column-oriented
  • Graph-based

4. Types of Databases

Database TypeBasic Idea
HierarchicalData is organized in levels or ranks, generally following a parent-child structure.
NetworkExtends the hierarchical idea by allowing a child record to associate with multiple parent records.
Object-OrientedStores information in a form that can be represented as objects and object instances.
RelationalStores related data using tables, rows and columns, with records identified by keys.
CloudProvides database storage and processing through cloud environments.
CentralizedStores and maintains the database at a single location.
NoSQLUses non-tabular models such as documents, key-value pairs, columns and graphs.
OperationalDesigned to support day-to-day operational data processing and transactions.

5. Hierarchical Databases

A hierarchical database organizes data into levels or ranks. Data is categorized around common points of linkage, producing a tree-like parent-child structure.

Higher-level entityParentChild

The important idea is that lower-level records are connected to a higher-level parent according to the hierarchy.

6. Network Databases

A network database can be viewed as an extension of the hierarchical model. Unlike a strict one-parent hierarchy, child records can be associated with multiple parent records.

Parent AChildParent B

This creates a network of linked records rather than a simple tree.

7. Object-Oriented Databases

An object-oriented database stores information in a way that can be represented as objects, similar to the Object-Oriented Programming paradigm.

  • Data can be represented as objects.
  • An object can represent an instance of a database model.
  • Objects can be referenced directly.
  • The object-oriented representation can reduce the work required to map application objects to database data.

8. Relational Databases

A relational database stores data in related tables. It is one of the most widely used and mature database models.

Relationships between pieces of information are established using records and keys. A relational database typically represents data using tables, rows and columns.

ConceptMeaning
TableCollection of related records.
Row / RecordOne complete data entry.
ColumnAn attribute describing a type of data.
KeyUsed to identify records or establish relationships.

9. Cloud Databases

A cloud database is used when data storage and database processing are provided through a virtual/cloud environment.

Cloud computing services commonly discussed in the notes include:

ModelFull FormBasic Idea
IaaSInfrastructure as a ServiceProvides infrastructure resources.
PaaSPlatform as a ServiceProvides a platform/environment for applications.
SaaSSoftware as a ServiceProvides software as a service.

For an on-premises application, the organization owns and manages the required hardware and software.

10. Centralized Databases

A centralized database is stored, located and maintained at a single central location.

Users access the centrally maintained data rather than maintaining separate copies at multiple locations.

11. Types of NoSQL Databases

Document-based Key-value Column-oriented Graph-based

12. Document-Based Databases

A document-based database is a non-relational database that stores information as documents instead of traditional rows and columns.

Documents may use formats such as:

  • JSON
  • BSON (Binary JSON)
  • XML

Examples mentioned in the notes include MongoDB, Amazon DynamoDB and Azure Cosmos DB.

13. Key-Value Stores

A key-value store is a simple NoSQL model in which each data element is represented as a pair consisting of a unique key and its associated value.

Unique KeyValue

The value may be a simple type such as a string or number, or a more complex object.

Key features

  • Simplicity
  • Scalability
  • Speed

Examples

Couchbase, Amazon DynamoDB, Riak, Aerospike, Berkeley DB and Redis.

14. Column-Oriented Databases

A column-oriented database stores data by columns rather than primarily by rows. This can be useful for analytical workloads where only a small number of columns need to be read from a large dataset.

Key features

  • Scalability
  • Compression
  • High responsiveness

Columnar databases are designed to efficiently process and retrieve large amounts of data, particularly for analytics.

Examples

Snowflake, Google BigQuery, ClickHouse, TinyBird, Apache Druid and Apache Pinot.

15. Graph-Based Databases

A graph database focuses on relationships between data elements. Data is represented using nodes, while connections between nodes are represented as links/edges/relationships.

Node A— relationship —Node B— relationship —Node C

Key features

  • Relationships can be identified directly through links.
  • Queries can return relationship-oriented results efficiently.
  • Performance depends strongly on the number and structure of relationships.
  • Adding nodes or edges can be straightforward without major schema changes.

Examples

AllegroGraph, Amazon Neptune, AnzoGraph DB, ArangoDB, JanusGraph, MarkLogic, RedisGraph, SAP HANA, TypeDB and TigerGraph.

16. Apache Cassandra

Apache Cassandra is an open-source NoSQL database designed for handling large-scale data in a highly scalable and distributed environment.

  • Can handle structured, semi-structured and unstructured data.
  • Was originally developed at Facebook.
  • Was open-sourced in 2008.
  • Became a top-level Apache project in 2010.
  • Uses Cassandra Query Language (CQL) for database operations.
  • Is designed as a highly scalable, distributed database.

The notes also connect Cassandra with the CAP theorem: Consistency, Availability and Partition Tolerance.

17. Cassandra Query Language (CQL)

CQL is used to perform database operations in Apache Cassandra, including creating keyspaces and tables, inserting data, deleting data and selecting data.

CREATEINSERTSELECTUPDATE / DELETE

18. Step 1 — Create a Keyspace

Use the following CQL statement to create a keyspace:

CREATE KEYSPACE Emp
WITH replication = {
    'class': 'SimpleStrategy',
    'replication_factor': '1'
};

A keyspace is the top-level namespace used to organize Cassandra tables and related database objects.

19. Step 2 — Use a Keyspace

After creating a keyspace, select it using the USE command.

USE keyspace-name;

USE Emp;

20. Step 3 — Create a Cassandra Table

Once the keyspace is selected, create the table using CQL.

CREATE TABLE Emp_table (
    name text PRIMARY KEY,
    Emp_id int,
    Emp_city text,
    Emp_email text
);

Here, name is defined as the primary key.

21. Step 4 — Insert Data

Insert employee information into the table with an INSERT statement.

INSERT INTO Emp_table
(name, Emp_id, Emp_city, Emp_email)
VALUES
('smamilla', 1001, 'Hyderabad',
 'sssvt.srikanth@gmail.com');

22. Complete Cassandra Flow

CREATE KEYSPACE USE KEYSPACE CREATE TABLE INSERT DATA SELECT / UPDATE / DELETE

Example

CREATE KEYSPACE Emp
WITH replication = {
    'class': 'SimpleStrategy',
    'replication_factor': '1'
};

USE Emp;

CREATE TABLE Emp_table (
    name text PRIMARY KEY,
    Emp_id int,
    Emp_city text,
    Emp_email text
);

INSERT INTO Emp_table
(name, Emp_id, Emp_city, Emp_email)
VALUES
('smamilla', 1001, 'Hyderabad',
 'sssvt.srikanth@gmail.com');

23. Quick Revision

TopicRemember
DataInformation that can be collected, stored and processed.
DatabaseOrganized collection of data managed for efficient access.
DBMSSoftware used to manage databases.
NoSQLNon-relational database approach; “Not only SQL”.
HierarchicalLevel-based parent-child organization.
NetworkAllows records to have multiple parent relationships.
Object-orientedRepresents data as objects.
RelationalUses related tables, rows, columns and keys.
CloudDatabase services provided through cloud environments.
CentralizedDatabase maintained at one central location.
DocumentStores JSON/BSON/XML-like documents.
Key-valueStores unique keys with associated values.
Column-orientedStores/processes data by columns, useful for analytics.
GraphUses nodes and relationships/edges.
CassandraDistributed, scalable NoSQL database using CQL.
CQLCassandra Query Language.
KeyspaceTop-level Cassandra namespace for organizing tables.