dbms material
dbms material
4 MARKS:
Database Management Systems (DBMS) can be classified based on several criteria, including the data
model they use, the number of users they support, the types of databases they manage, and the architecture
they follow. Here's a breakdown of the primary classifications:
o Hierarchical DBMS:
o Data is organized in a tree-like structure.
o Each record has a single parent, but may have multiple children.
o Example: IBM's Information Management System (IMS).
o Network DBMS:
o Similar to hierarchical DBMS, but allows many-to-many relationships.
o Data is represented as a graph, where entities are nodes and relationships are edges.
o Example: Integrated Data Store (IDS).
o Relational DBMS (RDBMS):
o Data is organized in tables (relations) with rows and columns.
o Uses SQL for querying and maintaining the database.
o Example: MySQL, PostgreSQL, Oracle, SQL Server.
o Object-oriented DBMS (OODBMS):
o Data is represented in the form of objects, similar to object-oriented programming.
o Supports complex data types and object identity.
o Example: ObjectDB, db4o.
o Object-relational DBMS (ORDBMS):
o Combines features of both RDBMS and OODBMS.
o Extends the relational model to support complex data types.
o Example: PostgreSQL, Oracle.
o Single-user DBMS:
o Supports one user at a time.
o Typically used on personal computers.
o Example: Microsoft Access.
o Multi-user DBMS:
o Supports multiple users simultaneously.
o Used in larger systems like enterprise environments.
o Example: MySQL, Oracle, SQL Server.
o Centralized DBMS:
o All data is stored and managed on a single central server.
o Accessed via network by multiple users.
o Example: IBM DB2.
o Distributed DBMS (DDBMS):
o Data is distributed across multiple physical locations.
o Appears as a single database to users.
o Example: Apache Cassandra, Google Cloud Spanner.
o Federated DBMS:
o Integrates multiple autonomous databases into a single federated database.
o Each constituent database remains independent.
o Example: Microsoft Access with linked tables from SQL Server.
Based on Architecture
o Single-tier Architecture:
o Also known as monolithic architecture.
o The database is directly accessible to the end user.
o Two-tier Architecture:
o Client-server architecture.
o Client application interacts with the server DBMS.
o Three-tier Architecture:
o Adds a middle layer between client and server.
o Middle tier includes application or web server.
o Example: Web applications using a web server, an application server, and a database server.
a. Weak Entity
An entity that depends on another entity called a weak entity. The weak entity doesn't
contain any key attribute of its own. The weak entity is represented by a double rectangle.
2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used to represent an
attribute.
For example, id, age, contact number, name, etc. can be attributes of a student.
a. Key Attribute
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.
b. Composite Attribute
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.
c. Multivalued Attribute
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.
For example, a student can have more than one phone number.
d. Derived Attribute
An attribute that can be derived from other attribute is known as a derived attribute. It can
be represented by a dashed ellipse.
For example, A person's age changes over time and can be derived from another attribute
like Date of birth.
3. Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus is used
to represent the relationship.
When only one instance of an entity is associated with the relationship, then it is known as
one to one relationship.
For example, A female can marry to one male, and a male can marry to one female.
Advertisement
b. One-to-many relationship
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.
For example, Scientist can invent many inventions, but the invention is done by the only
specific scientist.
c. Many-to-one relationship
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.
For example, Student enrolls for only one course, but a course can have many students.
d. Many-to-many relationship
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.
For example, Employee can assign by many projects and project can have many
employees.
Component of ER Diagram
1. Entity:
An entity may be any object, class, person or place. In the ER diagram, an entity can be
represented as rectangles.
a. Weak Entity
An entity that depends on another entity called a weak entity. The weak entity doesn't
contain any key attribute of its own. The weak entity is represented by a double rectangle.
2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used to represent an
attribute.
For example, id, age, contact number, name, etc. can be attributes of a student.
a. Key Attribute
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.
b. Composite Attribute
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.
c. Multivalued Attribute
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.
For example, a student can have more than one phone number.
d. Derived Attribute
An attribute that can be derived from other attribute is known as a derived attribute. It can
be represented by a dashed ellipse.
For example, A person's age changes over time and can be derived from another attribute
like Date of birth.
3. Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus is used
to represent the relationship.
When only one instance of an entity is associated with the relationship, then it is known as
one to one relationship.
For example, A female can marry to one male, and a male can marry to one female.
Advertisement
b. One-to-many relationship
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.
For example, Scientist can invent many inventions, but the invention is done by the only
specific scientist.
c. Many-to-one relationship
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.
For example, Student enrolls for only one course, but a course can have many students.
d. Many-to-many relationship
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.
For example, Employee can assign by many projects and project can have many
employees.
Concept of keys:
A key in DBMS is an attribute or a set of attributes that help to uniquely identify a tuple (or row) in
a relation (or table).
Keys are also used to establish relationships between the different tables and columns of a relational
database.
Individual values in a key are called key values.
A key could either be a combination of more than one attribute (or columns) or just a single
attribute.
The main motive of this is to give each record a unique identity.
Different Types Of Keys in DBMS-
There are following 10 important keys in DBMS-
1. Super key
2. Candidate key
3. Primary key
4. Alternate key
5. Foreign key
6. Partial key
7. Composite key
8. Unique key
9. Surrogate key
10. Secondary key
1. Super Key-
A super key is a set of attributes that can identify each tuple uniquely in the given relation.
A super key is not restricted to have any specific number of attributes.
Thus, a super key may consist of any number of attributes.
Example-
Consider the following Student schema-
Student ( roll , name , sex , age , address , class , section )
Given below are the examples of super keys since each set can uniquely identify each student in the
Student table-
( roll , name , sex , age , address , class , section )
( class , section , roll )
(class , section , roll , sex )
( name , address )
NOTE-
All the attributes in a super key are definitely sufficient to identify each tuple uniquely in the given
relation but all of them may not be necessary.
2. Candidate Key-
A set of minimal attribute(s) that can identify each tuple uniquely in the given relation is called as a
candidate key.
Example-
Consider the following Student schema-
Student ( roll , name , sex , age , address , class , section )
Given below are the examples of candidate keys since each set consists of minimal attributes
required to identify each student uniquely in the Student table-
( class , section , roll )
( name , address )
NOTES-
All the attributes in a candidate key are sufficient as well as necessary to identify each tuple
uniquely.
Removing any attribute from the candidate key fails in identifying each tuple uniquely.
The value of candidate key must always be unique.
The value of candidate key can never be NULL.
It is possible to have multiple candidate keys in a relation.
Those attributes which appears in some candidate key are called as prime attributes.
3. Primary Key-
A primary key is a candidate key that the database designer selects while designing the database.
OR
Candidate key that the database designer implements is called as a primary key.
NOTES-
The value of primary key can never be NULL.
The value of primary key must always be unique.
The values of primary key can never be changed i.e. no updation is possible.
The value of primary key must be assigned when inserting a record.
A relation is allowed to have only one primary key.
Remember-
4. Alternate Key-
Candidate keys that are left unimplemented or unused after implementing the primary key are called
as alternate keys.
OR
Unimplemented candidate keys are called as alternate keys.
5. Foreign Key-
An attribute ‘X’ is called as a foreign key to some other attribute ‘Y’ when its values are dependent
on the values of attribute ‘Y’.
The attribute ‘X’ can assume only those values which are assumed by the attribute ‘Y’.
Here, the relation in which attribute ‘Y’ is present is called as the referenced relation.
The relation in which attribute ‘X’ is present is called as the referencing relation.
The attribute ‘Y’ might be present in the same table or in some other table.
Example-
Consider the following two schemas-
Here, t_dept can take only those values which are present in dept_no in Department table since only
those departments actually exist.
NOTES-
Foreign key references the primary key of the table.
Foreign key can take only those values which are present in the primary key of the referenced
relation.
Foreign key may have a name other than that of a primary key.
Foreign key can take the NULL value.
There is no restriction on a foreign key to be unique.
In fact, foreign key is not unique most of the time.
Referenced relation may also be called as the master table or primary table.
Referencing relation may also be called as the foreign table.
6. Partial Key-
Partial key is a key using which all the records of the table can not be identified uniquely.
However, a bunch of related tuples can be selected from the table using the partial key.
Example-
Consider the following schema-
Department ( Emp_no , Dependent_name , Relation )
E1 Suman Mother
E1 Ajay Father
E2 Vijay Father
E2 Ankush Son
Here, using partial key Emp_no, we can not identify a tuple uniquely but we can select a bunch of
tuples from the table.
7. Composite Key-
A primary key comprising of multiple attributes and not just a single attribute is called as a composite
key.
8. Unique Key-
Unique key is a key with the following properties-
It is unique for all the records of the table.
Once assigned, its value can not be changed i.e. it is non-updatable.
It may have a NULL value.
Example-
The best example of unique key is Adhaar Card Numbers.
The Adhaar Card Number is unique for all the citizens (tuples) of India (table).
If it gets lost and another duplicate copy is issued, then the duplicate copy always has the same
number as before.
Thus, it is non-updatable.
Few citizens may not have got their Adhaar cards, so for them its value is NULL.
9. Surrogate Key-
Surrogate key is a key with the following properties-
It is unique for all the records of the table.
It is updatable.
It can not be NULL i.e. it must have some value.
Example-
Mobile Number of students in a class where every student owns a mobile phone.
SQL Subqueries
An SQL Subquery, is a SELECT query within another query. It is also known as Inner
query or Nested query and the query containing it is the outer query.
The outer query can contain the SELECT, INSERT, UPDATE, and DELETE statements. We can
use the subquery as a column expression, as a condition in SQL clauses, and with operators
like =, >, <, >=, <=, IN, BETWEEN, etc.
Rules to be followed
Following are the rules to be followed while writing subqueries −
Subqueries must be enclosed within parentheses.
A subquery must contain the SELECT query and the FROM clause always.
A subquery consists of all the clauses an ordinary SELECT clause can contain: GROUP BY,
WHERE, HAVING, DISTINCT, TOP/LIMIT, etc. However, an ORDER BY clause is only used
when a TOP clause is specified. It can't include COMPUTE or FOR BROWSE clause.
A subquery can return a single value, a single row, a single column, or a whole table.
They are called scalar subqueries.
Learn SQL in-depth with real-world projects through our SQL certification course. Enroll
and become a certified expert to boost your career.
Example
In the following query, we are creating a table named CUSTOMERS −
Open Compiler
Open Compiler
Open Compiler
SELECT * FROM CUSTOMERS WHERE ID IN (SELECT ID FROM CUSTOMERS WHERE SALARY >
4500);
Example
In the following example, we are creating another table CUSTOMERS_BKP with similar
structure as CUSTOMERS table −
Open Compiler
Now to copy the complete records of CUSTOMERS table into the CUSTOMERS_BKP table, we
can use the following query −
Open Compiler
Verification
Using the SELECT statement, we can verify whether the records from CUSTOMERS table
have been inserted into CUSTOMERS_BKP table or not −
Open Compiler
Example
We have the CUSTOMERS_BKP table available which is backup of CUSTOMERS table. The
following example updates SALARY by 0.25 times in the CUSTOMERS table for all the
customers whose AGE is greater than or equal to 27.
Open Compiler
UPDATE CUSTOMERS SET SALARY = SALARY * 0.25 WHERE AGE IN (SELECT AGE FROM
CUSTOMERS_BKP WHERE AGE >= 27 );
Verification
This would impact two rows and if you verify the contents of the CUSTOMERS using the
SELECT statement as shown below.
Open Compiler
Example
We have a CUSTOMERS_BKP table available which is a backup of the CUSTOMERS table. The
following example deletes the records from the CUSTOMERS table for all the customers
whose AGE is greater than or equal to 27.
Open Compiler
DELETE FROM CUSTOMERS WHERE AGE IN (SELECT AGE FROM CUSTOMERS_BKP WHERE AGE >= 27
);
Verification
If you verify the contents of the CUSTOMERS table using the SELECT statement as shown
below.
Open Compiler
A NUMBER(8,2);
B NUMBER(8);
C NUMBER;
8 MARKS:=
Flat Data
Model
An entity has a real world property called attribute and attribute define by a set of values
called domain. For example, in a university a student is an entity, university is the database,
name and age and sex are the attributes. The relationships among entities define the logical
association between entities.
Network Model
Context
Model
Therefore, this support different types of users and differ by the interaction of users in
database and also the data models in DBMS brought a revolutionary change in industries by
the handling of relevant data. The data models in DBMS are the systems that help to use and
create databases, as we have seen there are different types of data models and depending
on the kind of structure needed we can select the data model in DBMS.
Example
Roll number
Name
Branch
Age
Types of attributes
The different types of attributes are as follows −
Composite attribute
It can be divided into smaller sub parts, each sub part can form an independent attribute.
For example −
Name
FirstName MiddelName LastName
For example −
Phone number
PIN code
Single valued Attribute
Attributes having a single value for a particular item is called a single valued attribute.
Multi-valued Attribute
Attribute having a set of values for a single entity is called a multi-valued attribute.
For example −
e-mail
Tel.No
Hobbies
Derived Attributes or stored Attributes
When one attribute value is derived from the other is called a derived attribute.
Age is the derived attribute.
DOB is the stored attribute.
Complex Attribute
For example
If a person has more than one house and each house has more than one phone. Then, that
attribute phone is represented as a complex attribute.