DBMS SQL
DBMS SQL
information.
Information is data that has been processed, organized, and presented in a meaningful way.
Database is a collection of related data. A database management
system stores data in such a way that it becomes easier to retrieve, manipulate,
and produce information.
Properties-
Database schema is the skeleton structure that represents the logical view
of the entire database. It defines how the data is organized and how the
relations among them are associated. It formulates all the constraints that
are to be applied on the data. It is designed when the database doesn't exist
at all. Once the database is operational, it is very difficult to make any
changes to it. A database schema does not contain any data or information.
Types of Attributes
Simple attribute − Simple attributes are atomic values, which
cannot be divided further. For example, a student's phone
number is an atomic value of 10 digits.
Composite attribute − Composite attributes are made of more
than one simple attribute. For example, a student's complete
name may have first_name and last_name.
Derived attribute − Derived attributes are the attributes that do
not exist in the physical database, but their values are derived
from other attributes present in the database. For example,
average_salary in a department should not be saved directly in
the database, instead it can be derived. For another example,
age can be derived from data_of_birth.
Single-value attribute − Single-value attributes contain single
value. For example − Social_Security_Number.
Multi-value attribute − Multi-value attributes may contain more
than one values. For example, a person can have more than one
phone number, email_address, etc.
KEYS
Super Key − A set of attributes (one or more) that collectively
identifies an entity in an entity set.
Candidate Key − A minimal super key is called a candidate key.
An entity set may have more than one candidate key.
Primary Key − A primary key is one of the candidate keys
chosen by the database designer to uniquely identify the entity
set.
https://www.youtube.com/watch?v=CsGalH0QKbs
ENTITY-ATTRIBUTE
AGE: DERIVED,
PHONE-MULTIVAL
Relationship in /\ boxes.
\/
Dr Edgar F. Codd, after his extensive research on the Relational Model of database
systems, came up with twelve rules of his own, which according to him, a database
must obey in order to be regarded as a true relational database.
Eg- Information Rule,Guaranteed access rule, Data independence and other data
rules etc. Should be in table cells. Accessed by rows and columns etc
Functional dependency (FD) is a set of constraints between two attributes
in a relation. Functional dependency says that if two tuples have same
values for attributes A1, A2,..., An, then those two tuples must have to have
same values for attributes B1, B2, ..., Bn.
Normalization
If a database design is not perfect, it may contain anomalies, which are like a
bad dream for any database administrator. Managing a database with
anomalies is next to impossible.
Update anomalies − If data items are scattered and are not
linked to each other properly, then it could lead to strange
situations. For example, when we try to update one data item
having its copies scattered over several places, a few instances
get updated properly while a few others are left with old values.
Such instances leave the database in an inconsistent state.
Deletion anomalies − We tried to delete a record, but parts of
it was left undeleted because of unawareness, the data is also
saved somewhere else.
Insert anomalies − We tried to insert data in a record that does
not exist at all.
Normalization is a method to remove all these anomalies and bring the
database to a consistent state.
We see here in Student_Project relation that the prime key attributes are
Stu_ID and Proj_ID. According to the rule, non-key attributes, i.e. Stu_Name
and Proj_Name must be dependent upon both and not on any of the prime
key attribute individually. But we find that Stu_Name can be identified by
Stu_ID and Proj_Name can be identified by Proj_ID independently. This is
called partial dependency, which is not allowed in Second Normal Form.
Boyce-Codd Normal Form
Boyce-Codd Normal Form (BCNF) is an extension of Third Normal Form on
strict terms. BCNF states that −
For any non-trivial functional dependency, X → A, X must be a super-
key.
In the above image, Stu_ID is the super-key in the relation Student_Detail
and Zip is the super-key in the relation ZipCodes. So,
and
Zip → City
Join is a combination of a Cartesian product followed by a selection process. A Join
operation pairs two tuples from different relations, if and only if a given join
condition is satisfied.
taking a Cartesian product of two relations, which gives us all the possible tuples
that are paired together. But it might not be feasible for us in certain cases to take a
Cartesian product where we encounter huge relations with thousands of tuples
having a considerable large number of attributes.
Cartesian product
Natural Join
Natural join acts on those matching attributes where the values of attributes in both
the relations are same. Like to join two tables, it takes the common attributes and
joins the tables.
Theta Join, Equijoin, and Natural Join are called inner joins. An inner join includes
only those tuples with matching attributes and the rest are discarded in the
resulting relation.
three kinds of outer joins − left outer join, right outer join, and full outer join.