Sie sind auf Seite 1von 15

UNIT - I Introduction to Database Management Systems (DBMS)

Overview:
1. 2. 3. 4. 5. Purpose of Database Systems- Application Database Systems Vs File Systems Data Models Entity- Relationship Model Relational Model Other Data Models Database Languages Data-Definition Language (DDL) Data-Manipulation Language (DML) Database System Structure

Purpose of Database Systems


Definition of DBMS
A database-management systems (DBMS) is a collection of interrelated data and a set of programs to access those data. The collection of data, usually referred to as the database, contains information relevant to an enterprise. The primary goal of a DBMS is to provide a way to store and retrieve database information that is both convenient and efficient. 1. Database systems are designed to manage large bodies of information by the enterprises. 2. Management of data involves both defining structures for storage of information and providing mechanisms for the manipulation of information.

3. In addition, the database system must ensure the safety of the information stored, despite system crashes or attempts at unauthorized access. 4. The collection of information stored in the database at a particular moment is called an instance of the database. 5. The overall design of the database is called as the database schema.

Database System Applications


Banking: For customer information, accounts, and loans, and banking transactions. Airlines: For reservations and schedule information. Universities: For student information, course registrations, and grades. Credit card transactions: For purchases on credit cards and generation of monthly statements. Telecommunication: For keeping records of calls made, generating monthly bills, maintaining balances on prepaid calling cards, and storing information about the communication networks. Finance: For storing information about holdings, sales, and purchases of financial instruments such as stocks and bonds. Sales: For customer, product, and purchase information. Human resources: For information about employees, salaries, payroll taxes and benefits, and for generation of paychecks.

Database Systems Vs File Systems


1. The typical File-processing systems is supported by a conventional operating systems. 2. The system stores permanent records in various files, and it needs different application programs to extract records from, and add records to, the appropriate files. 3. Before database management systems (DBMSs) came along, organizations usually stored information in such systems.

4. Keeping organizational information in a file-processing system has a number of major disadvantages: Data redundancy and inconsistency o Multiple file formats (variation in files), duplication of information in different files Difficulty in accessing data o Need to write a new program to carry out each new task Data isolation multiple files and formats

Integrity problems
The data values stored in the database must satisfy certain types of consistency constraints (conditions). For example, the balance of a bank account may never fall below a prescribed amount (say, $25). Developers enforce these constraints in the system by adding appropriate code in the various application programs.

Atomicity of updates
Failures may leave database in an inconsistent state with partial updates carried out Example: Transfer of funds from one account to another should either complete or not happen at all

Concurrent accessed needed for performance


Uncontrolled concurrent accesses can lead to inconsistencies Example: Two people reading a balance and updating it at the same time

Security problems
Hard to provide user access to some, but not all, data Database systems offer solutions to all the above problems

Data Models
Underlying the structure of a database is the data model: a collection of conceptual tools for

describing data data relationships data semantics and consistency constraints.

Two Data Models Entity-Relationship Model Relational Model

Entity-Relationship Model
The entity-relationship (E-R) data model consists of a collection of basic objects, called entities, and of relationships among these objects. For example, each person is an entity, and bank accounts can be considered as entities. Entities are described in a database by a set of attributes. For example, the attributes account-number and balance may describe one particular account in a bank, and they form attributes of the account entity set. Similarly, attributes customer-name, customer-street address and customer-city may describe a customer entity.

An extra attribute customer-id is used to uniquely identify customers (since it maybe possible to have two customers with the same name, street address, and city).

A unique customer identifier must be assigned to each customer. A relationship is an association among several entities. For example, a depositor relationship associates a customer with each account that she has. The set of all entities of the same type and the set of all relationships of the same type are termed an entity set and relationship set, respectively. For example, customer and account related (entity set) to banking concepts. The overall logical structure (schema) of a database can be expressed graphically by an E-R diagram, which is built up from the following components: Rectangles, which represent entity sets Ellipses, which represent attributes Diamonds, which represent relationships among entity sets Lines, which link attributes to entity sets and entity sets to relationships Each component is labeled with the entity or relationship that it represents.

Terms are used in E-R Diagram,


Entity Relationship Attributes Entity set Relationship set Schema

Relational Model
The relational model uses a collection of tables to represent both data and the relationships among those data. Each table has multiple columns, and each column has a unique name.

One shows details of bank customers, the second shows accounts, and the third shows which accounts belong to which customers.

o The relational model is an example of a record-based model. Recordbased models are so named because the database is structured in fixed-format records of several types.

o Each table contains records of a particular type. Each record type defines a fixed number of fields, or attributes. The columns of the table correspond to the attributes of the record type. o A special character (such as a comma) may be used to delimit the different attributes of a record, and another special character (such as a newline character) may be used to delimit records. o Terms are used in Relational Model, Table data and relationships Table multiplt columns unique names Object Oriented Data Model - extending the E-R model- based on the objects and classes Object-relational data model- combines features of the object-oriented data model and relational data model. Network data model and the Hierarchical data model

Database Languages
A database system provides a data definition (structure) language to specify the database schema (overall database structure) and a data manipulation (management) language to express database queries and updates. 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 (Structured Query Language)- database query language.

Data-Definition Language
It specify a database schema by a set of definitions (set of commands) expressed by a special language called a data-definition language (DDL). For example, the following statement in the SQL language defines the account table: create table account (account-number char(10), balance integer)

Execution of the above DDL statement creates the account table. In addition, it updates a special set of tables called the data dictionary or data directory. A data dictionary contains metadatathat is, data about data. The schema of a table is an example of metadata (schema contains multiple tables with different set of datas). A database system consults the data dictionary before reading or modifying actual data. The data values stored in the database must satisfy certain consistency constraints (integrity constraints).

Data-Manipulation Language
1. A data-manipulation language (DML) is a language that enables users to access or manipulate data as organized by the appropriate data model. 2. Data manipulation is The retrieval of information stored in the database The insertion of new information into the database The deletion of information from the database The modification of information stored in the database 3. Two types of DML Procedural DMLs require a user to specify what data are needed and how to get those data (define the path also). Declarative DMLs (also referred to as nonprocedural DMLs) require a user to specify what data are needed without specifying how to get those data. The DML component of the SQL language is nonprocedural. A query is a statement requesting the retrieval of information. The portion of a DML that involves information retrieval is called a query language (Data Manipulation Language) Example 1 This query in the SQL language finds the name of the customer whose customer-id is 192-83-7465:

Example 2 Queries may involve information from more than one table. For instance, the following query finds the balance of all accounts owned by the customer with customerid 192-83-7465.

Data Definition Language (DDL) commands o Create table command SQL>create table employee(Eid number(6), name varchar2(20),city varchar2(30)); o Alter table command SQL>alter table employee modify (name varchar2(30)); SQL>alter table employee add (DOJ date); o Drop table command SQL>drop table employee; o Truncate command SQL>truncate table employee; o Desc command SQL>desc employee; Data Manipulation Language (DML) commands o Insert Command Explanation: Insert is used add one/more rows to a table while using this command the value are separated by commas and the data types char and date are enclosed in apostrophes. The

values must be entered in the same order as they are defined in the table. Syntax: insert into <tablename> values (a list of datavalues); Example: SQL>insert into orderinfo values(123,12-jan-99,b); o Select Command Select command can be used in 3 ways. To display all the tuples (records) in the relation. Syntax select *from <tablename>; Example select *from employee; Select command without using where clause To display a particular attribute from the relation. Syntax select <attributename> from <tablename>; Example select ename from employee; Select command with where clause To display a particular tuple from a relation. Syntax select *from <tablename> where <condition>; Example select *from employee where eid=5; Update Command To update the value of a particular attribute in a relation is Syntax update <tablename> set <field>=value; Example update employee set age=age+1; Update command with where clause To update the value of a particular tuple in a relation. Syntax

update <tablename> set <field>=<value> where <condition>; Example update employee set salary=salary+500 where eid=1; Delete Command After inserting rows in a table we can also delete it if required. The delete command consists of a from clause followed by an optional where clause. Delete with where clause To delete a particular tuple from a relation. Syntax delete from <table name> where <condition>; Example delete from employee where eid=4;

Delete with without where clause To delete all the tuples in a relation. Syntax delete from <table name>; Example delete from employee; Rename Command This command renames the name of the table. Example rename stud to stud1; Note : For remaining queries, refer the lab exercise document (Exercise No 3) Delete with without where clause To delete all the tuples in a relation. Syntax delete from <table name>;

Example delete from employee; Rename Command This command renames the name of the table. Example rename stud to stud1; Note : For remaining queries, refer the lab exercise document (Exercise No 3) Difference between char,varchar,varchar2 CHAR should be used for storing fix length character strings. String values will be space/blank padded before stored on disk. Example SQL> CREATE TABLE char_test (col1 CHAR(10)); Table created SQL> INSERT INTO char_test VALUES (jasmine'); 1 row created. SQL> SELECT col1, length(col1), FROM char_test; Len=10: 113,119,101,114,116,121,32,32,32,32 varchar and varchar2 VARCHAR can store up to 2000 bytes of characters while VARCHAR2 can store up to 4000 bytes of characters. If we declare data type as VARCHAR then it will occupy space for NULL values, In case of VARCHAR2 data type it will not occupy any space. Example SQL> CREATE TABLE char_test (col1 CHAR(10)); Table created SQL> INSERT INTO char_test VALUES (jasmine'); 1 row created. SQL> SELECT col1, length(col1), FROM char_test;

Len=10: 113,119,101,114,116,121

Database System Structure


A database system is partitioned into modules that deal with each of the responsibilities of the overall system. The functional components of a database system can be broadly divided into, storage manager query processor components. Storage Manager A storage manager is a program module that provides the interface between the low level data stored in the database and the application programs and queries submitted to the system. Thus, the storage manager is responsible for storing, retrieving, and updating data in the database Since the main memory of computers cannot store this much information, the information is stored on disks. Data are moved between disk storage and main memory as needed. (swapping in and swapping out operations) The storage manager components include: Authorization and integrity manager, which tests for the satisfaction of integrity constraints and checks the authority of users to access data. Transaction manager, which ensures that the database remains in a consistent (correct) state despite system failures, and that concurrent transaction executions proceed without conflicting. File manager, which manages the allocation of space on disk storage and the data structures used to represent information stored on disk. Buffer manager, which is responsible for fetching data from disk storage into main memory, and deciding what data to cache in main memory. The buffer manager is a critical part of the database system,

since it enables the database to handle data sizes that are much larger than the size of main memory. The storage manager implements several data structures, Data files, which store the database itself. Data dictionary, which stores metadata about the structure of the database, in particular the schema of the database. Indices, which provide fast access to data items that hold particular values. Query Processor The query processor subsystem complies and executes DDL and DML statements The query processor components include, DDL interpreter, which interprets DDL statements and records the definitions in the data dictionary. DML compiler, which translates DML statements in a query language into an evaluation plan consisting of low-level instructions that the query evaluation engine understands. Query evaluation engine, which executes low-level instructions generated by the DML compiler.

Das könnte Ihnen auch gefallen