11. Database Concept
11. Database Concept
DATABASE
DEPARTMENT
DEPTNO DNAME LOCATION
10 HR NEW YORK
20 ACCOUNTS BRAZIL
30 SALES CANADA
40 IT INDIA
COMPONENT OF A TABLE
Byte : group of 8 bits and is used to store a
character.
Data Item : smallest unit of named data. It
represent one type of information
and often referred to as a field or
column information
Record : collection of data items which
represent a complete unit of
information
Table : collection of all Rows and Columns.
Fields Table
SQLite
PostgreSQL
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 SALARY COMM
1 ANKITA F 10 20000 1200
2 SUJEET M 20 24000
3 VIJAYA F 10 28000 2000
4 NITIN M 30 18000 3000
5 VIKRAM M 30 22000 1700
Allows only distinct (no duplicate) values and also forces mandatory entry
(NOT NULL) 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.
Foreign key
Used to create relationship between two tables.
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 SALARY COMM
Child
1 ANKITA F 10 20000 1200 Table
2 SUJEET M 20 24000
3 VIJAYA F 10 28000 2000
4 NITIN M 30 18000 3000
5 VIKRAM M 30 22000 1700
DEPARTMENT
Parent
DEPTNO DNAME LOCATION
Table
10 HR NEW YORK
20 ACCOUNTS BRAZIL
30 SALES CANADA
40 IT INDIA
From the Above table definition we can observe that the DEPTNO
column of EMPLOYEE table is deriving its value from DEPTNO of table
DEPARTMENT. So we can say that the DEPTNO of EMPLOYEE table
is a foreign key whose value is dependent upon the Primary key column
DEPTNO of table DEPARTMENT.
REFERENTIAL INTEGRITY
You cannot modify or change the Primary Key value in Master table
if its matching record is present in related table.
BRIEF HISTORY OF MYSQL
MySQL is freely available open source RDBMS
Speed
MySQL runs very fast.
Ease of Use
Can be managed from command line or GUI
Cost
Is available free of cost. It is Open Source
Query language Support
Supports SQL
Portability
Can be run on any platform and supported by various
compilers
Data Types
Supports various data types like Numbers, Char etc.
FEATURES OF MYSQL
Security
Offers privileges and password systems that is very flexible
and secure.
Connectivity
Clients can connect to MySQL using drivers
Localization
The server can provide error message to client in many language
Pronounced as SEQUEL
Embedded DML
View
Authorization
Integrity
Transaction Control
DATA DEFINITION LANGUAGE
The information about created objects are stored in special file called
DATA DICTIONARY
DML is of 2 type
Procedural DML (in this we specify what data is needed and how to
get it)
Non-Procedural DML (in this we specify what
data is needed without specifying how to get it)
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