DBMS 1
DBMS 1
INTRODUCTION OF DBMS
WHAT IS DATABASE ?
The database is a collection of inter-related data which is used to retrieve, insert and delete the data efficiently. It is
also used to organize the data in the form of a table, schema, views, and reports, etc.
For example: The college Database organizes the data about the admin, staff, students and faculty etc.
Using the database, you can easily retrieve, insert, and delete the information.
SCHEMA :- A database schema is a logical representation of data that shows how the data in a database should
be stored logically.
VIEWS:-
•Views in SQL are considered as a virtual table. A view also contains rows and columns.
•To create the view, we can select the fields from one or more tables present in the database.
•A view can either have specific rows based on certain condition or all the rows of a table.
Database Management System
•Database management system is a software which is used to manage the database. For
example: MySQL, Oracle, etc are a very popular commercial database which is used in different applications.
•DBMS provides an interface to perform various operations like database creation, storing data in it, updating data,
creating a table in the database and a lot more.
•It provides protection and security to the database. In the case of multiple users, it also maintains data
consistency.
•It can provide a clear and logical view of the process that manipulates data.
•It contains ACID properties which maintain data in a healthy state in case of failure.
•It can view the database from different viewpoints according to the requirements of the user.
Advantages of DBMS
•Controls database redundancy: It can control data redundancy because it stores all the data in one single
database file and that recorded data is placed in the database.
•Data sharing: In DBMS, the authorized users of an organization can share the data among multiple users.
•Easily Maintenance: It can be easily maintainable due to the centralized nature of the database system.
•Reduce time: It reduces development time and maintenance need.
•Backup: It provides backup and recovery subsystems which create automatic backup of data
from hardware and software failures and restores the data if required.
•multiple user interface: It provides different types of user interfaces like graphical user interfaces, application
program interfaces
Disadvantages of DBMS
•Cost of Hardware and Software: It requires a high speed of data processor and large memory size to run
DBMS software.
•Size: It occupies a large space of disks and large memory to run them efficiently.
•Complexity: Database system creates additional complexity and requirements.
•Higher impact of failure: Failure is highly impacted the database because in most of the organization, all the
data stored in a single database and if the database is damaged due to electric failure or database corruption then
the data may be lost forever.
ACID PROPERTIE
A means Atomicity: This ensures the data operation will complete either with
success or with failure. It follows the 'all or nothing' strategy. For example, a
transaction will either be committed or will abort.
C means Consistency: If we perform any operation over the data, its value before
and after the operation should be preserved. For example, the account balance
before and after the transaction should be correct, i.e., it should remain conserved.
I means Isolation: There can be concurrent users for accessing data at the same
time from the database. Thus, isolation between the data should remain isolated.
For example, when multiple transactions occur at the same time, one transaction
effects should not be visible to the other transactions in the database.
D means Durability: It ensures that once it completes the operation and commits
the data, data changes should remain permanent.
Types of Databases
1) Centralized Database
It is the type of database that stores data at a centralized database system. It comforts the users to access the
stored data from different locations through several applications. These applications contain the authentication
process to let users access data securely. An example of a Centralized database can be Central Library that
carries a central database of each library in a college/university.
•Homogeneous DDB: Those database systems which execute on the same operating system and use
the same application process and carry the same hardware devices.
•Heterogeneous DDB: Those database systems which execute on different operating systems under
different application procedures, and carries different hardware devices.
All modern database management systems like SQL, MS SQL Server, IBM DB2, ORACLE, My-SQL, and
Microsoft Access are based on RDBMS.
HOW IT WORKS
Data is represented in terms of tuples (rows) in RDBMS.
A relational database is the most commonly used database. It contains several tables, and each table has its
primary key.
Due to a collection of an organized set of tables, data can be accessed easily in RDBMS.
Name Id Phone No.
GEETANSH 1 8976543011
ANKUR 2 8976543011
JATIN 3 4556678992
ASHU 4 9876654335
DIFFERENCE BETWEEN DBMS AND RDBMS
DBMS RDBMS
1) DBMS applications store data as file. RDBMS applications store data in a tabular form.
2) In DBMS, data is generally stored in either a In RDBMS, the tables have an identifier called primary
hierarchical form or a navigational form. key and the data values are stored in the form of tables.
Security and ProtectionDBMS provides a good protection mechanism. It isn't easy to protect a file under the file system.
Recovery Mechanism DBMS provides a crash recovery mechanism, i.e., DBMS protects the user from The file system doesn't have a crash mechanism, i.e., if the system crashes while
system failure. entering some data, then the content of the file will be lost.
Manipulation DBMS contains a wide variety of sophisticated techniques to store and retrieve The file system can't efficiently store and retrieve the data.
Techniques the data.
Concurrency Problems DBMS takes care of Concurrent access of data using some form of locking. In the File system, concurrent access has many problems like redirecting the file
while deleting some information or updating some information.
Where to use Database approach used in large systems which interrelate many files. File system approach used in large systems which interrelate many files.
Cost The database system is expensive to design. The file system approach is cheaper to design.
Data Redundancy and Due to the centralization of the database, the problems of data redundancy and In this, the files and application programs are created by different programmers
Inconsistency inconsistency are controlled. so that there exists a lot of duplication of data which may lead to inconsistency.
Structure The database structure is complex to design. The file system approach has a simple structure.
Data Independence •In this system, Data Independence exists, and it can be of two types.Logical In the File system approach, there exists no Data Independence.
Data Independence
•Physical Data Independence
Integrity Constraints Integrity Constraints are easy to apply. Integrity Constraints are difficult to implement in file system.
Data Models •In the database approach, 3 types of data models exist:Hierarchal data models In the file system approach, there is no concept of data models exists.
•Network data models
•Relational data models
Flexibility Changes are often a necessity to the content of the data stored in any system, The flexibility of the system is less as compared to the DBMS approach.
and these changes are more easily with a database approach.
•The DBMS design depends upon its architecture. The basic client/server
architecture is used to deal with a large number of PCs, web servers, database
servers and other components that are connected with networks.
•The client/server architecture consists of many PCs and a workstation which are
connected via the network.
•DBMS architecture depends upon how users are connected to the database to get
their request done.
Types of DBMS Architecture
1-Tier Architecture
•In this architecture, the database is directly available to the user. It means the user can directly sit on the DBMS
and uses it.
•Any changes done here will directly be done on the database itself. It doesn't provide a handy tool for end users.
•The 1-Tier architecture is used for development of the local application, where programmers can directly
communicate with the database for the quick response.
2-Tier Architecture
•The 2-Tier architecture is same as basic client-server. In the two-tier architecture, applications on the client end
can directly communicate with the database at the server side. For this interaction, API's like: ODBC, JDBC are
used.
•The user interfaces and application programs are run on the client-side.
•The server side is responsible to provide the functionalities like: query processing and transaction management.
•To communicate with the DBMS, client-side application establishes a connection with the server side.
3-Tier Architecture
•The 3-Tier architecture contains another layer between the client and server. In this architecture, client can't directly
communicate with the server.
•The application on the client-end interacts with an application server which further communicates with the database
system.
•End user has no idea about the existence of the database beyond the application server. The database also has no
idea about any other user beyond the application.
•The 3-Tier architecture is used in case of large web application.
Data Models
Data Model is the modeling of the data description, data semantics, and consistency constraints of the data. It
provides the conceptual tools for describing the design of a database at each level of data abstraction. Therefore,
there are following four data models used for understanding the structure of the database:
1) Relational Data Model: This type of model designs the data in the form of rows and columns within a table.
Thus, a relational model uses tables for representing data and in-between relationships. Tables are also called
relations. This model was initially described by Edgar F. Codd, in 1969. The relational data model is the widely used
model which is primarily used by commercial data processing applications.
2) Entity-Relationship Data Model: An ER model is the logical representation of data as objects and relationships
among them. These objects are known as entities, and relationship is an association among these entities. This
model was designed by Peter Chen and published in 1976 papers. It was widely used in database designing. A set
of attributes describe the entities. For example, student_name, student_id describes the 'student' entity. A set of the
same type of entities is known as an 'Entity set', and the set of the same type of relationships is known as
'relationship set'.
3) Object-based Data Model: An extension of the ER model with notions of
functions, encapsulation, and object identity, as well. This model supports a rich type
system that includes structured and collection types. Thus, in 1980s, various
database systems following the object-oriented approach were developed. Here, the
objects are nothing but the data carrying its properties.
4) Semistructured Data Model: This type of data model is different from the other
three data models (explained above). The semistructured data model allows the data
specifications at places where the individual data items of the same type may have
different attributes sets. The Extensible Markup Language, also known as XML, is
widely used for representing the semistructured data. Although XML was initially
designed for including the markup information to the text document, it gains
importance because of its application in the exchange of data.
KEYS
•Keys play an important role in the relational database.
•It is used to uniquely identify any record or row of data from the table. It is also used to establish and identify relationships between tables.
For example, ID is used as a key in the Student table because it is unique for each student. In the PERSON table, passport_number,
license_number, SSN are keys since they are unique for each person.
1.Primary key
•It is the first key used to identify one and only one instance of an entity uniquely. An entity can contain multiple
keys, as we saw in the PERSON table. The key which is most suitable from those lists becomes a primary key.
•In the EMPLOYEE table, ID can be the primary key since it is unique for each employee. In the EMPLOYEE table,
we can even select License_Number and Passport_Number as primary keys since they are also unique.
•For each entity, the primary key selection is based on requirements and developers.
Candidate key
•A candidate key is an attribute or set of attributes that can uniquely identify a tuple.
•Except for the primary key, the remaining attributes are considered a candidate key. The candidate keys are as
strong as the primary key.
For example: In the EMPLOYEE table, id is best suited for the primary key. The rest of the attributes, like SSN,
Passport_Number, License_Number, etc., are considered a candidate key.
Super Key
Super key is an attribute set that can uniquely identify a tuple. A super key is a superset of a candidate key.
For example: In the above EMPLOYEE table, for(EMPLOEE_ID, EMPLOYEE_NAME), the name of two
employees can be the same, but their EMPLYEE_ID can't be the same. Hence, this combination can also be a
key.
The super key would be EMPLOYEE-ID (EMPLOYEE_ID, EMPLOYEE-NAME), etc.
Foreign key
•Foreign keys are the column of the table used to point to the primary key of another table.
•Every employee works in a specific department in a company, and employee and department are two different
entities. So we can't store the department's information in the employee table. That's why we link these two tables
through the primary key of one table.
•We add the primary key of the DEPARTMENT table, Department_Id, as a new attribute in the EMPLOYEE table.
•In the EMPLOYEE table, Department_Id is the foreign key, and both the tables are related.
Alternate key
There may be one or more attributes or a combination of attributes that uniquely identify each tuple in a relation.
These attributes or combinations of the attributes are called the candidate keys. One key is chosen as the primary
key from these candidate keys, and the remaining candidate key, if it exists, is termed the alternate key. In other
words, the total number of the alternate keys is the total number of candidate keys minus the primary key. The
alternate key may or may not exist. If there is only one candidate key in a relation, it does not have an alternate key.
For example, employee relation has two attributes, Employee_Id and PAN_No, that act as candidate keys. In this
relation, Employee_Id is chosen as the primary key, so the other candidate key, PAN_No, acts as the Alternate key.
Composite key
Whenever a primary key consists of more than one attribute, it is known as a composite key. This key is also
known as Concatenated Key.
For example, in employee relations, we assume that an employee may be assigned multiple roles, and an
employee may work on multiple projects simultaneously. So the primary key will be composed of all three
attributes, namely Emp_ID, Emp_role, and Proj_ID in combination. So these attributes act as a composite key
since the primary key comprises more than one attribute.
|| OR OPERATOR
• ASCENDING
• DESCENDING
DESCENDING ORDER
ASCENDING ORDER
TWO QUERIES IN ONE
DIFFERENCE BETWEEN DROP DELETE AND TRUNCATE