0% found this document useful (0 votes)
9 views

Intro To Database

fuyty8o h

Uploaded by

quratulain2464
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Intro To Database

fuyty8o h

Uploaded by

quratulain2464
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Introduction to Databases

1. Database:
A database is information that is set up for easy access, management and updating. Computer
databases typically store aggregations of data records or files that contain information, such as sales
transactions, customer data, financials and product information.
Or
It is a collection of data, or information, that is specially organized for rapid search and retrieval by a
computer. Databases are structured to facilitate the storage, retrieval, modification, and deletion of data in
conjunction with various data-processing operations. A database management system (DBMS) extracts
information from the database in response to queries.

2. Uses (e.g.):
• Improve business processes. Companies collect data about business processes, such sales,
order processing and customer service. They analyze that data to improve these processes,
expand their business and grow revenue.
• Keep track of customers. Databases often store information about people, such as
customers or users. For example, social media platforms use databases to store user
information, such as names, email addresses and user behavior. The data is used to
recommend content to users and improve the user experience.
• Secure personal health information. Healthcare providers use databases to securely store
personal health data to inform and improve patient care.
• Store personal data. Databases can also be used to store personal information. For
example, personal cloud storage is available for individual users to store media, such as
photos, in a managed cloud.

3. DBMS: Database management System (DBMS) A DBMS


enables users to create and manage a database. It also helps
users create, read, update and delete data in a database, and it
assists with logging and auditing functions. The DBMS
provides physical and logical independence from data. Users
and applications do not need to know either the physical or
logical locations of data. A DBMS can also limit and control
access to the database and provide different views of the same
database schema to multiple users.
4. Types of Databases:
1. Relational: Relational databases are comprised of tables. Data is placed into predefined
categories in those tables. Each
table has columns with at least
one data category, and rows that
have a certain data instance for
the categories which are defined
in the columns. Information in a
relational database about a
specific customer is organized
into rows, columns and tables.
These are indexed to make it
easier to search using SQL or

Wahaj Ali Lecturer, Department of I.T


The Islamia University of Bahawalpur
Introduction to Databases
NoSQL queries. Relational databases use SQL in their user and application program
interfaces. A new data category can easily be added to a relational database without having
to change the existing applications. A relational database management system (RDBMS)
is used to store, manage, query and retrieve data in a relational database.
Typically, the RDBMS gives users the ability to control read/write access, specify report
generation and analyze use. Some databases offer atomicity, consistency, isolation and
durability, or ACID, compliance to guarantee that data is consistent and that transactions
are complete.

ACID Properties:
1. Atomicity: All changes to data are performed as if they are a single operation. That is, all
the changes are performed, or none of them are. For example, in an application that
transfers funds from one account to another, the atomicity property ensures that, if a debit
is made successfully from one account, the corresponding credit is made to the other
account.
2. Consistency: Data is in a consistent state when a transaction starts and when it ends. For
example, in an application that transfers funds from one account to another, the consistency
property ensures that the total value of funds in both the accounts is the same at the start
and end of each transaction.
3. Isolation: The intermediate state of a transaction is invisible to other transactions. As a
result, transactions that run concurrently appear to be serialized. For example, in an
application that transfers funds from one account to another, the isolation property ensures
that another transaction sees the transferred funds in one account or the other, but not in
both, nor in neither.
4. Durability: After a transaction successfully completes, changes to data persist and are not
undone, even in the event of a system failure. For example, in an application that transfers
funds from one account to another, the durability property ensures that the changes made
to each account will not be reversed.

2. Distributed: This database stores records or files in several physical locations. Data
processing is also spread out and
replicated across different parts of
the network. Distributed
databases can be homogeneous,
where all physical locations have
the same underlying hardware and
run the same operating systems
and database applications. They
can also be heterogeneous. In
those cases, the hardware, OS and
database applications can be
different in the various locations.
Cloud. These databases are built in a public, private or hybrid cloud for a virtualized
environment. Users are charged based on how much storage and bandwidth they use. They
also get scalability on demand and high availability. These databases can work with
applications deployed as software as a service.

Wahaj Ali Lecturer, Department of I.T


The Islamia University of Bahawalpur
Introduction to Databases
3. NoSQL: NoSQL (Not only Sql) databases are good when dealing with large collections
of distributed data. They can
address big data performance issues
better than relational databases.
They also do well analyze large
unstructured data sets and data on
virtual servers in the cloud. These
databases can also be called non-
relational databases. Object-
oriented. These databases hold data
created using object-oriented programming languages. They focus on organizing objects
rather than actions and data rather than logic. For instance, an image data record would be
a data object, rather than an alphanumeric value.
4. Graph: These databases are a type of NoSQL database. They store, map and query
relationships using concepts from
graph theory. Graph databases are
made up of nodes and edges. Nodes
are entities and connect the nodes.
These databases are often used to
analyze interconnections. Graph
databases are often used to analyze
data about customers as they
interact with a business on

Wahaj Ali Lecturer, Department of I.T


The Islamia University of Bahawalpur
Introduction to Databases
webpages and in social media. Graph databases use SPARQL, a declarative programming
language and protocol, for analytics. SPARQL can perform all the analytics that SQL can
perform, and can also be used for semantic analysis, or the examination of relationships.
This makes it useful for performing analytics on data sets that have both structured and
unstructured data. SPARQL lets users perform analytics on information stored in a
relational database, as well as friend-of-a-friend relationships, PageRank and shortest path.

5. Database Table:
A database table is a structure that organizes data into rows and columns – forming a grid. Tables
are similar to a worksheet in
spreadsheet applications. The rows run
horizontally and represent each record.
The columns run vertically and
represent a specific field. The rows and
columns intersect, forming a grid. The
intersection of the rows and columns
defines each cell in the table. The
header cell of a column usually displays
the name of the column. The column is
usually named to reflect the contents of
each cell in that column. For example, a
column name of FirstName could be
used to reflect that the cells will contain the first name of an individual. The rows don’t typically
have a header cell as such, but often the first column will contain a unique identifier – such as an
ID. This field is often assigned as the primary key, as a primary key requires a unique identifier
(i.e. the value of this field will be different for each record). This means that we can identify each
record by its ID (or other unique identifier). Therefore, tables can reference records in other tables
simply by referring to the record’s primary key value. In this case, the tables have a relationship.
This is where the relational part comes from relational database management systems.
6. Relationships among tables (entities):
1. One-to-one relationship: In a one-to-one relationship, a record in one table can
correspond to only one record in another table (or in
some cases, no records). One-to-one relationships
aren’t the most common, since in many cases you can
store corresponding information in the same table.
Whether you split up that information into multiple
tables depends on your overall data model and design
methodology; if you’re keeping tables as narrowly-
focused as possible (like in a normalized database),
then you may find one-to-one relationships useful.

Wahaj Ali Lecturer, Department of I.T


The Islamia University of Bahawalpur
Introduction to Databases
2. One-to-Many relationship: One-to-many relationships are the most common type
of relationships between tables in a database. In a one-to-many (sometimes called many-
to-one) relationship, a record in one
table corresponds to zero, one, or
many records in another table. For
example, think about tables for
customers and their orders, In this
case, one customer can place many
orders, and those multiple order
records will all link back to a single
record in the People table. That
connection is codified through the
User_ID field, which is a primary key
in the People table and a foreign key in the Orders table.
3. Many to Many relationship: A many-to-many relationship indicates that multiple
records in a table are linked to multiple records
in another table. Those records may only be
associated with a single record (or none at all)
but the key is that they can and often are linked
to more than one. Many-to-many relationships
aren’t very common in practical database use
cases, since adhering to normalization often
involves breaking up many-to-many
relationships into separate, more focused tables.
In fact, your database system may not even
allow for the creation of a direct many-to-many
relationship, but you can get around this by
creating a third table, known as a join table, and
create one-to-many relationships between it and
your two starting tables.
4. Recursive relationship: also called Unary relationship. Relationship between two
entities of the same type is called recursive
relationship. A Recursive relationship is nothing but,
simply an entity is having a relationship with self.
Example: (1) The person who is a supervisor for
many other employees also come under employee’s
category. (2) Student can be a class monitor and
handle other students but a person who is working as
a class leader is itself a student of the class and hence a class monitor has a recursive
relationship of entity student.

Wahaj Ali Lecturer, Department of I.T


The Islamia University of Bahawalpur
Introduction to Databases
7. Cardinality vs Modality:
• Cardinality: It describes that a data
model must be able to represent the number
of occurrences (maximum) of an object/s in
a given relationship. It can be expressed in
the pattern of “one (|)” or “many (|∈ (crow’s
foot))”.
• Modality: Its value is computed as “o”
when there is no requirement for the
relationship to occur or if the relationship is
optional. The modality value is “1” if there
is a compulsion for the occurrence of a
relationship. In simple words, it describes
whether a relationship between two or more
entities is even required or not (minimum
occurrences).
8. RDBMS Keys:
Key: It is an attribute or set of attributes which helps you to identify a row(tuple) in a
relation(table). They allow you to find the relation between two tables. Keys help you uniquely
identify a row in a table by a combination of one or more columns in that table. Key is also helpful
for finding unique record or row from the table. Database key is also helpful for finding unique
record or row from the table.

Types:

“All Alternate Keys are Secondary keys but not all Secondary key are Alternate Keys.”

Wahaj Ali Lecturer, Department of I.T


The Islamia University of Bahawalpur
Introduction to Databases
9. Normalization in Tables:
• Normalization is the process of organizing the data in the database.
• Normalization is used to minimize the redundancy from a relation or set of relations. It is also
used to eliminate undesirable characteristics like Insertion, Update, and Deletion Anomalies.
• Normalization divides the larger table into smaller and links them using relationships.
• The normal form is used to reduce redundancy from the database table.
➢ Data modification anomalies:
1. Insertion Anomaly: Insertion Anomaly refers to when one cannot insert a new tuple into
a relationship due to lack of data.
2. Deletion Anomaly: The delete anomaly refers to the situation where the deletion of data
results in the unintended loss of some other important data.
3. Updation Anomaly: The update anomaly is when an update of a single data value requires
multiple rows of data to be updated.
❖ Normal Forms:

Wahaj Ali Lecturer, Department of I.T


The Islamia University of Bahawalpur
Introduction to Databases
❖ Dependencies in Normal Forms:
1. Partial Dependency:
▪ For a table to be in the Second Normal form, it should be in the First Normal form
and it should not have Partial Dependency.
▪ Partial Dependency exists, when for a composite primary key, any attribute in the
table depends only on a part of the primary key and not on the complete primary
key. (“This only exists in Composite Primary key”)
▪ To remove Partial dependency, we can divide the table, remove the attribute which
is causing partial dependency, and move it to some other table where it fits in well.

2. Transitive Dependency: When a non-prime attribute depends on other non-prime


attributes rather than depending upon the prime attributes or primary key, This means if
we have a primary key A and a non-key domain B and C where C is more dependent on B
than A and B is directly dependent on A, then C can be considered transitively dependent
on A.

3. Multi Valued Dependency:


A table is said to have multi-valued dependency, if the following conditions are true,
▪ For a dependency A → B, if for a single value of A, multiple value of B exists,
then the table may have multi-valued dependency.

Wahaj Ali Lecturer, Department of I.T


The Islamia University of Bahawalpur
Introduction to Databases
▪ Also, a table should have at-least 3 columns for it to have a multi-valued
dependency.
▪ And, for a relation R(A,B,C), if there is a multi-valued dependency between, A
and B, then B and C should be independent of each other.
If all these conditions are true for any relation(table), it is said to have multi-valued dependency.

4. Join Dependency:
▪ The join decomposition is like a further generalization of the Multivalued
dependencies.
▪ In case the join of X1 and X2 over C is equal to relation X, then one can say that
there exists a join dependency (JD).
▪ Where X1 and X2 are the decompositions X1(A, B, C) and X2(C, D) of a given
relation X (A, B, C, D).
▪ Alternatively, X1 and X2 are lossless forms of decomposition of X.
▪ A JD ⋈ {X1, X2,…, Xn} holds over a relation X if X1, X2,….., Xn is a lossless-
join type of decomposition.
▪ The *(A, B, C, D), (C, D) happen to be a Join Dependency of X if the join of the
join’s attribute happens to be equal to the relation X.
▪ Here, we use the *(X1, X2, X3) to indicate that relation X1, X2, X3 and so on are
a Join Decomposition of X.

Wahaj Ali Lecturer, Department of I.T


The Islamia University of Bahawalpur
Introduction to Databases
❖ Normalization vs Denormalization:

10.SQL: Structured Query Language, SQL is a database computer language designed for the retrieval
and management of data in a relational database like MySQL, MS Access, SQL Server, Oracle,
Sybase, Informix, Postgres etc. SQL stands for Structured Query Language. SQL was developed
in the 1970s by IBM Computer Scientists.
❖ Applications:
➢ Execute different database queries against a database.
➢ Define the data in a database and manipulate that data.
➢ Create data in a relational database management system.
➢ Access data from the relational database management system.
➢ Create and drop databases and tables.
➢ Create and maintain database users.
➢ Create view, stored procedure, functions in a database.
➢ Set permissions on tables, procedures and views.
❖ Sql Commands:
1. DDL (Data Definition Language):
It consists of the SQL commands that can be used to define the database schema.
It simply deals with descriptions of the database schema and is used to create and
modify the structure of database objects in the database. DDL is a set of SQL
commands used to create, modify, and delete database structures but not data.
These commands are normally not used by a general user, who should be accessing
the database via an application.
• CREATE: This command is used to create the database or its objects (like
table, index, function, views, store procedure, and triggers).
• DROP: This command is used to delete objects from the database.
• ALTER: This is used to alter the structure of the database.
• TRUNCATE: This is used to remove all records from a table, including
all spaces allocated for the records are removed.
• COMMENT: This is used to add comments to the data dictionary.

Wahaj Ali Lecturer, Department of I.T


The Islamia University of Bahawalpur
Introduction to Databases
• RENAME: This is used to rename an object existing in the database.
2. DQL (Data Query Language):
These are used for performing queries on the data within schema objects. The
purpose of the DQL Command is to get some schema relation based on the query
passed to it. We can define DQL as follows it is a component of SQL statement
that allows getting data from the database and imposing order upon it. It includes
the SELECT statement. This command allows getting the data out of the database
to perform operations with it. When a SELECT is fired against a table or tables the
result is compiled into a further temporary table, which is displayed or perhaps
received by the program i.e. a front-end.
• SELECT: It is used to retrieve data from the database.
3. DML (Data Manipulation Language):
The SQL commands that deals with the manipulation of data present in the
database belong to DML or Data Manipulation Language and this includes most
of the SQL statements. It is the component of the SQL statement that controls
access to data and to the database.
• INSERT: It is used to insert data into a table.
• UPDATE: It is used to update existing data within a table.
• DELETE: It is used to delete records from a database table.
• LOCK: Table control concurrency.
• CALL: Call a PL/SQL or JAVA subprogram. (opt)
• EXPLAIN PLAN: It describes the access path to data. (opt)
4. DCL (Data Control Language):
DCL includes commands such as GRANT and REVOKE which mainly deal with
the rights, permissions, and other controls of the database system.
• GRANT: This command gives users access privileges to the database.
• REVOKE: This command withdraws the user’s access privileges given
by using the GRANT command.
5. TCL (Transaction Control Language):
Transactions group a set of tasks into a single execution unit. Each transaction
begins with a specific task and ends when all the tasks in the group successfully
complete. If any of the tasks fail, the transaction fails. Therefore, a transaction has
only two results: success or failure.
• BEGIN: Opens a Transaction.
• COMMIT: Commits a Transaction.
• ROLLBACK: Rollbacks a transaction in case of any error occurs.
• SAVEPOINT: Sets a save point within a transaction.
• SET TRANSACTION: Specifies characteristics for the transaction.

Wahaj Ali Lecturer, Department of I.T


The Islamia University of Bahawalpur
Introduction to Databases

11.References:
1. https://in.indeed.com/career-advice/career-development/what-is-relationship-in-database
2. https://database.guide/what-is-a-table/
3. https://www.ibm.com/docs/en/cics-ts/5.4?topic=processing-acid-properties-transactions
4. https://www.metabase.com/learn/databases/table-relationships
5. https://prepinsta.com/dbms/recursive-relationship/
6. https://techdifferences.com/difference-between-cardinality-and-modality.html
7. https://www.javatpoint.com/dbms-normalization

Wahaj Ali Lecturer, Department of I.T


The Islamia University of Bahawalpur

You might also like