618164281-database-management-system-new-notes
618164281-database-management-system-new-notes
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.
Applications of DBMS
Telecommunication: For keeping records of calls made, generating monthly bills etc
Finance: For storing information about holidays, sales and purchases of financial
instruments.
Advantages of DBMS
Malik mehboob
Fundamentals of DBMS 2
3. Sharing of data: the users can share the data among themselves.
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.
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:
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
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.
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.
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
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.
User
Malik mehboob
Fundamentals of DBMS 6
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
datatype(size),...column_name N datatype(size));
Syntax for add column: ALTER TABLE tablename ADD (columnname datatype
(size));
TRUNCATE: Truncate table command deletes the data inside a table but not the
table itself. Columns remain intact.
Data Manipulation Language (DML) - These SQL commands are used for storing,
retrieving, modifying, and deleting data.
Malik mehboob
Fundamentals of DBMS 8
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:
Transaction Control Language (TCL) - These SQL commands are used for
managing changes affecting the data. These commands are COMMIT, ROLLBACK,
and SAVEPOINT.
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:
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.
Malik mehboob
Fundamentals of DBMS 10
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: 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.
Upper: Converts mixed case or lower case character strings to upper case.
Malik mehboob
Fundamentals of DBMS 11
INITCAP: Converts the first letter of each word to uppercase & remaining letters to
lowercase. Syntax : Initcap(‘str’)
CONCAT: concat function joins values together. It concatenates the first character
value to the second character value.
Syntax : concat(‘str1′,’str2′)
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.
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
Date functions
Syntax: MONTHS_BETWEEN(date1,date2)
Malik mehboob
Fundamentals of DBMS 14
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:
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
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
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.
4 .SQL works with database programs like DB2, Oracle, MS Access etc.
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
Malik mehboob