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

Database Concept

Uploaded by

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

Database Concept

Uploaded by

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

R E L AT I O N A L DATA B A S E

Storing and manipulating records


D ATA BAS E
 May be defined as a collection of
interrelated data stored together to serve
multiple application
 It is computer based record keeping system.

 It not only allows to store but also allows


us modification of data as per requirements.
DBMS
 A D B M S refers to Database Management System
 It is a software that is responsible for storing,

manipulating, maintaining and utilizing


database.
 A database along with the a D B M S is

referred to
as a database system.
 There are various D B M S software available in

the market like :-


 Oracle, M S S Q L Server, M y S Q L , Sybase,

PostgreSQL, SQLite
PURPOSE OF DBMS
R E L AT I O NA L DATA BAS E M O D E L
 In relational database model data is organized
into table (i.e. rows and columns).
 These tables are also known as relations.

 A row in a table represent relationship among a

set of values.
 A column represent the field/attributes related to

relation under which information will be stored.


 For example if we want to store details of

students then : Roll, Name, Class, Section, etc.


will be the column/attributes and the collection of
all the column information will become a
Row/Record
S A M P L E TA B L E S
EMPLOYEE
EMPNO ENAME GENDER DEPTNO S A L A RY COMM
1 AN KI TA F 10 20000 1200
2 SUJEET M 20 24000 1400
3 V I J AYA F 10 28000 2000
4 NI T I N M 30 18000 3000
5 VIKRAM M 30 22000 1700

DEPARTMEN
T DEPTNO DNAME L O C AT I O N
10 HR N E W YO R K
20 ACCOUNTS BRAZIL
30 SALES C A NA DA
40 IT I NDI A
C O M P O N E N T S O F A TA B L E
 Byte : group of 8 bits and is used to store a
character.
 Data Item : smallest unit of named data. It

represents the type of


information and often referred to
as a field or column information
 Record : collection of data items which
represents a complete unit of
information
 Table : collection of all Rows and
Columns.
Table
Fields

DEPTNO DNAME L O C AT I O N
10 HR N E W YO R K
20 ACCOUNTS BRAZIL
30 SALES C A NA DA
40 IT I NDI A

Data Items
Records
COMMON RDBMS
 Oracle, M S S Q L Server, M y SQ L, I B M DB2, I BM
Informix, SA P Sybase, Adaptive
Enterprise, SA P Sybase Server
PostgreSQL, SQLite, etc. IQ , Teradata,
 Out of these M y SQ L, PostgreSQL and SQLite are

Open source implementation.


COMMON RDBMS
 MySQL
⚫ Runs on virtually all platforms including Linux, Unix and
Windows. Popular for web based application and online
publishing. It is a part of L A M P (Linux, Apache, My SQL,
PHP) stack
 SQLite
⚫ Relational D B M S but it is not client-server database
engine rather, it is embedded into end program. Arguably
the most widely deployed database engine as it is used by
several browsers, O S and embedded systems(Mobiles).
 PostgreSQL
⚫ General purpose object-relational D B M S . It is the most
advanced open source database system. It is free and open
source i.e. source code is available under PostgreSQL
license, a liberal open source license.
C O M M O N D B M S TOOLS FOR MOBILE DEVICES
 S Q L Anywhere, DB2 Everywhere, I B M Mobile
Database, S Q L Server Compact, S Q L Server
Express, Oracle DatabaseLite, SQLite, SQLBase
etc.
 Out of these SQLite is public domain open source

implementation
JUST A MINUTE…
BOOKCODE BOOKNAME PUB PRICE
B001 LET US C BPB 400
B002 VISUAL EEE 350
B AS I C
B003 J AVA PHI 550
B004 VC++ BPB 750

Identify the following in the above table

1) Degree of Table
2) Cardinality of Table
3) Attributes of Table
4) Tuple
5) Data types of Book Code and Price (as studied in Python)
CONCEPT OF KEYS
EMPNO ENAME GENDER DEPTNO S A L A RY COMM
1 AN KI TA F 10 20000 1200
2 SUJEET M 20 24000
3 V I J AYA F 10 28000 2000
4 NI T I N M 30 18000 3000
5 VIKRAM M 30 22000 1700

In relation each record must be unique i.e. no two


identical records are allowed in the Database. A
key attribute identifies the record and must have
unique values. There are various types of Keys:
Primary Key, Candidate Key, Alternate Key
and Foreign Key.
K EYS
 Primary Key
⚫ A set of one or more attribute that can identify a record
uniquely in the relation is called Primary Key.
⚫ There can be only 1 primary key in a table
⚫ Allows only distinct (no duplicate) values and also forces
mandatory entry (NOT N ULL) i.e. we cannot left it blank.
 Candidate Key
⚫ In a table there can be more than one attribute which
contains unique values. These columns are known as
candidate key as they are the candidate for primary key.
⚫ Among these database analyst select one as a primary key
based on requirement like must contain unique value,
compulsory entry and where maximum searching is done
etc.
K EYS
 Alternate Key
⚫ In case of multiple candidate keys, one of them will
be selected as Primary Key and rest of the column
will serve as Alternate Key
⚫ A Candidate Key which is not a primary key is an
Alternate Key.
 Foreign key
⚫ Used to create relationship between two tables.
⚫ It is a non-key attribute whose value is derived from
the Primary key of another table.
⚫ Foreign key column will for the value in Primary key
of another table, if present then entry will be allowed
otherwise data will be rejected.
⚫ Primary Key column table from where values will be
derived is known as Primary Table or Master Table
or Parent Table and Foreign key column table will be
Foreign Table or Detail Table or Child table
EMPLOYEE
EMPNO ENAME GENDER DEPTNO S A L A RY COMM
Child
1 A N K I TA F 10 20000 1200
2 SUJEET M 20 24000 Table
3 V I J AYA F 10 28000 2000
4 N ITIN M 30 18000 3000
5 VIKRAM M 30 22000 1700

DEPARTMEN
T DEPTNO Parent
DNAME L O C AT I O N
Table
10 HR N E W YO R K
20 ACCOUNTS BRAZIL
30 SALES C A NA DA
40 IT I NDI A

From the Above table definition we can observe that the


D E P T N O column of E M P L O Y E E table is deriving its value
from D E P T N O of table D E PA RT M E N T. So we can say that the
D E P T N O of E M P L O Y E E table is a foreign key whose value is
dependent upon the Primary key column D E P T N O of table
D E PA RT M E N T.
REFERENTIAL INTEGRITY
 Used to ensure relationship between records in
related tables are valid and user don’t
accidentally delete or change the related data.
 Referential integrity can be applied when:

⚫ The master table’s column is a Primary Key or has a


unique index
⚫ The related fields have the same data type
⚫ Both tables must belong to same database.
REFERENTIAL INTEGRITY
 When referential integrity is enforced
Foreign Key you using must observe
rules: the following
⚫ You cannot enter a value in Child Table which is not
available in Master Table’s Primary key column.
However you can enter N U L L values in foreign key
⚫ You cannot delete a record from Master Table if
matching record exists in related table
⚫ You cannot modify or change the Primary Key value
in Master table if its matching record is present in
related table.
B R I E F H I S T O RY O F M Y S Q L
 M y S Q L is freely available open source R D B M S
 Can be downloaded from www.mysql.org
 In M y S Q L information is stored in Tables.
 Provides features that support secure environment
for storing, maintaining and accessing data.
 It is fast, reliable, scalable alternative to many of
the
commercial R D B M S today.
 Create and supported by M y S Q L AB, a company
based in Sweden. This company is now subsidiary of
S u n Microsystems. On April 2009 Oracle Corp.
acquires S u n Microsystems.
 The chief inventor of M y S Q L was Michael
Widenius(a.k.a Monty). M y S Q L has been named after
Monty’s daughter My. The logo of M y S Q L is dolphin
and name of that dolphin is ‘Sakila’
M Y S Q L D ATA BAS E S Y S T E M
 M y S Q L database system refers to the
combination of a M y S Q L server instance and
M y S Q L database.
 It operates using Client/Server architecture in

which the server runs on the machine containing


the database and client connects to server over a
network
 M y S Q L is a multiuser database system, meaning

several users can access the database


simultaneously
M Y S Q L D ATA BAS E S Y S T E M
 The Server
⚫ Listens for client requests in over
coming network and access the
requirements
the database
and provide the requested as
information
to the Client per
 The Client the
⚫ Are the programs that connect to M y S Q L server and
sends requests to the server and receives the
response of Server. Client may be the M y S Q L prompt
or it may be Front-end programming which connect
to server programmatically like connecting to M y S Q L
using Python Language or J ava or any other
language
F E AT U R E S O F M Y S Q L
 Speed
⚫ M y S Q L runs very fast.
 Ease of Use
⚫ Can be managed from command line or G U I
 Cost
⚫ Is available free of cost. It is Open Source
 Query language Support
⚫ Supports S Q L
 Portability
⚫ Can be run on any platform and supported by various
compilers
 Data Types
⚫ Supports
various
data
types like
Numbers,
Char etc.
F E AT U R E S O F M Y S Q L
 Security
⚫ Offers privileges and password systems that is very flexible
and secure.
 Scalability and Limits
⚫ Can handle large databases. Some of real life
M y S Q L databases contains millions of records.
 Connectivity
⚫ Clients can connect to M y S Q L using drivers
 Localization
⚫ The server can provide error message to client in
many language
 Client and Tools
⚫ Provides several client and utility programs. Like
mysqldump and mysqladmin. G U I tools like M y S Q L
Administration and Query Browser
Enter the
password
given
S TA RT I N G M Y S Q L during
installation

Click on Start  All Programs  M y S Q L 


M y S Q L Server  M y S Q L Command Line Client
mysql> prompt
means now M y S Q L
is ready to take your
command and
execute

To exit from M y S Q L type exit or quit in front


of mysql prompt
SQL AND M Y S Q L
 S Q L stands for Structured Query Language.
 Is a language that enables you to create and

operate on relational databases.


 M y S Q L uses S Q L in order to access

databases.
 It is the standard language used by almost

all the
database s/w vendors.
 Pronounced as S E Q U E L

 Original version was developed by


IBM’s
Almanden Research Center
 Latest I S O standard of S Q L was released in 2008

and named as SQL:2008


P R O C E S S I N G C A PA B I L I T I E S O F S Q L
 D D L (Data Definition Language)
 D M L (Data Manipulation Language)
 Embedded D M L
 View
 Authorization
 Integrity
 Transaction Control
D ATA D E F I N I T I O N L A N G U A G E
 It allows to create database objects like creating
a table, view or any other database objects.
 The information about created objects are stored
in special file called DATA D I C T I O NA RY
 DATA D I C T I O NA RY contains metadata i.e. data
about data.
 While creating a table D D L allows to specify –
name of table, attributes, data types of each
attribute, may define range of values that
attributes can store, etc
 Major commands of D D L are –
C R EAT E , A LT E R , D R O P
D ATA M A N I P U L AT I O N L A N G U A G E
 It allows to perform following operation
on table
 Retrieval of information stored in table
 Insertion of new data in table
 Modification of existing data in table
 Deletion of existing data from table
 D M L is of 2 type
 Procedural D M L (in this we specify what data
is needed and how to get it)
 N on-Procedural D M L (in this we specify
what
data is needed without specifying how to get it)
 M ain D M L commands are –
S E L E C T, I N S E RT, U P DAT E A N D
DELETE
TCL COMMANDS
 Stands for Transaction Control Language
 M y S Q L transaction allows you to execute a set
of M y S Q L operations to ensure that the
database never contains the result of partial
operations. In a set of operations, if one of them
fails, the rollback occurs to restore the database
to its original state. For example Transfer of
money from one account to another etc.
 It follows AC I D property (Atomicity, Consistency,
Isolation and Durability)
 Commands used for managing the Transaction
are: C O M M I T, R O L L B A C K , S AV E P O I N T and
S E T TRANSACTION
TCL COMMANDS
 Commit
⚫ To save the current transaction
 RollBack
⚫ To undo/cancel the current transaction activity
 Savepoint
⚫ To insert a Flag/Bookmark in various stages of
Transaction, so that later on we can rollback from
any given savepoint
 Set Transaction
⚫ To specify the properties of current Transaction
 Start Transaction
⚫ To start transaction acitivity
TCL COMMANDS
 By default, M y S Q L automatically commits the
changes permanently to the database. To force
M y S Q L not to commit changes automatically,
you use the following statement:
Set autocommit = 0 Or
Set autocommit = O F F
To start again
Set autocommit = 1 Or
Set autocommit = O N
JUST A MINUTE…
 What is Database? What are the advantages of
Database System?
 What is D D L and DML? Give examples of

command belonging to each category

You might also like