├── Characteristics of DBMS ├── DBMS_vs_File_System.md ├── ER Model ├── MapReduce.md ├── README.md ├── SQL_vs_NoSQL_Database.md ├── database language.md ├── studentDatabase.md └── three schema architecture.md /Characteristics of DBMS: -------------------------------------------------------------------------------- 1 | #

Characteristics of DBMS (Database Management System)

2 | 3 | #Real World Entity: 4 | One of the most important and easy-to-understand characteristics of DBMS is that it is realistic. 5 | The DBMS has been designed in such a way that it can cater to the needs of huge business organizations and can store large data with efficient operations on them. 6 | 7 | #Self Explaining Nature: 8 | A DBMS contains one database and along with that it also contains metadata about that one database.Metadata is the data about data. 9 | 10 | #Atomicity of Operations (Transactions): 11 | Atomicity means that either the operation should not be performed or it should be performed in its entirety i.e. it must be either 0% or 100% completed. 12 | DBMS provides us with atomic operations. 13 | 14 | #Concurrent Access without Anomalies: 15 | Multiple users can access the database at the same time without any anomalies 16 | 17 | #Stores Any Kind of Structured Data: 18 | A database can store any kind of structured data. 19 | In most of the books or websites, you will see examples of students or employees as these are easy to explain but the very important fact is that the DBMS is not limited to storing only these kinds of information. 20 | 21 | #Integrity: 22 | Integrity means that the data which comes into the Database should be correct as well as consistent.In DBMS, the data that is entered into the database is both correct as well as consistent. Apart from that, integrating changes is very easy in a database. 23 | 24 | #Ease of Access (The DBMS Queries): 25 | Before DBMS, the conventional file system (i.e. files and folders) was used to store complex and large data.Searching for a Name in thousands of Students was a very difficult task. This is because manual searching is done in a conventional file system for a particular data. However, DBMS provides ease of access to the data inside the database. We can run a search query to find any data and the process is way faster than manual searching and is more reliable. The CRUD (Create, Read, Update & Delete) operations are very easy to perform with a database because of the DBMS queries. 26 | 27 | #ACID Properties: 28 | ACID stands for Atomicity, Consistency, Isolation, and Durability. 29 | We have already talked about atomicity and consistency. Atomicity means the transaction should either be 0% or 100% completed and consistency means that the change in data should be reflected everywhere in a database. 30 | Isolation means that multiple transactions can occur independently without the interference of some other transactions. 31 | Durability means that the chances of a successful atomic transaction i.e. a transaction that has been 100% completed should reflect in the database. 32 | 33 | #Security: 34 | The database should be accessible to the users in a limited way. The access to make changes to a database by the user should be limited and the users must not be given complete access to the entire database. Unauthorized users should not be allowed to access the database. Authentication: The DBMS has authentication for various users that directly refers to the limit to which the user can access the Database. Authentication means the process of laughing in of the user only with the rights that he/she has been authorized to. For instance, in any organization, admin has the access to make changes to the database of the organization as some new employee might have joined the organization or someone might have left it. However, the employees have access only to their personal profile and can make changes to it only. They cannot access the database of any other employee or the organization as a whole. 35 | -------------------------------------------------------------------------------- /DBMS_vs_File_System.md: -------------------------------------------------------------------------------- 1 | ## DBMS vs. File System 2 | 3 | 4 | ### Structure 5 | 6 | **File System:-** It helps to store a collection of raw files of data into a hard disk of the computer 7 | 8 | **DBMS:-** It is a software system which helps to store, manipulate or recover data. 9 | 10 | ### Meaning 11 | 12 | **File System:-** In this system, the user has to write the procedures for managing the database. 13 | 14 | **DBMS:-** In DBMS, the user is not required to write the procedures. 15 | 16 | ### Where to use 17 | 18 | **File System:-** File system approach used in large systems which interrelate many files. 19 | 20 | **DBMS:-** Database approach used in large systems which interrelate many files. 21 | 22 | 23 | 24 | ### Data Redundancy 25 | **File System:-** In the file system, Redundant data can be present. 26 | 27 | **DBMS:-** In DBMS there is no redundant data. 28 | 29 | ### Backup and Recovery 30 | **File System:-** It doesn’t provide backup and recovery of data if lost. 31 | 32 | **DBMS:-** It provides backup and recovery of data even if it is lost. 33 | 34 | ### Query processing 35 | **File System:-** There is no efficient query processing in the file system. 36 | 37 | **DBMS:-** Efficient query processing is there in DBMS. 38 | ### Consistency 39 | **File System:-** There is less data consistency in the file system. 40 | 41 | **DBMS:-** There is more data consistency because of the process of normalization. 42 | ### Complexity 43 | **File System:-** It is less complex as compared to DBMS. 44 | 45 | **DBMS:-** It has more complexity in handling as compared to the file system. 46 | ### Security Constraints 47 | **File System:-** File systems provide less security in comparison to DBMS. 48 | 49 | **DBMS:-** DBMS has more security mechanisms as compared to file systems. 50 | ### Cost 51 | **File System:-** It is less expensive than DBMS. 52 | 53 | **DBMS:-** It has a comparatively higher cost than a file system. 54 | ### Data Independence 55 | **File System:-** There is no data independence. 56 | 57 | **DBMS:-** In DBMS data independence exists. 58 | ### User Access 59 | **File System:-** Only one user can access data at a time. 60 | 61 | **DBMS:-** Multiple users can access data at a time. 62 | ### Sharing 63 | **File System:-** Data is distributed in many files. So, not easy to share data 64 | 65 | **DBMS:-** Due to its centralized nature sharing is easy 66 | ### Data Abstraction 67 | **File System:-** It gives details of storage and representation of data 68 | 69 | **DBMS:-** It hides the internal details of Database 70 | ### Integrity Constraints 71 | **File System:-** Integrity Constraints are difficult to implement 72 | 73 | **DBMS:-** Integrity constraints are easy to implement 74 | ### Example 75 | **File System:-** Cobol, C++ 76 | 77 | **DBMS:-** Oracle, SQL Server 78 | 79 | -------------------------------------------------------------------------------- /ER Model: -------------------------------------------------------------------------------- 1 | #

ER Model

2 | 3 | 4 | ER model stands for an Entity-Relationship model. It is a high-level data model. This model is used to define the data elements and relationship for a specified system. 5 | It develops a conceptual design for the database. It also develops a very simple and easy to design view of data. 6 | In ER modeling, the database structure is portrayed as a diagram called an entity-relationship diagram. 7 | 8 | 9 | 10 | ![Screenshot (366)](https://user-images.githubusercontent.com/76655825/199073181-62956982-dfc2-44b2-8b76-871377ec29dc.png) 11 | 12 | #Entity: 13 | An entity may be any object, class, person or place. In the ER diagram, an entity can be represented as rectangles. Consider an organization as an example- manager, product, employee, department etc. can be taken as an entity. 14 | 15 | #Attribute: 16 | The attribute is used to describe the property of an entity. Eclipse is used to represent an attribute. 17 | 18 | a. Key Attribute: 19 | The key attribute is used to represent the main characteristics of an entity. It represents a primary key. The key attribute is represented by an ellipse with the text underlined. 20 | 21 | b. Composite Attribute: 22 | An attribute that composed of many other attributes is known as a composite attribute. The composite attribute is represented by an ellipse, and those ellipses are connected with an ellipse. 23 | 24 | c. Multivalued Attribute: 25 | An attribute can have more than one value. These attributes are known as a multivalued attribute. The double oval is used to represent multivalued attribute. 26 | 27 | d. Derived Attribute: 28 | An attribute that can be derived from other attribute is known as a derived attribute. It can be represented by a dashed ellipse. 29 | 30 | # Relationship: 31 | A relationship is used to describe the relation between entities. Diamond or rhombus is used to represent the relationship. 32 | 33 | a. One-to-One Relationship: 34 | When only one instance of an entity is associated with the relationship, then it is known as one to one relationship. 35 | 36 | b. One-to-many relationship: 37 | When only one instance of the entity on the left, and more than one instance of an entity on the right associates with the relationship then this is known as a one-to-many relationship. 38 | 39 | c. Many-to-one relationship: 40 | When more than one instance of the entity on the left, and only one instance of an entity on the right associates with the relationship then it is known as a many-to-one relationship. 41 | 42 | d. Many-to-many relationship: 43 | When more than one instance of the entity on the left, and more than one instance of an entity on the right associates with the relationship then it is known as a many-to-many relationship. 44 | 45 | -------------------------------------------------------------------------------- /MapReduce.md: -------------------------------------------------------------------------------- 1 | ## What is mapreduce in MongoDb?🍃 2 | Let's get started with the definition and then understand how it works.😃👍 3 | 4 | #### Definition 5 | **mapReduce** , data processing programming model of MongoDb is mostly used for performing operations on large datasets. 6 | mapReduce() function performs the map and the reduce operations. 7 | To group the data in key-value pairs, map function is used and then the operations are performed using the reduce function of mapReduce to the keys with multiple values. 8 | mapReduce result can be returned as a document or written into a collection as well. 9 | 10 | #### Syntax 11 | 12 | The syntax of mapReduce() function: 13 | ``` 14 | db.collectionName.mapReduce( 15 | ... map(), 16 | ...reduce(), 17 | ...query{}, 18 | ...output{} 19 | ); 20 | ``` 21 | - The **map()** function has emit which takes two parameters: key and value. 22 | - The **reduce()** function performs the operation on the mapped data. It can perform operations like avg,sum etc. 23 | - The **query** is used to filter the result. 24 | - The **output** specifies the collection where the result is stored. 25 | 26 | #### Example 27 | For instance, let's assume that we have to get the min marks from each class.\ 28 | Min marks because, not everyone get's good grades right?🥲, anyway let's get back to it...\ 29 | So, let's assume there are three keys which are id, class and marks. 30 | ``` 31 | {"id":1, "class":C10, "marks":80} 32 | {"id":2, "class":C10, "marks":90} 33 | {"id":1, "class":C9, "marks":10} 34 | {"id":1, "class":C9, "marks":20} 35 | {"id":1, "class":C8, "marks":90} 36 | ``` 37 | We will group this data using the *class* key and the value will be *marks*. 38 | For this let us write the map function.\ 39 | We will create a var map with emit function that shows that we are using class as key and marks as value. 40 | 41 | ``` 42 | var map = function(){emit(this.class, this.marks)}; 43 | ``` 44 | 45 | The following result will be obtained by this:\ 46 | {“C10”:[80, 90]}, {“C9”:[10, 20]}, {“C8”:[90] } 47 | 48 | Now,this isn't the end result we wanted, is it?\ 49 | So, in order to find the min marks from each class we will use the reduce function to perform the operation. 50 | 51 | ``` 52 | var reduce = function(class,marks){return Array.min(marks);}; 53 | ``` 54 | This is a reduce function, which accepts two parameters i.e. the key which is class and the value which is marks. It then filters the min marks from each class. 55 | \ 56 | In order to get the output in a new collection we will: 57 | 58 | ``` 59 | db.collectionName.mapReduce(map,reduce,{out :"collectionName"}); 60 | ``` 61 | 62 | This is how we can use the mapReduce function in MongoDb!! -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Database-Management-System 2 | 3 | -------------------------------------------------------------------------------- /SQL_vs_NoSQL_Database.md: -------------------------------------------------------------------------------- 1 | 2 | Explore key differences between SQL and NoSQL databases and learn which type of database is best for various use cases. 3 | 4 | 5 | SQL is a decades-old method for accessing relational databases, and most who work with databases are familiar with it. As unstructured data, amounts of storage and processing power and types of analytics have changed over the years, however, we’ve seen different database technologies become available that are a better fit for newer types of use cases. These databases are commonly called NoSQL. 6 | 7 | SQL and NoSQL differ in whether they are relational (SQL) or non-relational (NoSQL), whether their schemas are predefined or dynamic, how they scale, the type of data they include and whether they are more fit for multi-row transactions or unstructured data. 8 | 9 | What is a SQL database? 10 | 11 | 12 | SQL, which stands for “Structured Query Language,” is the programming language that’s been widely used in managing data in relational database management systems (RDBMS) since the 1970s. In the early years, when storage was expensive, SQL databases focused on reducing data duplication. 13 | 14 | Fast-forward to today, and SQL is still widely used for querying relational databases, where data is stored in rows and tables that are linked in various ways. One table record may link to one other or to many others, or many table records may be related to many records in another table. These relational databases, which offer fast data storage and recovery, can handle great amounts of data and complex SQL queries. 15 | 16 | What is a NoSQL database? 17 | 18 | 19 | NoSQL is a non-relational database, meaning it allows different structures than a SQL database (not rows and columns) and more flexibility to use a format that best fits the data. The term “NoSQL” was not coined until the early 2000s. It doesn’t mean the systems don’t use SQL, as NoSQL databases do sometimes support some SQL commands. More accurately, “NoSQL” is sometimes defined as “not only SQL.” 20 | 21 | To lay the groundwork, see the following video from Jamil Spain: 22 | 23 | 24 | How SQL works 25 | 26 | 27 | SQL databases are valuable in handling structured data, or data that has relationships between its variables and entities. 28 | 29 | Scalability 30 | 31 | In general, SQL databases can scale vertically, meaning you can increase the load on a server by migrating to a larger server that adds more CPU, RAM or SSD capability. While vertical scalability is used most frequently, SQL databases can also scale horizontally through sharding or partitioning logic, although that’s not well-supported. 32 | 33 | Structure 34 | 35 | SQL database schema organizes data in relational, tabular ways, using tables with columns or attributes and rows of records. Because SQL works with such a strictly predefined schema, it requires organizing and structuring data before starting with the SQL database. 36 | 37 | Properties 38 | 39 | RDBMS, which use SQL, must exhibit four properties, known by the acronym ACID. These ensure that transactions are processed successfully and that the SQL database has a high level of reliability: 40 | 41 | Atomicity: All transactions must succeed or fail completely and cannot be left partially complete, even in the case of system failure. 42 | 43 | Consistency: The database must follow rules that validate and prevent corruption at every step. 44 | 45 | Isolation: Concurrent transactions cannot affect each other. 46 | 47 | Durability: Transactions are final, and even system failure cannot “roll back” a complete transaction. 48 | 49 | Support 50 | 51 | Because SQL databases have a long history now, they have huge communities, and many examples of their stable codebases online. There are many experts available to support SQL and programming relational data. 52 | 53 | Examples of SQL databases 54 | 55 | Db2 56 | MySQL 57 | PostgreSQL 58 | YugabyteDB 59 | CockroachDB 60 | Oracle Database 61 | Microsoft SQL Server 62 | Azure SQL Database 63 | How NoSQL works 64 | Unlike SQL, NoSQL systems allow you to work with different data structures within a database. Because they allow a dynamic schema for unstructured data, there’s less need to pre-plan and pre-organize data, and it’s easier to make modifications. NoSQL databases allow you to add new attributes and fields, as well as use varied syntax across databases. 65 | 66 | Scalability 67 | 68 | NoSQL databases scale better horizontally, which means one can add additional servers or nodes as needed to increase load. 69 | 70 | Structure 71 | 72 | NoSQL databases are not relational, so they don’t solely store data in rows and tables. Instead, they generally fall into one of four types of structures: 73 | 74 | Column-oriented, where data is stored in cells grouped in a virtually unlimited number of columns rather than rows. 75 | Key-value stores, which use an associative array (also known as a dictionary or map) as their data model. This model represents data as a collection of key-value pairs. 76 | Document stores, which use documents to hold and encode data in standard formats, including XML, YAML, JSON (JavaScript Object Notation) and BSON. A benefit is that documents within a single database can have different data types. 77 | Graph databases, which represent data on a graph that shows how different sets of data relate to each other. Neo4j, RedisGraph (a graph module built into Redis) and OrientDB are examples of graph databases. 78 | Properties 79 | While SQL calls for ACID properties, NoSQL follows the CAP theory (although some NoSQL databases — such as IBM’s DB2, MongoDB, AWS’s DynamoDB and Apache’s CouchDB — can also integrate and follow ACID rules). 80 | 81 | The CAP theorem says that distributed data systems allow a trade-off that can guarantee only two of the following three properties (which form the acronym CAP) at any one time: 82 | 83 | Consistency: Every request receives either the most recent result or an error. MongoDB is an example of a strongly consistent system, whereas others such as Cassandra offer eventual consistency. 84 | Availability: Every request has a non-error result. 85 | Partition tolerance: Any delays or losses between nodes do not interrupt the system operation. 86 | Support 87 | While NoSQL has quickly been adopted, it has smaller user communities and, therefore, less support. NoSQL users do benefit from open-source systems, as opposed to the many SQL languages that are proprietary. 88 | 89 | Examples of NoSQL databases 90 | 91 | Redis 92 | FaunaDB 93 | CouchDB 94 | MongoDB 95 | Cassandra 96 | Elasticsearch 97 | BigTable 98 | Neo4j 99 | HBase 100 | When to use SQL vs NoSQL 101 | 102 | When to use SQL 103 | 104 | SQL is a good choice when working with related data. Relational databases are efficient, flexible and easily accessed by any application. A benefit of a relational database is that when one user updates a specific record, every instance of the database automatically refreshes, and that information is provided in real-time. 105 | 106 | SQL and a relational database make it easy to handle a great deal of information, scale as necessary and allow flexible access to data — only needing to update data once instead of changing multiple files, for instance. It’s also best for assessing data integrity. Since each piece of information is stored in a single place, there’s no problem with former versions confusing the picture. 107 | 108 | Most of the big tech companies use SQL, including Uber, Netflix and Airbnb. Even major companies like Google, Facebook and Amazon, which build their own database systems, use SQL to query and analyze data. 109 | 110 | When to use NoSQL 111 | 112 | While SQL is valued for ensuring data validity, NoSQL is good when it’s more important that the availability of big data is fast. It’s also a good choice when a company will need to scale because of changing requirements. NoSQL is easy-to-use, flexible and offers high performance. 113 | 114 | NoSQL is also a good choice when there are large amounts of (or ever-changing) data sets or when working with flexible data models or needs that don't fit into a relational model. When working with large amounts of unstructured data, document databases (e.g., CouchDB, MongoDB, and Amazon DocumentDB) are a good fit. For quick access to a key-value store without strong integrity guarantees, Redis may be the best choice. When a complex or flexible search across a lot of data is needed, Elastic Search is a good choice. 115 | 116 | Scalability is a significant benefit of NoSQL databases. Unlike with SQL, their built-in sharding and high availability requirements allow horizontal scaling. Furthermore, NoSQL databases like Cassandra, developed by Facebook, handle massive amounts of data spread across many servers, having no single points of failure and providing maximum availability. 117 | 118 | Other big companies that use NoSQL systems because they are dependent on large volumes of data not suited to a relational database include Amazon, Google and Netflix. In general, the more extensive the dataset, the more likely that NoSQL is a better choice. 119 | -------------------------------------------------------------------------------- /database language.md: -------------------------------------------------------------------------------- 1 | # Database Languages 2 | Database languages, also known as query languages or data query languages, are a classification of programming languages that developers use to define and access databases, which are collections of organized data that users can access electronically. These languages allow users to complete tasks such as controlling access to data, defining and updating data and searching for information within the database management system. 3 | 4 | ## 4 categories of database languages 5 | Here are four types of database languages and their uses: 6 | 7 | 1. Data definition language (DDL) 8 | Data definition language (DDL) creates the framework of the database by specifying the database schema, which is the structure that represents the organization of data. Its common uses include the creation and alteration of tables, files, indexes and columns within the database. This language also allows users to rename or drop the existing database or its components. Here's a list of DDL statements: 9 | CREATE: Creates a new database or object, such as a table, index or column 10 | ALTER: Changes the structure of the database or object 11 | DROP: Deletes the database or existing objects 12 | RENAME: Renames the database or existing objects 13 | 14 | 2. Data manipulation language (DML) 15 | Data manipulation language (DML) provides operations that handle user requests, offering a way to access and manipulate the data that users store within a database. Its common functions include inserting, updating and retrieving data from the database. Here's a list of DML statements: 16 | INSERT: Adds new data to the existing database table 17 | UPDATE: Changes or updates values in the table 18 | DELETE: Removes records or rows from the table 19 | SELECT: Retrieves data from the table or multiple tables 20 | 21 | 3. Data control language (DCL) 22 | Data control language (DCL) controls access to the data that users store within a database. Essentially, this language controls the rights and permissions of the database system. It allows users to grant or revoke privileges to the database. Here's a list of DCL statements: 23 | GRANT: Gives a user access to the database 24 | REVOKE: Removes a user's access to the database 25 | 26 | 4. Transaction control language (TCL) 27 | Transaction control language (TCL) manages the transactions within a database. Transactions group a set of related tasks into a single, executable task. All the tasks must succeed in order for the transaction to work. Here's a list of TCL statements: 28 | COMMIT: Carries out a transaction 29 | ROLLBACK: Restores a transaction if any tasks fail to execute 30 | 31 | # Few Examples of database languages 32 | 1. SQL 33 | 2. SQL/XML 34 | 3. GraphQL 35 | -------------------------------------------------------------------------------- /studentDatabase.md: -------------------------------------------------------------------------------- 1 | # Creating Student Database in MongoDB 2 | 3 | ## Pre-requisites 4 | 5 | ### Install MongoDB and mongoose in your project. 6 | ### Spin up your mongo server and your mongo shell in the terminal. 7 | 8 | ## Steps 9 | 10 | 1. ### Step 1: Require Mongoose in your project 11 | const mongoose= require(“mongoose”); 12 | 13 | 2. ### Step 2: Connect your app with a MongoDB database using the URL where your MongoDB is hosted locally. 14 | mongoose.connect('mongodb://localhost:27017/Student', { useNewUrlParser : true }); 15 | 16 | 3. ### Step 3: Create a new schema “studentsSchema” 17 | const studentsSchema={ 18 | name:String, 19 | id: Number 20 | }; 21 | 22 | 4. ### Step 4: Create a new mongoose model based on this schema using the singular form of your collection i.e. student, and the schema 23 | const Item=mongoose.model(" Student ", studentsSchema); 24 | 25 | 5. ### Step 5: Create a new mongoose document using your Student model 26 | const student1=new Student({ 27 | name : " Stu-1 ", 28 | id: 1 29 | }); 30 | 31 | 6. ### Step 6: Save that document to your database 32 | student1.save(function (err, student) { 33 | if (err) return console.error(err); 34 | }); 35 | 36 | ## Ta-daa, you have now created a Student Database with data in it :tada: :tada: -------------------------------------------------------------------------------- /three schema architecture.md: -------------------------------------------------------------------------------- 1 | # Three-schema Architecture 2 | The three-schema architecture divides the database into three-level used to create a separation between the physical database and the user application. In simple terms, this architecture hides the details of physical storage from the user. 3 | 4 | The database administrator (DBA) responsible is to change the structure of database storage without affecting the user’s view. It deals with the data, the relationship between them and the different access methods implemented on the database. The logical design of database is called a schema. 5 | 6 | ## This architecture contains three layers of database management system, which are as follows − 7 | 1. External level 8 | 2. Conceptual level 9 | 3. Internal level 10 | 11 | ### External/ View level 12 | This is the highest level of database abstraction. It includes a number of external schemas or user views. This level provides different views of the same database for a specific user or a group of users. An external view provides a powerful and flexible security mechanism by hiding the parts of the database from a particular user. 13 | 14 | ### Conceptual or Logical level 15 | This level describes the structure of the whole database. It acts as a middle layer between the physical storage and user view. It explains what data to be stored in the database, what the data types are, and what relationship exists among those data. There is only one conceptual schema per database. 16 | 17 | This level describes the structure of the whole database. It acts as a middle layer between the physical storage and user view. It explains what data to be stored in the database, what the data types are, and what relationship exists among those data. There is only one conceptual schema per database. 18 | 19 | ### Internal or Physical level 20 | This is the lowest level of database abstraction. It describes how the data is stored in the database and provides the methods to access data from the database. It allows viewing the physical representation of the database on the computer system. 21 | 22 | The interface between the conceptual and internal schema identifies how an element in the conceptual schema is stored and how it may be accessed. It is one which is closest to physical storage. The internal schema not only defines different stored record types, but also specifies what indices exist, how stored fields are represented. --------------------------------------------------------------------------------