5. EVOLUTION OF DATABASE
5 Oracle Database, SQL
How to manage my data?
• How to search?
• How to edit?
• How to delete?
Various access methods , e.g., sequential, indexed,
random
• Requires extensive programming in third-generation language such as COBOL,
BASIC.
• Duplication of data
• Weak security.
1968
6. EVOLUTION OF DATABASE
6 Oracle Database, SQL
Earlier,
punched cards technology
was used to store the data
9. EVOLUTION OF DATABASE
9 Oracle Database, SQL
1970-Present
Edgar Frank "Ted" Codd
Father of Database Management Systems
10. EVOLUTION OF DATABASE
10 Oracle Database, SQL
1970-Present
Era of RDBMS
The relational database model was
conceived by E. F. Codd in 1970. It can be
defined using the following two
terminologies:
• Instance – a table with rows or
columns.
• Schema – specifies the structure (name
of relation, name and type of each
column)
11. EVOLUTION OF DATABASE
11 Oracle Database, SQL
1970-Present
Rule 0: Foundation rule
Any relational database management system that is propounded to be
RDBMS or advocated to be a RDBMS should be able to manage the
stored data in its entirety through its relational capabilities.
Rule 1: Rule of Information
Relational Databases should store the data in the form of relations.
Tables are relations in Relational Database Management Systems. Be
it any user defined data or meta-data, it is important to store the
value as an entity in the table cells.
Rule 2: Rule of Guaranteed Access
The use of pointers to access data logically is strictly forbidden. Every
data entity which is atomic in nature should be accessed logically by
using a right combination of the name of table, primary key
represented by a specific row value and column name represented by
attribute value.
12. EVOLUTION OF DATABASE
12 Oracle Database, SQL
1970-Present
Rule 3: Rule of Systematic Null Value Support
Null values are completely supported in relational databases. They should be uniformly
considered as ‘missing information’. Null values are independent of any data type. They
should not be mistaken for blanks or zeroes or empty strings. Null values can also be
interpreted as ‘inapplicable data’ or ‘unknown information.’
Rule 4: Rule of Active and online relational Catalog
In the Database Management Systems lexicon, ‘metadata’ is the data about the database or
the data about the data. The active online catalog that stores the metadata is called ‘Data
dictionary’. The so called data dictionary is accessible only by authored users who have the
required privileges and the query languages used for accessing the database should be used
for accessing the data of data dictionary.
Rule 5: Rule of Comprehensive Data Sub-language
A single robust language should be able to define integrity constraints, views, data
manipulations, transactions and authorizations. If the database allows access to the
aforementioned ones, it is violating this rule.
13. EVOLUTION OF DATABASE
13 Oracle Database, SQL
1970-Present
Rule 6: Rule of Updating Views
Views should reflect the updates of their respective base tables and vice versa. A view is a
logical table which shows restricted data. Views generally make the data readable but not
modifiable. Views help in data abstraction.
Rule 7: Rule of Set level insertion, update and deletion
A single operation should be sufficient to retrieve, insert, update and delete the data.
Rule 8: Rule of Physical Data Independence
Batch and end user operations are logically separated from physical storage and respective
access methods.
Rule 9: Rule of Logical Data Independence
Batch and end users can change the database schema without having to recreate it or recreate
the applications built upon it.
14. EVOLUTION OF DATABASE
14 Oracle Database, SQL
1970-Present
Rule 10: Rule of Integrity Independence
Integrity constraints should be available and stored as metadata in data dictionary and not in
the application programs.
Rule 11: Rule of Distribution Independence
The Data Manipulation Language of the relational system should not be concerned about the
physical data storage and no alterations should be required if the physical data is centralized or
distributed.
Rule 12: Rule of Non Subversion
Any row should obey the security and integrity constraints imposed. No special privileges are
applicable.
15. SQL
Oracle Database, SQL15
• SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to
communicate with a database.
• According to ANSI (American National Standards Institute), it is the standard language for
relational database management systems.
• SQL statements are used to perform tasks such as update data on a database, or retrieve data
from a database.
• Some common relational database management systems that use SQL are: Oracle, Sybase,
Microsoft SQL Server, Access, Ingres, etc.
• Although most database systems use SQL, most of them also have their own additional
proprietary extensions that are usually only used on their system. However, the standard SQL
commands such as "Select", "Insert", "Update", "Delete", "Create", and "Drop" can be used to
accomplish almost everything that one needs to do with a database
16. Oracle Database, SQL16
DDL DML DQL
DCL TCL DAL
Languages
• DDL (Data Definition Language)
• DML (Data Manipulation Language)
• DQL (Data Query Language)
• DCL (Data Control Language)
• TCL(Transactional control Language)
• DAL (Data Administration Language)
17. Oracle Database, SQL17
DDL
Data Definition Language, DDL , is the part of SQL that allows a
database user to create and restructure database objects.
CREATE TABLE
ALTER TABLE
DROP TABLE
CREATE INDEX
DROP INDEX
CREATE VIEW
DROP VIEW
18. Oracle Database, SQL18
CREATE TABLE
The basic syntax of the CREATE TABLE statement is as follows −
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype
);
CREATE TABLE CUSTOMERS(
ID NUMBER,
NAME VARCHAR (20),
AGE NUMBER,
ADDRESS CHAR (25) ,
SALARY NUMBER,
);
19. Oracle Database, SQL19
CREATE TABLE
To create table using another table:
CREATE TABLE new_table_name
AS
SELECT [ column1, column2...columnN ]
FROM existing_table_name
[ WHERE ]
;
CREATE TABLE SALARY
AS
SELECT ID, SALARY
FROM CUSTOMERS;
20. Oracle Database, SQL20
ALTER TABLE
The basic syntax of an ALTER TABLE command to add a New Column:
ALTER TABLE table_name
ADD
column_name datatype;
ALTER TABLE Customers
ADD
Mobile varchar2(10);
To DROP COLUMN in an existing table:
ALTER TABLE Customers
DROP COLUMN
Mobile;
ALTER TABLE table_name
DROP COLUMN
column_name ;
21. Oracle Database, SQL21
ALTER TABLE
To change the DATA TYPE of a column in a table:
ALTER TABLE table_name
MODIFY
column_name new_datatype;
ALTER TABLE Customers
MODIFY
Name varchar2(30);
To rename column name in a table:
ALTER TABLE Customers
RENAME COLUMN
Name TO FullName;
ALTER TABLE table_name
RENAME COLUMN
Old_Column_Name TO New_Column_Name;
22. Oracle Database, SQL22
ALTER TABLE
To RENAME TABLE:
ALTER TABLE table_name
RENAME TO
New_Table_Name;
ALTER TABLE Customers
RENAME TO
CustomerDetails;
24. Oracle Database, SQL24
CREATE INDEX
Indexes are used to retrieve data from the database very fast. The users
cannot see the indexes, they are just used to speed up searches/queries.
Note: Updating a table with indexes takes more time than updating a table
without (because the indexes also need an update). So, only create indexes on
columns that will be frequently searched against.
CREATE UNIQUE INDEX CustomerIDIndex
ON
CustomerDetails (ID);
CREATE [UNIQUE] INDEX TableName
ON
Table Name (Column1, Column2);
26. Oracle Database, SQL26
CREATE VIEW
A view is nothing more than a SQL statement that is stored in the database
with an associated name. A view is actually a composition of a table in the
form of a predefined SQL query.
A view can contain all rows of a table or select rows from a table. A view
can be created from one or many tables which depends on the written SQL query
to create a view.
CREATE VIEW IndianCustomers AS
SELECT *
FROM CustomerDetails
WHERE Address LIKE ‘%India%’;
CREATE VIEW View_Name AS
SELECT column1, column2,…., coulmnN
FROM Tablename
[WHERE];
28. Oracle Database, SQL28
DML
Data Manipulation Language, DML , is the part of SQL used to manipulate data
within objects of a relational database.
INSERT
UPDATE
DELETE
29. Oracle Database, SQL29
INSERT
The basic syntax of INSERT:
INSERT INTO Customers VALUES (101, ‘Ramesh’, 23,’New Delhi, India’,10000);
INSERT INTO Customers (ID, NAME, AGE, ADDRESS, SALARY)
VALUES (101, ‘John’, 23,’New Street, UK’,10000);
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)
SELECT column1, column2, column3 FROM tablename;
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)
VALUES (value1, value2, value3,...valueN);
INSERT INTO EMP_HISTORY
SELECT EMPLOYEE_ID, EMPLOYEE_NAME, SALARY, DEPARTMENT_ID
FROM employees;
30. Oracle Database, SQL30
DELETE
The basic syntax of DELETE:
DELETE FROM Customers WHERE ID=100;
DELETE FROM Customers;
DELETE FROM TABLE_NAME [WHERE];
31. Oracle Database, SQL31
UPDATE
The basic syntax of UPDATE:
UPDATE Customers SET salary =20000
WHERE ID=100;
UPDATE TableName
SET
Column1=Value1,
Column1=Value1,
…,
ColumnN=ValueN
[WHERE];
32. Oracle Database, SQL32
DQL/DRL
Data Query Language (DQL) or Data Retrieval Language (DRL) is the most concentrated focus of SQL for
modern relational database users
SELECT
The SQL SELECT statement is used to fetch the data from a database table which returns this data in the
form of a result table. These result tables are called result-sets.
The basic syntax of the SELECT statement is as follows −
SELECT ID, Name,Salary From Customers;
SELECT column1, column2, columnN FROM table_name;
33. Oracle Database, SQL33
DCL
It allow you to control access to data within the database.
DCL commands are normally used to create objects related to user access and
also control the distribution of privileges among users.
GRANT
REVOKE
34. Oracle Database, SQL34
GRANT
Use the GRANT statement to give privileges to a specific user or role, or to
all users, to perform actions on database objects. You can also use the GRANT
statement to grant a role to a user, to PUBLIC, or to another role.
The following types of privileges can be granted:
Delete data from a specific table.
Insert data into a specific table.
Update data in a table or in a subset of columns in a table.
Select data from a table, view, or a subset of columns in a table.
Create a trigger on a table.
Run a specified function or procedure.
The syntax that you use for the GRANT statement depends on whether you are granting privileges to a
schema object or granting a role
35. Oracle Database, SQL35
GRANT
Privilege is the permission name, which is granted to the user. It may be SELECT, INSERT, UPDATE, DELETE,
EXECUTE, ALL and many others, on a database object.
Privileges are of two types
System privilege – Schema level privilege which is granted by DBA to the users is known as System
privilege. They include privilege to issue commands like CREATE (cluster, database link, directory, job,
procedure, role, synonym, table, trigger, tablespace, types, view, database), ALTER, DROP, DEBUG,
FLASHBACK, LOCK, CONNECT, RESOURCE etc. Please note that these privileges are not limited to an
object access, but applicable at User level.
Object privilege – Object level privilege can be granted from object owning user (Grantor) to other user
(GRANTEE). Grantor permits access on a specific object and grantee enjoys the access privilege only on
the database object concerned. It may be DELETE, SELECT, INSERT, UPDATE, EXECUTE, INDEX, READ,
WRITE, ALTER (table, sequence).
36. Oracle Database, SQL36
GRANT
ADMIN option allows the Grantee to grant a System privilege to other user. Only DBA or user with GRANT
ANY PRIVILEGE system privilege can grant a system privilege to other users. Users which possess a system
privilege with ADMIN option can pass only that system privilege.
GRANT option allows the Grantor (owner) to grant an Object privilege on an object to other user. To
grant an object privilege, grantor must satisfy any of the below criteria:
1. He must own the object
2. He must have access on object with GRANT OPTION from the owner of the object
3. He must have GRANT ANY OBJECT PRIVILEGE system privilege and an object privilege on the object
37. Oracle Database, SQL37
GRANT
Syntax for objects
GRANT [privilege]
ON [object]
TO {user |PUBLIC |role}
[WITH ADMIN | GRANT OPTION];
GRANT SELECT ON T1 TO U2;
GRANT CREATE INDEX TO U1 WITH ADMIN OPTION;
Syntax for roles
GRANT roleName [ {, roleName }* ] TO grantees
38. Oracle Database, SQL38
REVOKE
REVOKE command is used to revoke an existing privilege from a user. It can revoke a system privilege,
object privilege or a role from a user. Only DBA or a user with ADMIN OPTION can revoke system
privilege.
REVOKE [privilege]
ON [object]
FROM {USER |PUBLIC | ROLE}
REVOKE SELECT ON T1 FROM U1;
39. Oracle Database, SQL39
DAL
Data administration commands allow the user to perform audits and perform
analyses on operations within the database.
They can also be used to help analyze system performance.
START AUDIT
STOP AUDIT
40. Oracle Database, SQL40
TCL
It allow the user to manage database transactions.
COMMIT Saves database transactions
ROLLBACK Undoes database transactions
SAVEPOINT Creates points within groups of transactions in which to ROLLBACK
SET TRANSACTION Places a name on a transaction
SET TRANSACTION READ ONLY NAME 'T1';
41. Oracle Database, SQL41
Constraints
Constraints are the rules enforced on the data columns of a table. These are used to limit the type of data that
can go into a table. This ensures the accuracy and reliability of the data in the database.
Constraints can be divided into following two types:
• Column level constraints : limits only column data
• Table level constraints : limits whole table data
1. NOT NULL
2. UNIQUE
3. PRIMARY KEY
4. FOREIGN KEY
5. CHECK
6. DEFAULT
42. Oracle Database, SQL42
NOT NULL
REVOKE command is used to revoke an existing privilege from a user. It can revoke a system privilege,
object privilege or a role from a user. Only DBA or a user with ADMIN OPTION can revoke system
privilege.
REVOKE [privilege]
ON [object]
FROM {USER |PUBLIC | ROLE}
REVOKE SELECT ON T1 FROM U1;
43. Oracle Database, SQL43
NOT NULL constraint restricts a column from having a NULL value. Once NOT NULL constraint is applied to a
column, you cannot pass a null value to that column. It enforces a column to contain a proper value. One
important point to note about NOT NULL constraint is that it cannot be defined at table level.