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

Unit - 1

Uploaded by

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

Unit - 1

Uploaded by

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

Unit - I

OVERVIEW OF DATABASE MANAGEMENT SYSTEMS

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.

Data: Data is raw fact or figures or entity. Information:


The processed data is called information.Database: A

database is a collection of related data.

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:

Aspect Data Information Knowledge


Definition Raw, unprocessed facts Processed and organized data Processed information with deeper understanding
and context
Form Numbers, symbols, text, Structured and contextualized data Synthesized insights, experience, and
etc. understanding
Meaning Lacks inherent meaning Provides context and relevance Involves understanding and interpretation
Context No context or Contextualizes data Applies insights to various contexts
interpretation
Use Building block for Used for decision-making, analysis, Applied to solve problems, make decisions
information communication
Example 5, 10, 15, 20 Temperature trend over time Weather pattern prediction based on temperature
trends

Database Management System:


1. A Database Management System (DBMS) is a collection of program thatenables
user to create, maintain and manipulate a database.
2. The DBMS is hence a general purpose software system that facilitates theprocess
of defining, constructing and manipulating database for various applications.
3. A Database Management System (DBMS) is a software system that is designed
to manage and organize data in a structured manner. It allows users to create,
modify, and query a database, as well as manage the security and access
controls for that database. DBMS provides an environment to store and retrieve
data in convenient and efficient manner.
Characteristics of DBMS
• To incorporate the requirements of the organization, system should be designedfor

easy maintenance.
• Information systems should allow interactive access to data to obtain new

information without writing fresh programs.


• System should be designed to co-relate different data to meet new

requirements.
• An independent central repository, which gives information and meaning of

available data is required.


• Integrated database will help in understanding the inter-relationships betweendata

stored in different applications.


• The stored data should be made available for access by different users

simultaneously.
• Automatic recovery feature has to be provided to overcome the problems with

processing system failure.

Advantages of a DBMS

Using a DBMS to manage data has many advantages:


Data independence: Application programs should be as independent as possiblefrom
details of data representation and storage. The DBMS can provide an abstract view of
the data to insulate application code from such details.
Efficient data access: A DBMS utilizes a variety of sophisticated techniques to store
and retrieve data efficiently. This feature is especially important if the data is stored
on external storage devices.
Data integrity and security: If data is always accessed through the DBMS, the DBMS
can enforce integrity constraints on the data. For example, before insertingsalary
information for an employee, the DBMS can check that the department budget is not
exceeded. Also, the DBMS can enforce access controls that govern what data is visible
to different classes of users.
Data administration: When several users share the data, centralizing the
administration of data can offer significant improvements. Experienced professionals
who understand the nature of the data being managed, and how different groups of
users use it, can be responsible for organizing the data representation to minimize
redundancy and for fine-tuning the storage of the datato make retrieval efficient.
Concurrent access and crash recovery: A DBMS schedules concurrent accessesto the
data in such a manner that users can think of the data as being
accessed by only one user at a time. Further, the DBMS protects users from theeffects
of system failures.
Reduced application development time: Clearly, the DBMS supports many important
functions that are common to many applications accessing data stored in the DBMS.
This, in conjunction with the high-level interface to the data, facilitates quick
development of applications. Such applications are also likely to be more robust than
applications developed from scratch because many important tasks are handled by the
DBMS instead of being implemented by the application.
Functions of DBMS
• Data Definition: The DBMS provides functions to define the structure of the data in

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,

modified or deleted. These functions which perform these operations arepart of


DBMS. These functions can handle plashud and unplashud data manipulation needs.
Plashud queries are those which form part of the application. Unplashud queries are
ad-hoc queries which performed on a need basis.
• Data Security & Integrity: The DBMS contains modules which handle the

security and integrity of data in the application.


• Data Recovery and Concurrency: Recovery of the data after system failure and

concurrent access of records by multiple users is also handled by DBMS.


• Data Dictionary Maintenance: Maintaining the data dictionary which contains the

data definition of the application is also one of the functions of DBMS.


• Performance: Optimizing the performance of the queries is one of the important

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:

Basis DBMS Approach File System Approach

DBMS is a collection of The file system is a collection of


data. In DBMS, the user is data. In this system, the user has
Meaning
not required to write the to write the procedures for
procedures. managing the database.
Due to the centralized Data is distributed in many files,
Sharing of data approach, data sharing is and it may be of different formats,
easy. so it isn't easy to share data.
DBMS gives an abstract The file system provides the detail
Data Abstraction view of data that hides the of the data representation and
details. storage of data.
DBMS provides a good It isn't easy to protect a file under
Security and Protection
protection mechanism. the file system.
The file system doesn't have a
DBMS provides a crash
crash mechanism, i.e., if the
recovery mechanism, i.e.,
Recovery Mechanism system crashes while entering
DBMS protects the user
some data, then the content of the
from system failure.
file will be lost.
DBMS contains a wide
variety of sophisticated The file system can't efficiently
Manipulation Techniques
techniques to store and store and retrieve the data.
retrieve the data.
In the File system, concurrent
DBMS takes care of access has many problems like
Concurrency Problems Concurrent access of data redirecting the file while deleting
using some form of locking. some information or updating
some information.
Database approach used in File system approach used in large
Where to use
large systems which systems which interrelate many
interrelate many files. files.
The database system is The file system approach is
Cost
expensive to design. cheaper to design.
Due to the centralization of In this, the files and application
the database, the problems programs are created by different
Data Redundancy and
of data redundancy and programmers so that there exists a
Inconsistency
inconsistency are lot of duplication of data which
controlled. may lead to inconsistency.
The database structure is The file system approach has a
Structure
complex to design. simple structure.
In this system, Data
Independence exists, and it
can be of two types.
In the File system approach, there
Data Independence o Logical Data exists no Data Independence.
Independence
o Physical Data
Independence

Integrity Constraints are Integrity Constraints are difficult to


Integrity Constraints
easy to apply. implement in file system.
In the database approach,
3 types of data models
exist:

o Hierarchal data In the file system approach, there


Data Models models is no concept of data models
o Network data exists.
models
o Relational data
models

Changes are often a


necessity to the content of
The flexibility of the system is less
the data stored in any
Flexibility as compared to the DBMS
system, and these changes
approach.
are more easily with a
database approach.
Oracle, SQL Server, Sybase
Examples Cobol, C++ etc.
etc.

Role of Database Administrator.


Typically there are three types of users for a DBMS:

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

The role of DBA is very important and is defined by the


following functions.

• 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

users to understand the data in the system and its use.

• Defining Security & Integrity checks: The DBA finds about the access

restrictions to be defined and defines security checks accordingly. Data


Integrity checks are defined by the DBA.

• Defining Backup/Recovery Procedures: The DBA also defines proceduresfor

backup and recovery. Defining backup procedure includes specifying what


data is to be backed up, the periodicity of taking backups and also

the medium and storage place to backup data.

• Monitoring performance: The DBA has to continuously monitor the

performance of the queries and take the measures to optimize all the
queries in the application.

Database Administrator is solely responsible for giving permission to access data


available in the database. It also makes sure who has the right to change the content.
DBA is held responsible and accountable for logical, physical design, external model
design, and integrity and security control.
Database Manager

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.

Types of Data Models


1. High Level- Conceptual data model.

2. Low Level – Physical data model.

3. Relational or Representational

4. Object-oriented Data Models:

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.

The most common data models are


1. Relational Model
The Relational Model uses a collection of tables both data and the relationship among
those data. Each table has multiple columns and each column has a uniquename.
Relational database comprising of two tables.

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

attributes used to retrieve data.


3. Representation of different types of relationship is possible with this model.
2. Network Model
The data in the network model are represented by collection of records and
relationships among data are represented by links, which can be viewed as
pointers.

The records in the database are organized as collection of arbitrary groups.

Advantages:
1. Representation of relationship between entities is implemented using pointers

which allows the representation of arbitrary relationship


2. Unlike the hierarchical model it is easy.
3. Data manipulation can be done easily with this model.

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

method of implementation of one–to-many relationships.


2. Proper ordering of the tree results in easier and faster retrieval of records.
3. Allows the use of virtual records. This result in a stable database especiallywhen

modification of the data base is made.

Data Instances and Schemas


Database Instances
Database change over time as information is inserted and deleted. The collectionof
information stored in the database at a particular moment is called an instance of the
database.
Database Schema
The overall design of the database is called the database schema. A schema is a
collection of named objects. Schemas provide a logical classification of objectsin the
database. A schema can contain tables, views, triggers, functions, packages, and
other objects.
DBMS Architecture
A commonly used view of data approach is the three-level architecture suggestedby
the ANSI/SPARC (American National Standards Institute/Standards Planning and
Requirements Committee). ANSI/SPARC proposed an architectural frameworkfor
databases.
The three levels of the architecture are three different views of the data:

External Schema - individual user view


Conceptual Schema- Logical or community user viewPhysical
Schema -Internal or storage view

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

2. Logical data independence

There are two types of data independence:

1. Logical 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.

2. Physical Data Independence

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

Database languages and interfaces


A database system provides a data definition language to specify the databaseschema
and a data manipulation language to express database queries and updates.
In practice, the data definition and data manipulation languages are not two separate
languages; instead they simply form parts of a single database language,such as the
widely used SQL language.

The DBMS languages are pictorially represented as follows −


Data Definition Language
Data Definition Language (DDL) statements are used to define the databasestructure
or schema.
Following are the some commands that come under DDL:

a. CREATE It is used to create a new table in the database.

Syntax:

(CREATE TABLE TABLE_NAME (COLUMN_NAMES DATATYPES [ ...]);


In above statement, TABLE_NAME is the name of the table, COLUMN_NAMES is the name of
the columns and DATATYPES is used to define the type of data.

Example:

. CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Email VARCHAR2(100), DOB DATE);

b. DROP: It is used to delete both the structure and record stored in the table.

Syntax: To DROP a table permanently from memory

. DROP TABLE table_name [cascade constraint];


The cascade constraint is an optional parameter which is used for tables which have foreign
keys that reference the table being dropped. If cascade constraint is not specified and used
attempt to drop a table that has records in a child table, then an error will occur. So by using
cascade constraints, all child table foreign keys are dropped.

Example

. DROP TABLE EMPLOYEE;

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.

Adding new columns in Table:

With the use of ALTER table command we can add new columns existing table.

Syntax: To add a new column in the table

. ALTER TABLE table_name ADD column_name column-definition;


In the above syntax, where table_name corresponds to the name of the table, column-
definition corresponds to the valid specifications for a column name and data type.

EXAMPLE:

. ALTER TABLE STU_DETAILS ADD (ADHAR_NUM VARCHAR2 (15));


.
Syntax: To ADD a multiple column from a table.

ALTER TABLE table_name ADD column_name1, column_name2;


Example:

. ALTER TABLE STU_DETAILS ADD ADHAR_NUM, NAME;


Adding constraints in a Table:

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.

Syntax: To ADD a constraint from a table.

. ALTER TABLE table_name ADD (column_name column-


definition CONSTRAINT constraint_name);
Example:

. ALTER TABLE STU_DETAILS ADD (CONSTRAINT PK_STU_DETAILS PRIMARY KEY (STU_ID);

Following points should be kept in mind while adding new columns/relationships to existing
tables.

o No need for parentheses if you add only one column or constraints.


o You can add a column at any time if NULL is not specified. You can add a new column
with NOT NULL if the table is empty.

Modifying Column using ALTER:

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:

. ALTER TABLE table_name MODIFY (column definitions....);


Example:

. ALTER TABLE STU_DETAILS MODIFY (ADHAR_NUM VARCHAR2 (20));


SQL does not allow column widths to be reduced even if all column values are of valid length.
So the values should be set to NULL to reduce the width of the columns. It is also not possible
to reduce the width of the ADHAR_NUM column from 18 to 12 even if all values in the
ADHAR_NUM column are less than 12 characters, unless all al values in the name column are
null. You can modify the column form NULL to NOTNULL constraints if there is no record in
that column in the table.
Example:

. ALTER TABLE STU_DETAILS MODIFY (ADHAR_NUM VARCHAR2 (20) NOT NULL);


Drop column and constraints using ALTER

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.

Syntax: To drop a column from a table.

. ALTER TABLE table_name DROP COLUMN column_name;


Example:

. ALTER TABLE STU_DETAILS DROP COLUMN ADHAR_NUM;


.
Syntax: To drop a multiple column from a table.

. ALTER TABLE table_name DROP COLUMN column_name1, column_name2;


Example:

. ALTER TABLE STU_DETAILS DROP COLUMN ADHAR_NUM, NAME;


Syntax: To drop a constraint from a table.

. ALTER TABLE table_name DROP CONSTRAINT constraint_name;


Example:

. ALTER TABLE STU_DETAILS DROP CONSTRAINT FK_STU_DETAILS;

Following points should be kept in mind while deleting columns/associations:

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:

. ALTER TABLE STU_DETAILS DROP PRIMARY KEY CASCADE;


Example: To disable constraint

. ALTER TABLE STU_DETAILS DISABLE CONSTRAINT FK_STU_DETAILS;


Example: To Enable constraint

. ALTER TABLE STU_DETAILS ENABLE CONSTRAINT FK_STU_DETAILS;

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:

. ALTER TABLE STU_DETAILS SET UNUSED COLUMN ADHAR_NUM;

RENAMING TABLE

SQL provides the facility to change the name of the table by using a ALTER TABLE statement.

Syntax:

. ALTER TABLE <OLD_TABLENAME> Rename to <NEW_TABLENAME>;


Example:

. ALTER TABLE STU_NAME Rename to STUDENT_NAME;


d. TRUNCATE: It is used to delete all the rows from the table and free the space containing the
table.

Syntax:

. TRUNCATE TABLE table_name;


Example:

. TRUNCATE TABLE EMPLOYEE;


e. Rename: It is used to rename the table.

Syntax:

. Rename <OLD_TABLENAME> to <NEW_TABLENAME>;


In the above syntax, Rename is a command, <OLD_TABLENAME> is the name of the table and
<NEW_TABLENAME> is the name that you have changed.
Example:

. Rename STU_NAME to STUDENT_NAME;

2. Data Manipulation Language

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.

Following are the some commands that come under DML:

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.

Syntax: To add row in a table

. INSERT INTO TABLE_NAME


. (col1, col2, col3,.... col N)
. VALUES (value1, value2, value3, .... valueN);
Or

. INSERT INTO TABLE_NAME


. VALUES (value1, value2, value3, .... valueN);
In the above syntax, TABLE_NAME is the name of the table in which the data will be inserted.
The (col1, col2, col3, col N) are optional and name of the columns in which values will be
inserted. The value1 corresponds to the value of be inserted in col1 and similarly value2
corresponds to the value of be inserted in col2 and so on.
For example:

. INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS");


Syntax: To add multiple rows in a table

. INSERT INTO TABLE_NAME


. (col1, col2, col3,.... col N)
. VALUES (value1, value2, value3, .... valueN), (value1, value2, value3, .... valueN);
For example:

. 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.

Syntax: To update record in a table

. UPDATE table_name SET [column_name1= value1,...column_nameN = valueN] [WHERE


CONDITION]
In the above syntax, table_name is the name of the table, the column_name is the name of
column in the table to be modified, and value1 corresponds to the valid SQL values. The
"WHERE" is a condition that restricts the rows updated for which the specified condition is
true. If condition is not specified is not defined then SQL updates all the rows in the table. It
contains comparison and logical operators etc.

The following the list of points should be remembered while executing the UPDATE
statement.

o It references only one table.


o In the SET clause atleast one column must be assigned an expression for the update
statement,
o In the where clause you could also give multiple conditions for update statement.
For example:

. 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.

Syntax: To Delete a record from table


. DELETE FROM table_name [WHERE condition];
In the above syntax, condition is used in the where clause to filter the records that are actually
being removed. You can remove zero or more rows from a table. If you do not use where
condition then DELETE statement will remove all the rows from the table. You can also use one
or multiple conditions in WHERE clause.

For example:

. DELETE FROM javatpoint


. WHERE Author="Sonoo";
d. SELECT: This is the same as the projection operation of relational algebra. It is used to select
the attribute based on the condition described by WHERE clause.

Syntax: It is used for retrieve the records from table

. 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.

Why Data Dictionary is Essential?


There is less information and details provided by data models. So, a data dictionary is
essential and needed to have proper knowledge and usage of contents. Data Dictionary
provides all information about names that are used in system models. Data Dictionary also
provides information about entities, relationships, and attributes that are present in the
system model. As a part of the structured analysis and design tool, the implementation of a
data dictionary is done.

Following type of information is maintained by data dictionary -


a) Description of the schema of the database.
b) Detailed information about the physical database design.
c) Description of database users, their roles and their access rights.
d) Description of database transactions.
e) The description of the relationship between database transactions and data items
referenced by them.
f) Information about the usage statistics. That means, how many times the queries are raised
to the database, how many transactions are made by the DBMS.

• 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.

Passive data dictionary


• Passive data dictionary is used only for documentation purpose.
• Passive dictionary is a self-contained application and set of files used for documenting the
data processing environment.
• The process of maintaining or modification of the database is manual.
• It is managed by the users of the database systems.

Data Control Language

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.

1. It is a part of the structured query language (SQL).

2. It helps in controlling access to information stored in a database. It complements


the data manipulation language (DML) and the data definition language (DDL).

3. It is the simplest among three commands.

4. It provides the administrators, to remove and set database permissions to desired


users as needed.

5. These commands are employed to grant, remove and deny permissions to users for
retrieving and manipulating a database.

Transactional Control Language

Transaction Control language is a language that manages transactions within the


database.

It is used to execute the changes made by the DML statements.

TCL Commands

Transaction Control Language (TCL) Commands are:

Commit − It is used to save the transactions in the database.

Rollback − It is used to restore the database to that state which was last committed.

Begin − It is used at the beginning of a transaction.

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

Sno. Rollback Commit Savepoint

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.

o String Data types


o Numeric Data types
o Date and time Data types
Data Types in MySQL, SQL Server and Oracle Databases
MySQL Data Types
A list of data types used in MySQL database. This is based on MySQL 8.0.

MySQL String Data Types

It is used to specify a fixed length string


that can contain numbers, letters, and
CHAR(Size)
special characters. Its size can be 0 to 255
characters. Default is 1.
It is used to specify a variable length string
that can contain numbers, letters, and
VARCHAR(Size)
special characters. Its size can be from 0
to 65535 characters.
It is equal to CHAR() but stores binary byte
BINARY(Size) strings. Its size parameter specifies the
column length in the bytes. Default is 1.
It is equal to VARCHAR() but stores binary
VARBINARY(Size) byte strings. Its size parameter specifies
the maximum column length in bytes.
It holds a string that can contain a
TEXT(Size)
maximum length of 255 characters.
It holds a string with a maximum length of
TINYTEXT
255 characters.
It holds a string with a maximum length of
MEDIUMTEXT
16,777,215.
It holds a string with a maximum length of
LONGTEXT
4,294,967,295 characters.
It is used when a string object having only
one value, chosen from a list of possible
ENUM(val1, val2, val3,...) values. It contains 65535 values in an
ENUM list. If you insert a value that is not
in the list, a blank value will be inserted.
It is used to specify a string that can have
0 or more values, chosen from a list of
SET( val1,val2,val3,....)
possible values. You can list up to 64
values at one time in a SET list.
It is used for BLOBs (Binary Large Objects).
BLOB(size)
It can hold up to 65,535 bytes.
MySQL Numeric Data Types

It is used for a bit-value type. The number


BIT(Size) of bits per value is specified in size. Its size
can be 1 to 64. The default value is 1.
It is used for the integer value. Its signed
range varies from -2147483648 to
2147483647 and unsigned range varies
INT(size)
from 0 to 4294967295. The size
parameter specifies the max display width
that is 255.
INTEGER(size) It is equal to INT(size).
It is used to specify a floating point
number. Its size parameter specifies the
FLOAT(size, d) total number of digits. The number of
digits after the decimal point is specified
by d parameter.
FLOAT(p) It is used to specify a floating point
number. MySQL used p parameter to
determine whether to use FLOAT or
DOUBLE. If p is between 0 to24, the data
type becomes FLOAT (). If p is from 25 to
53, the data type becomes DOUBLE().
It is a normal size floating point number.
Its size parameter specifies the total
DOUBLE(size, d) number of digits. The number of digits
after the decimal is specified by d
parameter.
It is used to specify a fixed point number.
Its size parameter specifies the total
number of digits. The number of digits
after the decimal parameter is specified
DECIMAL(size, d)
by d parameter. The maximum value for
the size is 65, and the default value is 10.
The maximum value for d is 30, and the
default value is 0.
DEC(size, d) It is equal to DECIMAL(size, d).
It is used to specify Boolean values true
BOOL and false. Zero is considered as false, and
nonzero values are considered as true.
MySQL Date and Time Data Types

It is used to specify date format YYYY-


DATE MM-DD. Its supported range is from
'1000-01-01' to '9999-12-31'.

You might also like