Er. Nawaraj Bhandari Database
Record Keeping Systems
File system on a computer Word document Excel Spreadsheet Access database Manual card index file Files on a USB stick Are these all databases?
Database Size - 1
Databases range in size:
Single user databases on a PC Small office database with everyone doing the
same sorts of tasks Medium size database system with core data but
people doing different tasks Corporate databases spread over many sites Very large databases and data-warehouses
But databases aren’t like buckets!
Database systems are not just a mass of data
It isn’t just about what they can hold
They are organised So we need a more
precise definition
More Detailed Definition
“We define a database as an organised collection of logically related data”.
Organised
Data is structured so as to be easily stored, manipulated and retrieved by users.
It is no good just having some data if we don’t know how to get it in order to look at it and use it.
Related
Pieces of data do not exist in isolation For example:
In a salesperson’s database, it is natural for the customer’s name and the customer’s address to be stored together
They are related Together, with other data about the customer,
they are part of a meaningful set
Data Data are any raw facts, numbers, or text that can be processed by
a computer.
Data can be found in different formats : 1. operational or transactional data such as, sales, cost,
inventory, payroll, and accounting
2. nonoperational data such as forecast data
3. meta data - data about the data itself, such as logical database design or data dictionary definitions
Types of Data
1. Traditionala. Text such as names, address etc.b. Numbers such as age, roll number, number of friends, etc.c. Dates such as a date of birth, college enrolled date, exam
date, etc.
2. Multi-mediaa. Imagesb. Soundsc. Video
Data and Information
There is a little distinction between ‘data’ and ‘information’
Data are ‘raw facts’.
Bagum, Ammena 01.02.81 97327627Ako, Sarah 08.08.81 98737373Finkle, Clive 09.09.81 93838383Mc Farren, Debra 01.01.80 98383837Sinseros, Douglas 27.05.80 99344222
Information
Information is data that has been processed in such a way that it can increase the knowledge of the person who uses it.
Student Name Date of Birth Student IDBagum, Ammena 01.02.81 97327627Ako, Sarah 08.08.81 98737373Finkle, Clive 09.09.81 93838383Mc Farren, Debra 01.01.80 98383837Sinseros, Douglas 27.05.80 99344222
SQL is a Standard
SQL(Structural Query Language) is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems.
SQL statements are used to retrieve and update data in a database.
SQL works with database programs like MS Access, DB2, Informix, MS SQL Server, Oracle, Sybase, etc.
SQL Database Tables
A database most often contains one or more tables. Each table is identified by a name (e.g. “Workers" or “Departments"). Tables contain records (rows) with data.
Below is an example of a table called “Workers":
LastName FirstName Jobtitle Age
Surani Lawrence Manager 56
Argo Emily 32
Villa Ahmed Packer 25
Manager
With SQL, we can query a database and have a result set returned.
A query like this:
SELECT LastName FROM workers
Gives a result set like this:
SQL Queries
LastName
Surani
Argo
Villa
• Data Definition Language(DDL)• Data Manipulation Language (DML) • Data Control Language (DCL) • Transaction Control (TCL)
SQL COMMANDS
DDL statements are used to define the database structure or schema
Data Definition Language(DDL)
• CREATE: to create objects in the database• ALTER: updates the structure of the database• DROP - delete objects from the database• TRUNCATE - remove all records from a table,
including all spaces allocated for the records are removed
• COMMENT - add comments to the data dictionary
DML statements are used for managing data within schema objects.
Data Manipulation Language (DML)
• SELECT - retrieve data from the a database• INSERT - insert data into a table• UPDATE - updates existing data within a table• DELETE - deletes all records from a table, the space
for the records remain• MERGE - UPSERT operation (insert or update)• CALL - call a PL/SQL or Java subprogram• EXPLAIN PLAN - explain access path to data• LOCK TABLE - control concurrency
Data Control Language (DCL)
• GRANT - gives user's access privileges to database
• REVOKE - withdraw access privileges given with the GRANT command
TCL statements are used to manage the changes made by DML statements. It allows statements to be grouped together into logical transactions.
Transaction Control Language (TCL)
• COMMIT - save work done• ROLLBACK - restore database to original since the last
COMMIT• SAVEPOINT - identify a point in a transaction to which
you can later roll back• SET TRANSACTION - Change transaction options like
isolation level and what rollback segment to use