Lecture On Database
Lecture On Database
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 1 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
Levels of Abstraction
Physical level: describes how a record (e.g., customer) is stored.
Logical level: describes data stored in database, and the relationships among the data.
o type customer = record
customer_id : string;
customer_name : string;
customer_street : string;
customer_city : string;
end;
View level: application programs hide details of data types. Views can also hide information (such as
an employees salary) for security purposes.
View of Data
Fig. An architecture for a database system
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 2 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
Data Models
A collection of tools for describing
o Data
o Data relationships
o Data semantics
o Data constraints
Relational model
Entity-Relationship data model (mainly for database design)
Object-based data models (Object-oriented and Object-relational)
Semistructured data model (XML)
Other older models:
o Network model
o Hierarchical model
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 3 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
Relational Model
Example of tabular data in the relational model
Database Design
The process of designing the general structure of the database:
Logical Design Deciding on the database schema. Database design requires that we find a good
collection of relation schemas.
o Business decision What attributes should we record in the database?
o Computer Science decision What relation schemas should we have and how should the
attributes be distributed among the various relation schemas?
Physical Design Deciding on the physical layout of the database
Transaction Management
A transaction is a collection of operations that performs a single logical function in a database
application
Transaction-management component ensures that the database remains in a consistent (correct)
state despite system failures (e.g., power failures and operating system crashes) and transaction
failures.
Concurrency-control manager controls the interaction among the concurrent transactions, to ensure
the consistency of the database.
Database Administrator
Coordinates all the activities of the database system; the database administrator has a good
understanding of the enterprises information resources and needs.
Database administrator's duties include:
o Schema definition
o Storage structure and access method definition
o Schema and physical organization modification
o Granting user authority to access the database
o Specifying integrity constraints
o Acting as liaison with users
o Monitoring performance and responding to changes in requirements
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 5 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
Dr. E.F. Codd proposed the relational model for database systems in 1970.
You can logically relate data from multiple tables using foreign keys (FK).
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 6 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
A relational database:
Can be accessed and modified by executing structured query language (SQL) statements
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 7 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
SQL Statements
FROM table;
FROM table;
SELECT *
FROM departments;
FROM departments;
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 8 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
Arithmetic Expressions
Create expressions with number and date data by using arithmetic operators.
FROM employees;
Operator Precedence
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 9 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
Operator Precedence
FROM employees;
Using Parentheses
FROM employees;
FROM employees;
FROM employees;
A column alias:
Immediately follows the column name - there can also be the optional AS keyword between the column
name and alias
Requires double quotation marks if it contains spaces or special characters or is case sensitive
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 10 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
FROM employees;
FROM employees;
Concatenation Operator
A concatenation operator:
FROM employees;
Date and character literal values must be enclosed within single quotation marks.
FROM employees;
Duplicate Rows
SELECT department_id
FROM employees;
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 11 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
Eliminate duplicate rows by using the DISTINCT keyword in the SELECT clause.
FROM employees;
DESC[RIBE] tablename;
DESCRIBE employees;
DESC employees;
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 12 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
FROM table
[WHERE condition(s)];
FROM employees
WHERE department_id = 90 ;
Character strings and date values are enclosed in single quotation marks.
Character values are case sensitive, and date values are format sensitive.
FROM employees
Comparison Conditions
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 13 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
FROM employees
FROM employees
FROM employees
Use the LIKE condition to perform wildcard searches of valid search string values.
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 14 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
SELECT first_name
FROM employees
SELECT last_name
FROM employees
You can use the ESCAPE identifier to search for the actual % and _ symbols.
FROM employees
Logical Conditions
FROM employees
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 15 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
FROM employees
FROM employees
Rules of Precedence
FROM employees
OR job_id = 'AD_PRES'
FROM employees
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 16 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
ORDER BY Clause
FROM employees
ORDER BY hire_date ;
FROM employees
FROM employees
ORDER BY annsal;
FROM employees
FROM employees
Manipulating Data
A transaction consists of a collection of DML statements that form a logical unit of work.
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 18 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
(department_id, department_name )
UPDATE table
[WHERE condition];
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 19 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
Specific row or rows are modified if you specify the WHERE clause.
UPDATE employees
SET department_id = 70
All rows in the table are modified if you omit the WHERE clause.
UPDATE copy_emp
You can remove existing rows from a table by using the DELETE statement.
[WHERE condition];
All rows in the table are deleted if you omit the WHERE clause.
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 20 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
Database Transactions
Database Transactions
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 21 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
UPDATE...
SAVEPOINT update_done;
Savepoint created.
INSERT...
ROLLBACK TO update_done;
Rollback complete.
Normal exit from iSQL*Plus, without explicitly issuing COMMIT or ROLLBACK statements
The current user can review the results of the DML operations by using the SELECT statement.
Other users cannot view the results of the DML statements by the current user.
The affected rows are locked; other users cannot change the data within the affected rows.
Locks on the affected rows are released; those rows are available for other users to manipulate.
Committing Data
1 row deleted.
1 row inserted.
COMMIT;
Commit complete.
22 rows deleted.
ROLLBACK;
Rollback complete.
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 23 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
Statement-Level Rollback
If a single DML statement fails during execution, only that statement is rolled back.
The user should terminate transactions explicitly by executing a COMMIT or ROLLBACK statement.
Read Consistency
Changes made by one user do not conflict with changes made by another user.
Naming Rules
Must not duplicate the name of another object owned by the same user
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 24 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
A storage area
Creating Tables
(deptno NUMBER(2),
dname VARCHAR2(14),
loc VARCHAR2(13));
Table created.
DESCRIBE dept;
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 25 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
User Tables:
Data Dictionary:
SELECT table_name
FROM user_tables ;
FROM user_objects ;
SELECT *
FROM user_catalog ;
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 26 of 27
ACT-506: Advanced Application of Computer in Textiles Lecture on Database
Dropping a Table
Table dropped.
A.N.M. Bazlur Rashid, Assistant Professor (Computer) & Head, Department of Allied Engineering, Bangladesh University of Textiles / Page 27 of 27