0% found this document useful (0 votes)
5 views44 pages

NoSQL Database Types and CRUD Operations

The document covers NoSQL data management, detailing four types of NoSQL databases: key-value stores, document-based stores, column-based stores, and graph-based trading. It also discusses CRUD operations and various data modeling techniques, including conceptual and hierarchical methods. Additionally, it addresses relational database design, focusing on functional dependencies, normalization, and guidelines to avoid anomalies in relational schemas.

Uploaded by

cheetah69757
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views44 pages

NoSQL Database Types and CRUD Operations

The document covers NoSQL data management, detailing four types of NoSQL databases: key-value stores, document-based stores, column-based stores, and graph-based trading. It also discusses CRUD operations and various data modeling techniques, including conceptual and hierarchical methods. Additionally, it addresses relational database design, focusing on functional dependencies, normalization, and guidelines to avoid anomalies in relational schemas.

Uploaded by

cheetah69757
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

22CS2403

Database Management System

Unit – 4

1
PART A

• NoSQL Data Management (Cont..)


• NoSQL Database Types

• Data Modelling

• CRUD Operations

2
NoSQL Databases Types
• There are four different types of NoSQL databases on which dozens of data models are based

1. Key-value store

• Built specifically for high-performance requirements and probably one of the most common data models, key-value stores use
key-values ​with pointers to store data.

3
NoSQL Databases Types (2)
2. Document-based Store

XML and JSON tend to be tied to SQL, which slows down queries and the whole process. However, because NoSQL doesn’t use
a relational model, it doesn’t have to, which is where document-based stores come in. All data is stored in one table, so there is no
need for cross-referencing, and instead of storing information in a table, it is stored in a document. While it is very similar to a key-
value store and can sometimes be considered an umbrella for it, the difference is that document-based NoSQL generally has
some form of encoding, such as XML

4
NoSQL Databases Types (3)
3. Column based store

• This data model stores information in columns rather than rows, which is more common with SQL. Data is stored in columns that
are grouped into families, and these families are further grouped into more columns. This essentially creates an almost unlimited
column nesting data model.

• Row-oriented vs column-oriented database types.

5
NoSQL Databases Types (4)
4. Graph-based trading

• Graph or network data models consider the relationship between two pieces of information to be as meaningful as the
information itself. As such, this data model is really made for any information you would typically represent in a chart. It uses
relationships and nodes, where the data is the information itself, and the connection is created between the nodes. Graph
NoSQL database example:

6
CRUD

7
Create Operation

8
Create Operation

• [Link]([

{ key1: value1, key2: value2, ... },

{ key1: value3, key2: value4, ... },

]);

9
Read Operation

$lt: Less than


$lte: Less than or equal to
$eq: Equal to
$ne: Not equal to
$gte: Greater than or equal to

10
Update Operation

11
Delete Operation

12
NoSQL Data Modelling Techniques
• Conceptual Techniques

• There are three conceptual techniques for modelling NoSQL data:

• Denormalisation. Denormalisation is a common technique that involves copying data into multiple tables or forms to
simplify it. Use denormalisation to easily group all the data you need to query in one place. Unfortunately, this means
that the data volume increases for various parameters, considerably increasing the data volume.

• Aggregates. This allows users to create nested entities with complex internal structures and change their specific
systems. Ultimately, aggregation limits connections by minimising one-to-one relationships. Most NoSQL data models
have some form of this soft schema technique. For example, graph and key-value store databases have values ​in any
format because these data models place no restrictions on the matter.

• Application Side Joins. Since NoSQL databases are question-oriented and join are performed during design time,
NoSQL often does not enable joins. Compared to relational databases, this is done when the query is executed.
Naturally, this frequently entails a performance penalty and is sometimes unavoidable
13
General Modelling Techniques
• There are five general techniques for modelling NoSQL data:

1. Enumerable keys. For the most part, unordered fundamental values ​are instrumental because items can be distributed across multiple
dedicated servers just by hashing the key. Adding some functionality using ordered keys is helpful, although it may add a bit of complexity
and a performance hit.

2. Dimension reduction. GIS tend to use R-Tree indexes and needs to be updated in place, which can be expensive when dealing with large
volumes of data. Another traditional approach is to flatten the 2D structure into a simple list, like what is done with Geohash. You can use
dimensionality reduction to map multidimensional data to simple key-value models or even multifaceted models. Use dimensionality
reduction to map multidimensional data to a key-value model or another non-multidimensional model.

3. Index table. With an index table, please take advantage of indexes in stores that don’t necessarily support them internally. Try to create and
maintain a unique table with keys following a specific access pattern. For example, a master table to store user accounts for access by user
ID.

4. Composite key index. Although a general technique, composite keys are handy when using ordered keys. If you take that and combine it
with secondary keys, you can create a multidimensional index that is very similar to the dimensionality reduction technique above.

5. Inverted Lookup – Direct Aggregation. The concept behind this technique is to use an index that meets a specific set of criteria but then
aggregates that data with full scans or some form of the original representation. 14
Hierarchical Modelling Techniques
• Tree aggregation. Tree aggregation is essentially modelling data as a single document. This can be effective for any record
that is always accessible at once, such as a Twitter thread or a Reddit post. The problem then, of course, is that random access
to any single record is inefficient.

• Neighborhood lists. This is a direct technique where nodes are modelled as independent field records with direct ancestors.
That’s a fancy way of saying it lets you search for nodes by their parents or children. However, like tree aggregation, it is
relatively inefficient for retrieving the entire subtree for any given node.

• Materialized paths. This technique is a denormalisation type used to avoid recursive traversal in tree structures. We primarily
want to assign parents or children to each node, which helps us determine the possible ancestors or descendants of the node
without worrying about traversal. We can store materialised paths as IDs, either as a set or as a single string.

• Nested sets. A standard technique for tree structures in relational databases applies equally to NoSQL and key-value or
document databases. The idea is to store the tree leaves as an array and then map each non-leaf node to a range of leaves
using start/end indices. Modelling this way is efficient for dealing with immutable data because it requires only a tiny amount of
memory and doesn’t necessarily use traversal. That said, updates are expensive because they need index updates.
15
Hierarchical Modelling Techniques (2)
• Merging nested documents: Numeric field names. Most search engines tend to work with records that are a
flat list of fields and values rather than something with a complex internal structure. As such, this data
modelling technique attempts to map these complex structures onto a simple document, such as mapping
documents with a hierarchical structure, which is a common problem you may encounter. Of course, this work
is painful and not easily scalable, especially as the nested structures grow.

• Merging nested documents: Proximity queries. One way to solve potential problems with the numbered field
name data modelling technique is to use a similar process called Proximity Queries. These limit the distance
between words in a document, which helps increase performance and reduce the impact on query speed.

• Batch processing of graphs. Batch graph processing is an excellent technique for exploring up or down
relationships for a node in multiple steps. However, it’s an expensive process and doesn’t necessarily scale
well. We can use Message Passing and MapReduce to do this type of graph processing

16
PART – B

DATABASE DESIGN

17
Unit 4: Functional Dependencies and
Normalization for Relational Databases
Syllabus
1 Informal Design Guidelines for Relational Databases 3. Normal Forms Based on Primary Keys
3.1 Normalization of Relations
1.1 Semantics of the Relation Attributes
3.2 Practical Use of Normal Forms
1.2 Redundant Information in Tuples and Update Anomalies
3.3 Definitions of Keys and Attributes
1.3 Null Values in Tuples Participating in Keys

1.4 Spurious Tuples 3.4 First Normal Form


3.5 Second Normal Form
2 Functional Dependencies (FDs)
3.6 Third Normal Form
2.1 Definition of FD

2.2 Inference Rules for FDs 4. BCNF (Boyce-Codd Normal Form)

2.3 Equivalence of Sets of FDs


18
2.4 Minimal Sets of FDs
1. Informal Design Guidelines for Relational
Databases

1.1 Semantics of the Relation Attributes

1.2 Redundant Information in Tuples and Update Anomalies

1.3 Null Values in Tuples

1.4 Spurious Tuples

19
Informal Design Guidelines for Relational
Databases

• What is relational database design?


• The grouping of attributes to form "good" relation schemas

• Two levels of relation schemas


• The logical "user view" level

• The storage "base relation" level

20
Design is concerned mainly with base
relations
• We first discuss informal guidelines for good relational design

• Then we discuss formal concepts of functional dependencies and normal


forms
• - 1NF (First Normal Form)

• - 2NF (Second Normal Form)

• - 3NF (Third Normal Form)

• - BCNF (Boyce-Codd Normal Form)

21
1.1: Semantics of the Relation Attributes

• GUIDELINE 1: Informally, each tuple in a relation should represent one entity


or relationship instance. (Applies to individual relations and their attributes).
• Attributes of different entities (EMPLOYEEs, DEPARTMENTs, PROJECTs) should
not be mixed in the same relation
• Only foreign keys should be used to refer to other entities

• Entity and relationship attributes should be kept apart as much as possible.

• Bottom Line: Design a schema that can be explained easily relation by relation.
The semantics of attributes should be easy to interpret.
22
A simplified COMPANY relational database
schema

23
1.2: Redundant Information in Tuples and Update
Anomalies

• Information is stored redundantly


• Wastes storage

• Causes problems with update anomalies


• Insertion anomalies

• Deletion anomalies

• Modification anomalies

24
EXAMPLE OF AN UPDATE ANOMALY

• Consider the relation:


• EMP_PROJ(Emp#, Proj#, Ename, Pname, No_hours)

• Update Anomaly:
• Changing the name of project number P1 from “Billing” to “Customer-
Accounting” may cause this update to be made for all 100 employees
working on project P1.

25
EXAMPLE OF AN INSERT ANOMALY

• Consider the relation:


• EMP_PROJ(Emp#, Proj#, Ename, Pname, No_hours)

• Insert Anomaly:
• Cannot insert a project unless an employee is assigned to it.

• Conversely
• Cannot insert an employee unless an he/she is assigned to a project.

26
EXAMPLE OF AN DELETE ANOMALY

• Consider the relation:


• EMP_PROJ(Emp#, Proj#, Ename, Pname, No_hours)

• Delete Anomaly:
• When a project is deleted, it will result in deleting all the employees
who work on that project.
• Alternately, if an employee is the sole employee on a project, deleting
that employee would result in deleting the corresponding project.
27
Two relation schemas suffering from update
anomalies

28
Example States for EMP_DEPT and
EMP_PROJ

29
Guideline to Redundant Information in
Tuples and Update Anomalies
• GUIDELINE 2:
• Design a schema that does not suffer from the insertion, deletion and
update anomalies.
• If there are any anomalies present, then note them so that applications
can be made to take them into account.

30
1.3: Null Values in Tuples

• GUIDELINE 3:
• Relations should be designed such that their tuples will have as few NULL values as
possible
• Attributes that are NULL frequently could be placed in separate relations (with the primary
key)

• Reasons for nulls:


• Attribute not applicable or invalid
• Attribute value unknown (may exist)
• Value known to exist, but unavailable
31
1.4: Spurious Tuples
• Bad designs for a relational database may result in erroneous
results for certain JOIN operations
• The "lossless join" property is used to guarantee meaningful
results for join operations

• GUIDELINE 4:
• The relations should be designed to satisfy the lossless join condition.
• No spurious tuples should be generated by doing a natural-join of any
relations.

32
Spurious Tuples (2)

• There are two important properties of decompositions:


a) Non-additive or losslessness of the corresponding join

b) Preservation of the functional dependencies.

• Note that:
• Property (a) is extremely important and cannot be sacrificed.
• Property (b) is less stringent and may be sacrificed.
33
2. Functional Dependencies (FD)

2.1 Definition of FD

2.2 Inference Rules for FDs

2.3 Equivalence of Sets of FDs

2.4 Minimal Sets of FDs

34
2.1 Functional Dependencies

• Functional dependencies (FDs)


• Are used to specify formal measures of the "goodness" of relational designs

• And keys are used to define normal forms for relations

• Are constraints that are derived from the meaning and interrelationships of
the data attributes

• A set of attributes X functionally determines a set of attributes Y if


the value of X determines a unique value for Y
35
Functional Dependencies (2)

• X 🡪 Y holds if whenever two tuples have the same value for X, they must have
the same value for Y
• For any two tuples t1 and t2 in any relation instance r(R): If t1[X]=t2[X], then
t1[Y]=t2[Y]

• X 🡪 Y in R specifies a constraint on all relation instances r(R)

• Written as X 🡪 Y; can be displayed graphically on a relation schema as in


Figures. ( denoted by the arrow: ).

• FDs are derived from the real-world constraints on the attributes


36
Examples of FD constraints (1)

• Social security number determines employee name


• SSN 🡪 ENAME

• Project number determines project name and location


• PNUMBER 🡪 {PNAME, PLOCATION}

• Employee ssn and project number determines the hours per week
that the employee works on the project
• {SSN, PNUMBER} 🡪 HOURS
37
Examples of FD constraints (2)

• An FD is a property of the attributes in the schema R

• The constraint must hold on every relation instance r(R)

• If K is a key of R, then K functionally determines all attributes in


R
• (since we never have two distinct tuples with t1[K]=t2[K])

38
2.2: Inference Rules for FDs
• Given a set of FDs F, we can infer additional FDs that hold whenever the
FDs in F hold
• Armstrong's inference rules:
• IR1. (Reflexive) If Y subset-of X, then X 🡪 Y i.e X 🡪X
• IR2. (Augmentation) If X 🡪 Y, then XZ 🡪 YZ
• (Notation: XZ stands for X U Z)
• IR3. (Transitive) If X 🡪 Y and Y 🡪 Z, then X 🡪 Z

• IR1, IR2, IR3 form a sound and complete set of inference rules
• These are rules hold and all other rules that hold can be deduced from these

39
Inference Rules for FDs
• Some additional inference rules that are useful:
• Decomposition: If X 🡪 YZ, then X 🡪 Y and X 🡪 Z
• Union: If X 🡪 Y and X 🡪 Z, then X 🡪 YZ
• Psuedotransitivity: If X 🡪 Y and WY 🡪 Z, then WX 🡪 Z

• The last three inference rules, as well as any other inference


rules, can be deduced from IR1, IR2, and IR3 (completeness
property)

40
Inference Rules for FDs

• Closure of a set F of FDs is the set F+ of all FDs that can be


inferred from F

• Closure of a set of attributes X with respect to F is the set X + of


all attributes that are functionally determined by X

• X+ can be calculated by repeatedly applying IR1, IR2, IR3 using


the FDs in F
41
2.3: Equivalence of Sets of FDs
• Two sets of FDs F and G are equivalent if:
• Every FD in F can be inferred from G, and
• Every FD in G can be inferred from F
• Hence, F and G are equivalent if F+ =G+

• Definition (Covers):
• F covers G if every FD in G can be inferred from F
• (i.e., if G+ subset-of F+)

• F and G are equivalent if F covers G and G covers F

• There is an algorithm for checking equivalence of sets of FDs


42
2.4: Minimal Sets of FDs

• A set of FDs is minimal if it satisfies the following conditions:


1. Every dependency in F has a single attribute for its RHS.

2. We cannot remove any dependency from F and have a set of


dependencies that is equivalent to F.

3. We cannot replace any dependency X 🡪 A in F with a dependency


Y 🡪 A, where Y proper-subset-of X ( Y subset-of X) and still have a
set of dependencies that is equivalent to F.
43
2.4: Minimal Sets of FDs (2)

• Every set of FDs has an equivalent minimal set

• There can be several equivalent minimal sets

• There is no simple algorithm for computing a minimal set of FDs that is


equivalent to a set F of FDs

• To synthesize a set of relations, we assume that we start with a set of


dependencies that is a minimal set
• E.g., see algorithms 11.2 and 11.4
44

You might also like