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

618164281-database-management-system-new-notes

A Database is an organized collection of similar data that allows for retrieval and processing of information. A Database Management System (DBMS) is software that manages data storage and retrieval, ensuring data integrity, security, and consistency. The document outlines various aspects of DBMS, including its applications, advantages, architecture, SQL commands, and functions.

Uploaded by

jackhacktivist17
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

618164281-database-management-system-new-notes

A Database is an organized collection of similar data that allows for retrieval and processing of information. A Database Management System (DBMS) is software that manages data storage and retrieval, ensuring data integrity, security, and consistency. The document outlines various aspects of DBMS, including its applications, advantages, architecture, SQL commands, and functions.

Uploaded by

jackhacktivist17
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Fundamentals of DBMS 1

Database:-

The term Database is made up of two words, i.e., Data and Base. Database
is a base for data. A database is organized collection of similar data and the organized
information serves as a base from which the desired information can be retrieved,
conclusions can be drawn and decisions can be made by further reorganizing or
processing this data.

Database Management System:

A database management system (DBMS) is software designed to store, retrieve,


define, and manage data. DBMS is a collection of interrelated data and a set of
programs to access that data. The primary goal of a DBMS is to provide a way to store
and retrieve database information that is both convenient and efficient. DBMS
software functions as an interface between the end user and the Database.

Applications of DBMS

Banking: For maintaining customer information, accounts, loans, and banking


transactions.

Universities: For maintaining student records, course registration and grades

Railway Reservation: For checking the availability of reservation in different trains,


tickets etc.

Airlines: For reservation and schedule information.

Telecommunication: For keeping records of calls made, generating monthly bills etc

Finance: For storing information about holidays, sales and purchases of financial
instruments.

Sales: For customer, product and purchase information.

Advantages of DBMS

1.Reduction in Data redundancy: it reduces duplication of data.

2. Reduction in inconsistency: Data is consistent every time because there is no


duplicate data present in the database.

Malik mehboob
Fundamentals of DBMS 2

3. Sharing of data: the users can share the data among themselves.

4. Data security: Data is secured centrally and it is easy to secure data.

5. Maintenance of data integrity: It means that the data is accurate and consistent in
the database.

6. Privacy: It means that only authorized users can access a database according to its
privacy constraint.

Entity

An entity is an object that has its existence in the real world. It includes those things
about which data is collected.

Releational Database Management System

A Relational database management system (RDBMS) is a database management


system that is based on relational model as introduced by E.F. Codd. It should satisfy
Codd’s 12 rules but in practice there is no DBMS that satisfies all these rules.

RDBMS stores data in the form of related tables. RDBMS are powerful
because they require few assumptions about how data is related or how it will be
extracted from the database. An important feature of relational systems is that a single
database can be spread across several tables.

Keys:

The integrity of the information stored in a database is controlled by keys. A key or


key field is a column value in a table that is used to either uniquely identify a row of
data in a table or establish a relationship with another table. A key is normally
correlated with one column in a table, although it might be associated with multiple
columns.

Primary Key: It denotes a key that is chosen by the database designer as the
principal means of identifying unique records within a table. The primary key should
be chosen in such a way that its value must not change. There should not be any
duplicacy in the record of primary key.

Malik mehboob
Fundamentals of DBMS 3

Candidate Key: A combination of one or more fields whose value uniquely identifies
a record in a table that is no two records in a table can have the same value.

Alternate Key: Any candidate key other than the one chosen as a primary key is
known as alternate key.

Foreign Key: A foreign key is the combination of one or more columns in a table
(parent table) or references a primary key in another table (child table).

Table

A table is a collection of related data held in a structured format within a database. It


consists of fields (columns) and rows. A table is a set of data elements using a model
of vertical columns and horizontal rows, the cell being the unit where a row and
column intersect.

Attributes: Attributes are units that describe the characteristics or properties of


entities. In a database, entities are represented by tables and attributes by columns. For
example a student entity might have numerous attributes such as ID, name, address
etc.

Domain: The domain of an attribute is the collection of all possible values an attribute
can have.

Field / Column: A column represents one related part of a table and is the smallest
logical structure of storage in a database. It holds one piece of information about on
item of subject.

Record / Row/tuples: A record is a collection of multiple related fields that can be


treated as a unit. In a database terminology, each row is a record. However database
experts prefer to use the word row.

Data integrity:

Data integrity refers to maintaining and assuring the accuracy and consistency of data
over its entire life cycle. Data integrity is a critical aspect to the design,
implementation and usage of any system which stores, processes or retrieves data.
Data integrity is the opposite of data corruption, which is a form of data loss.

Malik mehboob
Fundamentals of DBMS 4

Types of Integrity
Two types of data integrity are as follows:
Entity Integrity
The entity integrity is a constraint on primary key value. It states that any attribute of
a primary key cannot contain null value. If primary key contains null value, it is not
possible to uniquely identify a record in a relation. Entity integrity ensures that it
should be easy to identify each entity in the database.

Referential Integrity
The referential integrity is a constraint on foreign key value. It states that if a foreign
key exists in a relation, the foreign key value match the primary key value of some
tuple in its parent relation. Otherwise the foreign key value must be completely null.

Constraints

Constraints within a database are rules which control values allowed in columns and
also enforce the integrity between columns and tables. The different types of
constraints are null, not null, unique.

Null: if a particular row does not contain a data then it may be treated as null value.
Column of any data type may contain NULL unless the column was defined as NOT
NULL, when table was created.

NOT NULL: if a column is defined as NOT NULL , then it becomes a mandatory


column i.e., the user has to enter the data into it. It can take duplicate values if it is not
a unique column but cannot take NULLS.

UNIQUE: This is similar to primary key. It is used to ensure that information in the
column for each record is unique.

Architecture of DBMS

DBMS design depends upon its architecture. DBMS architecture depends upon how
users are connected to the Database to get their request done. Basically there are two
types of architecture of DBMS Two tier architecture and three tier architecture.

Malik mehboob
Fundamentals of DBMS 5

Two tier architecture

USER User

Application
Network

SDatabase server

The 2 tier architecture is same as basic client -server. The application is partioned into
a component that resides at the client machine. It invokes database system
functionality at the server machine through query language statements. Application
program interface standard like open database connectivity (ODBC) and java database
connectivity (JDBC) are used for interaction between the client and the server. Client
side establishes a connection with the server side to communicate.

Three tier Architecture

User

Malik mehboob
Fundamentals of DBMS 6

Application client Client

Network
Application server
Server Server

Database system

The 3-tier architecture contains another layer between the client and server. In this
architecture client can’t directly communicate with the server. The client machine
acts as merely a front end and does not contain any direct database calls. In three tier
architecture client end communicates with an application server through a forms
interface. The application server in turn communicates with a database system to
access data. Three tier applications are more appropriate for large applications and
for applications that run on World Wide Web.
Instance of database: the collection of information stored in the database at a
particular moment is called an instance of the database.

Schema: the overall design of the database is called the database schema.

SQL Commands:

SQL commands are instructions, coded into SQL statements, which are used to
communicate with the database to perform specific tasks, work, functions and queries
with data.

SQL commands can be used not only for searching the database but also to perform
various other functions for example, we can create tables, add data to tables, or
modify data, drop the table, set permissions for users. SQL commands are grouped
into four major categories depending on their functionality:

Data Definition Language (DDL) - These SQL commands are used for creating,
modifying, and dropping the structure of database objects. The commands are
CREATE, ALTER, DROP, RENAME, and TRUNCATE.

Malik mehboob
Fundamentals of DBMS 7

CREATE TABLE Statement


The CREATE TABLE Statement is used to create tables to store data. Integrity
Constraints like primary key, unique key, and foreign key can be defined for the
columns while creating the table
The Syntax for the CREATE TABLE Statement is:

CREATE TABLE table_name(column_name1datatype(size),column_name2

datatype(size),...column_name N datatype(size));

ALTER TABLE Statement


The SQL ALTER TABLE command is used to modify the definition (structure) of a
table by modifying the definition of its columns. The ALTER command is used to
perform the following functions.
1) Add, drop, and modify table columns

Syntax for add column: ALTER TABLE tablename ADD (columnname datatype
(size));

Syntax for Drop column: ALTER TABLE tablename DROP columnname;

Syntax for modify column: ALTER TABLE tablename MODIFY column


columnname;
2) Add and drop constraints
3) Enable and Disable constraints

Drop Table Statement:DROP TABLE statement is used to delete a table.


Syntax:

Drop Table tablename;

TRUNCATE: Truncate table command deletes the data inside a table but not the
table itself. Columns remain intact.

Syntax: TRUNCATE TABLE tablename;

Data Manipulation Language (DML) - These SQL commands are used for storing,
retrieving, modifying, and deleting data.

Malik mehboob
Fundamentals of DBMS 8

These Data Manipulation Language commands are: SELECT, INSERT, UPDATE,


and DELETE.

SQL SELECT Statement


The most commonly used SQL command is SELECT statement. SQL SELECT
statement is used to query or retrieve data from a table in the database. A query may
retrieve information from specified columns or from all of the columns in the table.
To create a simple SQL SELECT Statement, we must specify the column(s) name and
the table name. The whole query is called SQL SELECT Statement.
Syntax:
SELECT column_list FROM table-name;

SQL INSERT Statement


The INSERT Statement is used to add new rows of data to a table.
Syntax for SQL INSERT is:

INSERT INTO table_name VALUES (value1, value2, value3,...valueN);

SQL UPDATE Statement:


The UPDATE Statement is used to modify the existing rows in a table.
The Syntax for SQL UPDATE Command is:

UPDATE table_name SET (column_name=value);

SQL Delete Statement

The DELETE Statement is used to delete rows from a table. The DELETE statement
removes unwanted rows from a table. If the WHERE clause is not used, all the rows
in a table can be removed if there are no integrity constraints.
Syntax of a SQL DELETE Statement
DELETE FROM table_name [WHERE condition];

Where Clause

WHERE Clause is used to filter records. The WHERE clause is used to extract only
those records that fulfill a specified criterion.
Malik mehboob
Fundamentals of DBMS 9

Syntax:

SELECT column_name FROM table_name


WHERE = condition;

Transaction Control Language (TCL) - These SQL commands are used for
managing changes affecting the data. These commands are COMMIT, ROLLBACK,
and SAVEPOINT.

Commit: Commit command is used to permanently save any transaction into


database. The syntax is as :

Commit;

Rollback: This command restores the database to last commited state. It is also use
with savepoint command to jump to a savepoint in a transaction.

Syntax:

Rollback; OR Rollback to savepoint;

Savepoint: Savepoint command is used to temporarily save a transaction so that we


can rollback to that point whenever necessary

Syntax:
SAVEPOINT savepoint_name;

Data Control Language (DCL) - These SQL commands are used for providing
security to database objects. These commands are GRANT and REVOKE.

Sql Operators

An operator is a sign or symbol that specifies the type of calculation to perform within
an expression An operator performs on separate data items and returns a result. The
data items are called operands or arguments. Operators are mentioned by special
characters or by keywords.

Arithmetic operators: Arithmetic operators can perform arithmetic operation on


numeric operands involved. Arithmetic operators are addition(+), subtraction(-),
multiplication(*) and division(/). The + and - operators can also be used in date
arithmetic.

Malik mehboob
Fundamentals of DBMS 10

Comparison / Relational operator: A comparison (or relational) operator is a


mathematical symbol which is used to compare between two values. The result of a
comparison can be TRUE, FALSE, or UNKNOWN.

Logical Operator: There are three Logical Operators namely, AND, OR, and NOT.
These operators compare two conditions at a time to determine whether a row can be
selected for the output. When retrieving data using a SELECT statement, we can use
logical operators in the WHERE clause, which allows us to combine more than one
condition.e,g AND, OR etc.

Functions

Functions are a very powerful feature of sql. They are used to perform calculations on
data & modify individual data items. Functions take arguments & always return a
value. There are two types of SQL functions:

 Single row functions


 Multiple row functions

Single Row functions: These functions operate on single rows and return one result
per row.

Multiple Row functions: Functions can manipulate groups of rows to give one result
per group of row. These functions are also known as group functions.

Character functions

Character functions accept characters as input and can return both character and
number value.

Case manipulation functions: These functions convert case for character strings.
These include Lower, Upper, Initcap.

Lower: Converts mixed case or Upper case character strings to Lower case.

Syntax : lower(‘str’) e,g. LOWER(APPle) output= apple.

Upper: Converts mixed case or lower case character strings to upper case.

Syntax : UPPER(‘str’). E,g. UPPER(apple). Output= APPLE.

Malik mehboob
Fundamentals of DBMS 11

INITCAP: Converts the first letter of each word to uppercase & remaining letters to
lowercase. Syntax : Initcap(‘str’)

Example; INITCAP(aPPLe). Output= Apple.

Character manipulation functions: These functions manipulate character strings.


These include:

CONCAT: concat function joins values together. It concatenates the first character
value to the second character value.

Syntax : concat(‘str1′,’str2′)

SUBSTR: Returns specified characters from character value starting at character


position m, n characters long. It is used to get a substring from string.
Syntax : substr(‘str’,m ,n). e,g. SUBSTR(‘apple’,2,3). Output= ppl.
LENGTH: It is used to calculate the length of the string. It returns the number of
characters in the expression.
Syntax : length(‘str’). E.g. LENGTH(apple). Output= 5
INSTR: It is used to find the numeric position of the named character.
Syntax : Instr(‘str1′,’str2′). E.g. INSTR(‘apple’,’L’). output=4
LPAD: LPAD (left pad) is SQL function used to add padding characters to the left
side of a string up to a given length. The default padding character is a space. If the
string's length is greater than the required length, it will be trimmed (excess characters
will be removed).
Syntax:LPAD (text-exp , length [, pad-exp])
E,g. LPAD((‘apple’,10,*). Output= *****apple.
RPAD: RPAD (right pad) is SQL function used to add padding characters to the right
side of a string up to a given length. The default padding character is a space. If the
string's length is greater than the required length, it will be trimmed (excess characters
will be removed). Syntax:

RPAD (text-exp , length [, pad-exp]);

e.g. RPAD(((‘apple’,10,*). Output= apple*****.

Malik mehboob
Fundamentals of DBMS 12

TRIM: The TRIM function in SQL is used to remove specified heading or trailing
characters or both from a string. The most common pattern being removed is white
spaces.

LTRIM function is used to remove the white spaces on the left side of the string.

RTRIM function is used to remove white spaces on the right side of the string.

Number functions/Numeric Functions

SQL numeric functions are used primarily for numeric manipulation and/or
mathematical calculations. Numeric functions accept numeric input and return
numeric values.

ABS( ): Returns the absolute positive value of an expression. Or returns the absolute
value of numeric expression.
Syntax: ABS(expression)
E.g. ABS(-7). output= 7

CEIL(number):Returns the smallest integer greater than, or equal to, the specified
numeric expression.
Syntax:CEIL(expression)
e.g. CEIL(25.75) .output=26. CEIL(-25.75). output= -25
FLOOR(number):Returns the largest integer less than, or equal to, the specified
numeric expression.
Syntax: FLOOR(expression)
e.g. FLOOR(25.7). output= 25. FLOOR(-25.75). output= -26

Malik mehboob
Fundamentals of DBMS 13

MOD(number, divisor):Returns the remainder of the division from 2 integer values.


Syntax: MOD(dividend, divisor). E.g. MOD(8,2). Output=0. MOD(9,2). Output= 1.
POWER(number, power):Returns the exponential value for the numeric expression.
Syntax: POWER(number, power). E.g. POWER(4,2). Output= 16.
ROUND(number, precision):Returns the numeric value rounded off to the next
value specified.
Syntax: ROUND(number, number of places)
Example:
SELECT ROUND(235.415, 2). Output= 235.42
SQRT(number):Returns the square root value of the expression.
Syntax: SQRT(number)
Example:
SELECT SQRT(4). Output= 2.
TRUNC(number, precision) :Returns a numeric value that truncate to the specific
places
Syntax: TRUNCATE(number,places)
Example: TRUNCATE(1.3456, 2). Output: 1.34
EXP( ):Returns the base of the natural logarithm (e) raised to the power of passed
numeric expression.

LEN( ): The LEN() function returns the length of the value.

Syntax: LEN( value)

Date functions

Date functions operate on values of the DATE data type.

MONTHS_BETWEEN function: The MONTHS_BETWEEN function calculates


the number of months between two dates. The return value is positive when the first
date is later than the second date and negative when the first date is earlier than the
second date.

Syntax: MONTHS_BETWEEN(date1,date2)

Malik mehboob
Fundamentals of DBMS 14

ADD_MONTHS: Adds n number of calendar months to date. The value of n must be


an integer and can be negative. Syntax:ADD_MONTHS(date,n)
e.g. ADD_months(’05-jan-19’,7) . output= 08 –aug-19

NEXT_DAY: Finds the date of the next specified day of the week. Syntax:

NEXT_DAY(date,’char’)

LAST_DAY: Finds the date of the last day of the month that contains date. Syntax:

LAST_DAY(date)

Conversion Functions

Conversion functions convert a value from one datatype to another. Generally, the
form of the function names follows the convention datatype TO datatype. The first
datatype is the input datatype. The second datatype is the output datatype. The SQL
conversion functions are:

TO_DATE: Converts a character string representing a date to a date value according


to the fmt that is specified. If fmt is omitted, the format is DD-MON-YY.

TO_NUMBER: Converts a character string containing digits to a number in the


format specified by the optional format model fmt.

TO_CHAR:Converts a number or date value to a VARCHAR2 character string with


format model fmt.
SQL GROUP Functions
Group functions are built-in SQL functions that operate on groups of rows and return
one value for the entire group. These functions are: COUNT, MAX, MIN, AVG,
SUM, DISTINCT
SQL COUNT ( ): This function returns the number of rows in the table that satisfies
the condition specified in the WHERE condition. If the WHERE condition is not
specified, then the query returns the total number of rows in the table.

SQL MAX( ): This function is used to get the maximum value from a column.
SQL MIN( ): This function is used to get the minimum value from a column.
SQL AVG( ): This function is used to get the average value of a numeric column.
SQL SUM( ): This function is used to get the sum of a numeric column.

Malik mehboob
Fundamentals of DBMS 15

Backend of a database: A back-end database is a database that is accessed by users


indirectly through an external application rather than by application programming
stored within the database itself or by low level manipulation of the data (e.g.
through SQL commands).A back-end database stores data but does not include end-
user application elements such as stored queries, forms, macros or reports. The term
back-end database is most widely used among developers using small database
programming systems which can contain the end-user application programming
within the database as a single item.
Frontend of a database: The front end is an interface between the user and the back
end. The front and back ends may be distributed amongst one or more systems.
The front is an abstraction, simplifying the underlying component by providing
a user-friendly interface.

Oracle: An Oracle database is a collection of data treated as a unit. The purpose of a


database is to store and retrieve related information. A database server is the key to
solving the problems of information management. In general, a server reliably
manages a large amount of data in a multiuser environment so that many users can
concurrently access the same data. All this is accomplished while delivering high
performance. A database server also prevents unauthorized access and provides
efficient solutions for failure recovery. Oracle Database is the first database designed
for enterprise grid computing, the most flexible and cost effective way to manage
information and Application.

SQL: Sql was initially developed at IBM by Donald D Chamberlin and Raymond F
Boyce in the early 1970’s. This version was initially called SEQUEL (Structured
English Query Language) but later it was changed to SQL because it was trademark of
UK based Aircraft Company.
SQL is a special purpose programming language designed for managing data held in a
relational database management system (RDBMS). SQL is a standard interactive and
programming language for getting information from and updating a database. SQL
consists of Data Definition Language, Data Manipulation Language & Data Control
Language. The scope of SQL includes data insert, Update, Delete, Schema Creation &
modification & data access control.

Advantages:

1 SQL queries can be used to retrieve large amounts of records from database quickly
and efficiently.

Malik mehboob
Fundamentals of DBMS 16

2 SQL databases use long established standard which is being adopted by ANSI &
ISO.

3 Using standard SQL it is easier to manage database systems without having to write
substantial amount of code.

Disadvantages :

Interfacing an SQL database is more complex than adding a few lines of code

2 More features implemented in proprietary way.

Characteristics of SQL:

1 SQL is an ANSI and ISO standard computer language for creating and manipulating
databases.

2. SQL allows the user to create, update, delete and retrieve data from database.

3. SQL is very simple and easy to learn.

4 .SQL works with database programs like DB2, Oracle, MS Access etc.

SQL Data types

The data type of a column defines what type of value the column can hold. Each
column in a database table is required to have a name and a data type. The different
types of data types are :

Varchar2: this data type is used to store variable length strings. The maximum length
of a VARCHAR2 data type is 4000 bytes. The string that we insert into the column
will be stored as they are provided. No spaces will be added to the string.

CHAR: CHAR is a fixed length string data type. This means that string values will be
padded or have space characters added to them. The maximum length of CHAR data
type is 2000 bytes.

NUMBER: Numeric data type is used to store numeric values that can be positive or
negative. Syntax: NUMBER(precision, Scale).
Malik mehboob
Fundamentals of DBMS 17

Here precision is the number of digits in a number and scale is the number of digits to
the right of the decimal point in a number.

LONG: Character data type upto a length of 2GB. Only 1 LONG column is allowed
per table.

DATE: Date data type is used for storing date data and time. The default format for a
date is DD:MM:YY.

Transaction

Collection of operations that form a single logical unit of work is called a transaction.
Transaction accesses data using two operations READ and WRITE.

Properties of Transaction

Transaction have four basic properties which are called ACID properties.

A-----------Atomicity
C-----------Consistency
I------------Isolation
D-----------Durability

Atomicity: It means that transaction is either performed completely or not performed


at all.

Consistency: The consistency property of a transaction implies that if database was in


a consistent state before the initiation of transaction, then at the end of transaction the
database will also be in a consistent state.

Isolation: Isolation property of a transaction indicates that the steps or operation


performed by a transaction should be isolated from other transactions.

Durability: The changes applied to the database by a committed transaction must


persist in the database. These changes must not be lost because of any failure.

Malik mehboob

You might also like