Unit - 1
Unit - 1
Unit-I Introduction
Introduction:
Database is a collection of related data. Database management system is software
designed to assist the maintenance and utilization of large scale collection of data.
DBMScame into existence in 1960 by Charles. Integrated data store which is also
called as the first general purpose DBMS. Again in 1960 IBM brought IMS-Information
management system. In 1970 Edgor Codd at IBM came with new database called
RDBMS. In 1980 then came SQL Architecture- Structure Query Language. In 1980 to
1990 there were advances in DBMS e.g. DB2, ORACLE.
For example, a university database might contain information about the following:
Entities such as students, faculty and courses.
Relationships between entities, such as students' enrollment in courses,
faculty teaching courses.
The Differences between Data, Information, and Knowledge:
easy maintenance.
• Information systems should allow interactive access to data to obtain new
requirements.
• An independent central repository, which gives information and meaning of
simultaneously.
• Automatic recovery feature has to be provided to overcome the problems with
Advantages of a DBMS
the application. These include defining and modifying the record structure, the type
and size of fields and the various constraints to be satisfied by the data in each field.
• Data Manipulation: Once the data structure is defined, data needs to be inserted,
functions of DBMS.
File System
The file system is basically a way of arranging the files in a storage medium like a hard disk.
The file system organizes the files and helps in the retrieval of files when they are required.
File systems consist of different files which are grouped into directories. The directories
further contain other folders and files. The file system performs basic operations like
management, file naming, giving access rules, etc.
Difference between File System and DBMS
here are the following differences between DBMS and File systems:
1. The END User who uses the application. Ultimately he is the one who actuallyputs
the data into the system into use in business. This user need not know anything
about the organization of data in the physical level.
2. The Application Programmer who develops the application programs. He/She has
more knowledge about the data and its structure. He/she can manipulate the data
using his/her programs. He/she also need not have access and knowledge ofthe
complete data in the system.
3. The Data base Administrator (DBA) who is like the super-user of the system
• Defining the schema: The DBA defines the schema which contains the
structure of the data in the application. The DBA determines what data
needs to be present in the system and how this data has to be presentedand
organized.
• Liaising with users: The DBA needs to interact continuously with the
• Defining Security & Integrity checks: The DBA finds about the access
performance of the queries and take the measures to optimize all the
queries in the application.
Database manager is a program module which provides the interface betweenthe low
level data stored in the database and the application programs and queries submitted
to the system:
– The database manager would translate DML statement into low levelfile
system commands for storing, retrieving, and updating data in the
database.
– Integrity enforcement. Database manager enforces integrity by checking
consistency constraints like the bank balance of customer must be maintained to a
minimum of Rs. 1000, etc.
– Security enforcement. Unauthorized users are prohibited to view the information
stored in the data base.
– Backup and recovery. Backup and recovery of database is necessary to ensurethat
the database must remain consistent despite the fact of failures.
Database Users
Database users are the people who need information from the database tocarry
out their business responsibility. The database users can be broadly classified into
two categories like application programmers and end users.
Sophisticated End Users :
Sophisticated end users interact with the system without writing programs. They
form requests by writing queries in a database query language. Theseare
submitted to query processor. Analysts who submit queries to explore data in the
database fall in this category.
Specialized End Users :
Specialized end users write specialized database application that does not fitinto
data-processing frame work. Application involves knowledge base and expert
system, environment modeling system, etc.
Naive End Users :
Naive end user interact with the system by using permanent application programExample:
Query made by the student, namely number of books borrowed
in library database.
System Analysts :
System analysts determine the requirements of end user, and developspecification for
canned transaction that meets this requirement.
Canned Transaction :
Readymade programs through which naive end users interact with the databaseis
called canned transaction.
Database System Concepts and Architecture
Data Models, Schemas, and Instances
One fundamental characteristic of the database approach is that it provides somelevel
of data abstraction by hiding details of data storage that are irrelevant to database
users.
A data model is a collection of concepts that can be used to describe the
conceptual/logical structure of a database.
The structure of a database means that holds the data’s data types, relationships,and
constraints.
According to C.J. Date (one of the leading database experts), a data model is an
abstract, self-contained, logical definition of the objects, operators, and so forth, that
together constitute the abstract machine with which users interact. The objects allow us
to model the structure of data; the operators allow us to model its behavior.
3. Relational or Representational
5. Object-Relational Models:
1. High Level-conceptual data model: User level data model is the high level or
conceptual model. This provides concepts that are close to the way that many users
perceive data.
2 .Low level-Physical data model: provides concepts that describe the details ofhow
data is stored in the computer model. Low level data model is only for Computer
specialists not for end-user.
3. Representation data model: It is between High level & Low level data model Which
provides concepts that may be understood by end-user but that are not toofar
removed from the way data is organized by within the computer.
Advantages
1. The main advantage of this model is its ability to represent data in a simplified
format.
2. The process of manipulating record is simplified with the use of certain key
Advantages:
1. Representation of relationship between entities is implemented using pointers
3. Hierarchical Model
A hierarchical data model is a data model which the data is organized into a tree like
structure. The structure allows repeating information using parent/child relationships:
each parent can have many children but each child has one parent.All attributes of a
specific record are listed under an entity type.
Advantages:
1. The representation of records is done using an ordered tree, which is natural
The three level database architecture allows a clear separation of the information
meaning (conceptual view) from the external data representation and from the
physical data structure layout. A database system that is able to separate the three
different views of data is likely to be flexible and adaptable.
The External Schema is the view that the individual user of the database has. Thisview
is often a restricted view of the database and the same database may provide a
number of different views for different classes of users.
The Conceptual schema (sometimes called the logical schema) describes thestored
data in terms of the data model of the DBMS. In a relational DBMS, the conceptual
schema describes all relations that are stored in the database.
It hides physical storage details, concentrating upon describing entities, datatypes,
relationships, user operations, and constraints.
The physical schema specifies additional storage details. Essentially, the physicalschema
summarizes how the relations described in the conceptual schema are actually stored
on secondary storage devices such as disks and tapes.
It tells us what data is stored in the database and how.
Data Independence
Data independence can be defined as the capacity to change the schema at onelevel
without changing the schema at next higher level.
It also means the internal structure of database should be unaffected by changes to
physical aspects of storage. Because of data independence, the Database
administrator can change the database storage structures without affecting the users
view.
The different levels of data abstraction are:
1. Physical data independence
o Logical data independence refers characteristic of being able to change the conceptual
schema without having to change the external schema.
o Logical data independence is used to separate the external level from the conceptual
view.
o If we do any changes in the conceptual view of the data, then the user view of the data
would not be affected.
o Logical data independence occurs at the user interface level.
o Physical data independence can be defined as the capacity to change the internal
schema without having to change the conceptual schema.
o If we do any changes in the storage size of the database system server, then the
Conceptual structure of the database will not be affected.
o Physical data independence is used to separate conceptual levels from the internal
levels.
o Physical data independence occurs at the logical interface level.
Fig: Data Independence
Syntax:
Example:
b. DROP: It is used to delete both the structure and record stored in the table.
Example
c. ALTER: It is used to alter the structure of the database. This change could be either to
modify the characteristics of an existing attribute or probably to add a new attribute.
Following are the list of modifications that can be done using ALTER command.
o With the use of ALTER commands we can add or drop one or more columns form
existing tables.
o Increase or decrease the existing column width by changing the data type
o Make an existing mandatory column to optional.
o Enable or disable the integrity constraints in a table. We can also add, modify or delete
the integrity constraints from a table.
o We can also specify a default value for existing column in a table.
With the use of ALTER table command we can add new columns existing table.
EXAMPLE:
You can also add constraints to an existing table. For example: If you forget to add a primary
key constraint to a table during creation, you can add it using the ALTER TABLE statement.
Following points should be kept in mind while adding new columns/relationships to existing
tables.
With the use of ALTER table we can modify column and constraint in the existing table. These
statements can increase or decrease the column widths and changing a column from
mandatory to optional.
Syntax:
You cannot only modify columns but you can also drop them entirely if it is no longer required
in a table. Using drop statement in alter command we can also remove the constraints form
the table.
o You cannot drop columns in a table. If you want to drop a column from a table, the
deletion is permanent so you cannot undo the column if you accidentally drop the
wrong column.
o You cannot drop a column whose username is SYS.
o If you want to drop a primary key column unless you drop the foreign keys that belong
to it then use cascade keyword for this.
Example:
o Instead of dropping a column in a table, we can also make the column unused and drop
it later on. It makes the response time faster. After a column has been marked as
unused, the column and all its contents are no longer available and cannot be recovered
in the future. The unused columns will not be retrieved using Select statement
Example:
RENAMING TABLE
SQL provides the facility to change the name of the table by using a ALTER TABLE statement.
Syntax:
Syntax:
Syntax:
o DML commands are used to modify the database. It is responsible for all form of
changes in the database.
o The command of DML is not auto-committed that means it can't permanently save all
the changes in the database. They can be rollback.
a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a table.
To insert a new row into a table you must be your on schema or INSERT privilege on the table.
Following are the list of points should be considered while inserting the data into tables.
o SQL uses all the columns by default if you do not specify the column name while
inserting a row.
o The number of columns in the list of column name must match the number of values
that appear in parenthesis after the word "values".
o The data type for a column and its corresponding value must match.
. INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS"), ("Raman", "DBMS
"), ("Priya", "DBMS");
b. UPDATE: This command is used to update or modify the value of a column in the table.
The following the list of points should be remembered while executing the UPDATE
statement.
. UPDATE students
. SET User_Name = 'Sonoo'
. WHERE Student_Id = '3'
.
c. DELETE: It is used to remove one or more row from a table. To delete rows from the table, it
must be in your schema or you must have delete privilege.
For example:
. SELECT expressions
. FROM TABLES
. WHERE conditions;
For example:
. SELECT emp_name
. FROM employee
. WHERE age > 20;
Some examples:
o CREATE - to create objects in the database
o ALTER - alters the structure of the database
o DROP - delete objects from the database
o TRUNCATE - remove all records from a table, including all spaces allocatedfor
the records are removed
In addition, it updates a special set of tables called the data dictionary or data
directory. A data dictionary contains metadata—that is, data about data. The
schema of a table is an example of metadata. A database system consults the data
dictionarybefore reading or modifying actual data.
A Data Dictionary comprises two words i.e. Data which simply means information being
collected through some sources and Dictionary means where this information is available.
A Data Dictionary can be defined as a collection of information on all data elements or
contents of databases such as data types, and text descriptions of the system. It makes it
easier for users and analysts to use data as well as understand and have common knowledge
about inputs, outputs, components of a database, and intermediate calculations.
• For example - Consider a Student database, in which various fields are RollNo, FirstName,
LastName, and CourseID. The data dictionary for this database ban maintains the information
about this database. The data dictionary contains the dog column names, Data type of each
field and the description of each column of the database.
Active and Passive Data Dictionaries
Active data dictionary
• Active Data dictionary is managed automatically by the database management system.
• They are consistent with current structure.
• In the active data dictionary, when any modification or changes is executed by the DBMS,
then this dictionary it also gets modified by the DBMS automatically.
• Most of the active data dictionaries are derived from system catalog.
Data control language (DCL) is used to access the stored data. It is mainly used for
revoke and to grant the user the required access to a database. In the database, this
language does not have the feature of rollback.
5. These commands are employed to grant, remove and deny permissions to users for
retrieving and manipulating a database.
TCL Commands
Rollback − It is used to restore the database to that state which was last committed.
Savepoint − The changes done till savpoint will be unchanged and all the transactions
after savepoint will be rolled back.
Difference between Commit, rollback and savepoint of TCL commands
DML
commands
Rollback means the saves Savepoint helps to
database is restored modification save the
1.
to the last committed and it transaction
state permanently temporarily.
saves the
transaction.
Syntax- ROLLBACK
Syntax- Syntax- SAVEPOINT
2. [To
COMMIT; [savepoint_name;]
SAVEPOINT_NAME];
Example-
Example- ROLLBACK Example- SQL>
3. SAVEPOINT
Update5; COMMIT;
table_create;
SQL Data Types
Data types are used to represent the nature of the data that can be stored in the database
table. For example, in a particular column of a table, if we want to store a string type of data
then we will have to declare a string data type of this column.
Data types mainly classified into three categories for every database.