Introduction To Database Management

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

INTRODUCTION TO DATABASE MANAGEMENT

Database management is the process of storing data in a computer in an organized manner and can
be retrieved electronically.

PROCEDURES FOR CREATNG TABLES

1.CREAT TABLE DEPARTMENT

(Essn VARCHAR(9) NOT NULL,

Department _name VARCHAR(15) NOT NULL,

Sex CHAR,

Bdate DATE,

Relationship VARCHAR(8),

Primary key(Essn,Department_name),

Foreign key(Essn) REFERENCES EMPLOYEES.

2.CREAT TABLE WORKS_ON

(Essn CHAR(9) NOT NULL,

Pno INT NOT NULL,

Hours DECIMAL(1,2) NOT NULL

Primary key(Essn,Pno),

FOREIGN KEY(Essn)REFERENCES EMPLOYEES

3.CREAT TABLE PROJECT

(Pname VARCHAR(15) NOT NULL,

PnumberINT NOT NULL,

Plocation VARCHAR(15),

Dnum INT NOT NULL,

PRIMARY KEY (Pnumber),

UNIQUE(Pname),

FOREIGN KEY(Dnum) REFERENCES DEPARTMENT (Dnumber);

EXAMPLE OF TABLE PROJECT HOW IT WIIL BE DISPLAYED

Pname Pnumber Plocation Dnumber


To order a given column (attribute)from the smallest to the largest the command ORDER
BY,ATTRIBUTE_NAME ASC likewise to arrange to arrange the attribute from the largest to the
smallest,we use ORDER BY ATTRIBUTE_NAME ASC.

EXAMPLE

SELECT Fname FROM

EMPLOYEES

ORDER BY Fname DESC

DELETE COMMAND

DELETE COMMAND is used to remove a tuple or a row from a relation or table.

EXAMPLE

DELETE *FROM EMPLOYEE,

WHERE Lname=’Brown’

UPDATE COMMAND

UPDATE COMMAND is used to modifies values of the selected attributes

EXAMPLE

UPDATE PROJECT,

SET Plocation=”Ballairre”,Dname=5,

WHERE Pnumber=10

How to fetch NULL values

SELECT Fname,Lname,

FROM EMPLOYEE,
WHERE Super_Ssn is NULL
Aggregate of functions to the SQL
SELECT SUM(SALARY), MAX(SALARY), MIN(SALARY), AVG(SALARY)
FROM EMPLOYEES
SUM finds or compute the sum of all the values of a given attribute in a given relation.
MAX the maximum values or the largest of a given attribute.
MIN finds the minimum values of a given attribute.
AVG finds the average of all the values of a given attribute.
COUNT
EXAMPLE
SELECT COUNT(*)
FROM EMPLOYEE
GROUP BY clause
SELECT SALARY,COUNT(SALARY)
FROM EMPLOYEE

SELECT Dno,COUNT(Dno)
FROM EMPLOYEE GROUP BY Dno

SELECT SALARY,Dno,COUNT(Dno)
FROM EMPLOYEE GROUP BY Dno
ATTRIBUTE
Are the properties that defines a relation
RELATION SCHEMA the design of one table containing the name of the table(relation) and the name of
the column.
Properties of the attributes
 Tuples in a relation are not ordered and do not change the table.
 Once the schema is defined,Vi,in each tuple,t,must be ordered.
Properties of the relations
 Relation is distinct from any other relation.
 Each cell in a relation contains exactly one value of atomic.
 Each attribute has distinct name.
 Values of an attribute are all from the same domain.
 Order of the attributes have no significance.
 Each tuple is distinct ,there are no duplicate tuples.
 Order of tuples has no significance.
Relational keys
 A candidate keys
 Super key
 Primary key
A super key
A super key is a key that uniquely identifies a tuple within a relation.
A relation may have more than one super key but is always has at least one.
Candidate key
It is a super key that is minimal that is, there is no proper subset that is itself a super key.
Properties of a super key
 In each tuple of a relation the values of a relation schema uniquely identify that tuple(unique).
 No proper subset of a relation schema has the uniqueness properties(irreducibility).
Primary key
The primary key of a relation is a candidate key especially selected to be the key for the relation.
Relational language
Relational language is an abstract language which provides the database users with an interface
through which they can specify data to be retrieved.
Foreign key
Is the attribute within one relation that matches candidate key of another relation.
Relational algebra
Is a procedural language consisting of a set of operators
Each operator rakes one or more relations as its inputs and produces relation as its output.
Characteristics of a relation
 Ordering of a tiple in a relation-element of a set have no order among them therefore tuples
in a relation are not ordered.
 Ordering of values within a tuple-a tuple is a list of n values.so the ordering of values in a
tuple is important.
 Values and NULL in a tuple-each value in a tuple is an atomic value i.e.it is not divisible into
components within the framework of basic relation model.
NULL values are used to represent the values that may be unknown or may not apply to a tuple.
 Interpretation of a relation-a relation schema can be represented as a declaration or type of
assertion. Each tuple in a relation can be interpreted as a fact.
Categories of databases constraints
 Constraints that are inherent to the model-inherent model-based constraint
 Constraints that can be directly expressed in the scheme of the data model. Typically
defined in the data definition language.
 Constraints that cannot directly expressed in the schemas of the data model and hence
must be expressed and enforced by a data program.
Example
Application based
Semantic based
Business rules
Domain constraints
Domain constraints specify within each tuple, the value of each attribute must be atomic value
from the domain
Key constraints and constraints on NULL values
All tuple in a relation must be distinct or unique.
This means that no two tuples can have the same combination of values of all their attributes
Usually there are other subset of the attribute of a relation schema with the property that no two
tuple an have the same combination of all values for all their attributes

Types of the databases


Distributed database-it is o e that is spread out over multiple devices.
Personal database-is a database that is designated for the single user
End user database-a database that is primarily used by a single person
Commercial database-is a database that is designated by the commercial business
Operational database -is a database that allows the user to modify a data a real-time

You might also like