Академический Документы
Профессиональный Документы
Культура Документы
INTRODUCTION
TO
DBMS
DBMS
Data is generally raw and unprocessed like age ,
name which can be processed and store in
computer.
What is a Database?
A Database is a collection of related data
organized in a way that data can be easily
accessed, managed and updated.
Introduction to DBMS
• A DBMS is a software that allows creation,
definition and manipulation of database,
allowing users to store, process and analyze data
easily.
• Examples:
• MySql
• Oracle
DATABASE MANAGEMENT SYSTEMS
Data
The data in a database is stored physically on the storage
devices. In a database, data is a separate entity from the
software that accesses it.
Users
Procedures
The last component of a DBMS is a set of procedures or
rules that should be clearly defined and followed by the users
of the database.
File Based Systems Disadvantage
• Data redundancy and inconsistency
• Data isolation (other user can’t see the transitions of one user)
• Security problems
DBMS vs. File System
• DBMS is very expensive but, the traditional file system is cheap.
• DBMS is good for the large system but, the traditional file system
is good for a small system having a small number of items.
• DBMS required lots of effort for designing but, the traditional file
system needs very low design efforts.
• DBMS is highly secured but, the traditional file system is not
secure.
• DBMS is data sharable but, the traditional file system does not
allow data sharing.
• DBMS is flexible but, the traditional file system has a lack of
flexibility and has many limitations.
• DBMS has a complex backup system but, the traditional file
system has a simple backup system.
ADVANTAGES OF DBMS
Conceptual level
Teaches
Cardinality
• Cardinality is the number of occurrences of an
entity from a relation that can be associated with
the number of occurrences in another relation.
• It is also known as degree of relationship.
One-to-one
• When only one instance of an entity is
associated with the relationship, it is marked
as '1:1'.
One-to-many
• When more than one instance of an entity is
associated with a relationship, it is marked as '1:N'.
• Example: An employee can also work for multiple
departments at one time.
Many-to-one
• When more than one instance of entity is
associated with the relationship, it is marked
as 'N:1'.
Many-to-many
• The following image reflects that more than one
instance of an entity on the left and more than
one instance of an entity on the right can be
associated with the relationship.
Example of Many to Many
• Each department can have any number of
employees working on a specific task.
Attributes
• Attributes are the properties of entities.
Attributes are represented by means of
ellipses.
Types of attributes
• Identifying Attribute is used to uniquely identify
an instance of an entity.
• Simple and composite attribute
• Stored and derived attribute
• Single valued and multi valued
Simple Attribute
Attribute Roll_No can not be sub-
divided further.
Composite Attribute
• Name is a composite attribute which can be
further subdivided in first name and last name
Multivalued attributes are depicted by
double ellipse.
• PhoneNo is a multivalued attribute because it has
multiple values for the same entity student
Stored and derived Attribute
• Derived attribute : age
• Stored attribute: BirthDate
A very simple E-R diagram with three entity sets, their attributes and
the relationship between the entity sets.
• Primary key:{Stu_Id}
Candidate key
A candidate key is a set of columns, in a table that can uniquely
identify any database record without referring to any other data.
SYNTAX
• ALTER TABLE table_name
ADD column_name datatype;
EXAMPLE
• ALTER TABLE Customers
ADD Email varchar(255);
EXAMPLE
DROP TABLE STUDENT;
This command will delete the student table
RENAME COMMAND
EXAMPLE
• SELECT * FROM table_name;
Select Example
INSERT
SYNTAX
• INSERT INTO table_name (column1, column2,
column3, ...)
VALUES (value1, value2, value3, ...);
Example
• INSERT INTO Customers (CustomerName, City,
Country)
• VALUES ('Cardinal', 'Stavanger', 'Norway');
Insert Example
Update
• UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
• UPDATE Customers
SET ContactName = 'Alfred Schmidt',
City= 'Frankfurt'
WHERE CustomerID = 1;
Update Example
DELETE
Syntax
• DELETE FROM table_name WHERE condition;
Example:
Delete from Student where name=‘RAM’;
SQL
AGGREGATE FUNCTIONS
69
Introduction
• An aggregate function allows you to perform a
calculation on a set of values to return a single
scalar value
70
SQL Aggregate Functions
1. Count
COUNT function is the simplest function and
very useful in counting the number of
records.
Example
72
SQL Aggregate Functions
2. MAX
SQL MAX function is used to find out the record with
maximum value among a record set.
73
Example
Output
SQL Aggregate Functions
3. MIN
SQL MIN function is used to find out the
record with minimum value among a record
set.
Example
Output
4. AVG
• SQL AVG function is used to find out the
average of a field in various records.
Example
Output
5. SUM
• SQL SUM function is used to find out the sum
of a field in various records.
Example
Output
Normalization
Student_Detail
The above table is not in 3NF because it has a transitive functional dependency:
Stu_ID City
City Zip
Hence Stu_ID Zip
The above states the relation <Student_Detail> violates the 3rd Normal Form
(3NF).
To remove the violation, you need to split the tables and remove the transitive
functional dependency.
Student_Details Zipcode
BCNF
Boyce-Codd Normal Form (BCNF) is an extension of
Third Normal Form on strict terms.
BCNF states that –
•For any functional dependency, X → A, X must be
a super-key.
•In the given relations, Stu_ID is the super-key in
the relation Student_Detail and Zip is the super-
key in the relation ZipCodes.
•So, Stu_ID → Stu_Name, Zip and Zip → City Which
confirms that both the relations are in BCNF.