Unit 1
Unit 1
Unit 1
• RDBMS
o RDBMS stands for Relational Database Management System.
o Examples of RDBMS
Dr. Codd has used the term guideline because till date no commercial
relational database system fully conforms to all 12 rules.
• This rule states that any database system should have characteristics as
relational, as a database and as a management system to be RDBMS.
TABLE: CLIENT_MASTER
ADDRESS VARCHAR2(30),
CITY VARCHAR2(15),
PINCODE NUMBER(8),
STATE VARCHAR2(15),
BALDUE NUMBER(10,2) );
STRUCTURE
ADDRESS1 VARCHAR2(30)
CITY VARCHAR2(15)
PINCODE NUMBER(8)
STATE VARCHAR2(15)
BALDUE NUMBER(10,2)
• This can be accomplished through a combination of the table name, Primary Key, and
column name.
• EXAMPLE:
Emp_info Emp_Salary_info
91 John 91 20000
92 Thomas 92 40000
• This involves the support of a null value, which is distinct from an empty string or
number with a value of zero.
• Of course, this can’t apply to primary key. In addition, most database implementations
support the concept of a not- null field constraint that prevents null values in a specific
table column.
• EXAMPLE:
• EXAMPLE:
• The Relational database must support at least one clearly defined language
that includes functionality for data definition, data manipulation, data
integrity and database transaction control.
1. Data Definition
2. View Definition
3. Data Manipulation
4. Integrate Constraints
5. Authorization
6. Transaction Control
• Each view should support the same full range of data manipulation that has
direct access to a table available.
• This rule states that insert, update, and delete operations should be supported
for any retrievable set rather than just for a single row in a single table.
EXAMPLE:
• The user is isolated from the physical method of storing and retrieving
information from the database.
• How data is viewed should not be changed when the logical structure
(table’s structure) of the database changes.
• Most databases rely on strong ties between the data viewed and the actual
structure of the underlying tables.
EXAMPLE:
In this rule we want to retrieve any ID, when we retrieve Data without ID that
time we can not satisfy this rule.
• The database language (like SQL) should support constraints on user input
that maintain database integrity.
– 1. Primary Key column can not have NULL & Must be UNIQUE.
EXAMPLE:
The database can be located at the user server or at any other network. The
end user should not be able to know about the database servers. He should be able
to get the records as if he is pulling the records locally. Even if the database is
located in different servers, the accessibility time should be comparatively less.
• There should be no way to modify the database structure other than through
the multiple row database language (like SQL).
• Most databases today support administrative tools that allow some direct
manipulation of the data structure.
EXAMPLE:
If a relational system supports a low level (Single record at a time) language
that low level language can not be used to sub word or by pass the integrity rules or
constraints expressed in the higher level (multiple record at a time) relational
language.
Relational Algebra
Relational Algebra is procedural query language, which takes Relation as input and generate
relation as output. Relational algebra mainly provides theoretical foundation for relational
databases and SQL. It uses operators to perform queries.
Projection (π)(PI)
The projection eliminates all attributes of the input relation but those mentioned in the
projection list.
The projection method defines a relation that contains a vertical subset of Relation.
This helps to extract the values of specified attributes to eliminate duplicate values.
(pi) symbol is used to choose attributes from a relation.
This operator helps you to keep specific columns from a relation and discards the other
columns.
Example :
R
(A B C)
----------
1 2 4
2 2 3
3 2 3
4 3 4
π (BC)
Output
B C
-----
2 4
2 3
3 4
1 Google Active
2 Amazon Active
3 Apple Inactive
4 Alibaba Active
5 Amazon Active
CustomerName Status
Google Active
Amazon Active
Apple Inactive
Alibaba Active
SELECT (σ)
The SELECT operation is used for selecting a subset of the tuples according to a given
selection condition.
Sigma(σ)Symbol denotes it.
It is used as an expression to choose tuples which meet the selection condition.
Select operator selects tuples that satisfy a given predicate.
σp(r)
σ is the predicate
p is prepositional logic
σ(c>3)R
will select the tuples which have c more than 3.
Note: selection operator only selects the required tuples but does not display them. For
displaying, data projection operator is used.
For the above selected tuples, to display we need to use projection also.
π (σ (c>3)R ) will show following tuples.
A B C
-------
1 2 4
4 3 4
Example 1
σ Status=”Active” (Customers)
Example 2
Output – Selects tuples from Customers where CustomerName is ”Amazon” and Status is
‘Active’.
Example 3
σ CustomerId>3(Customers)
Output – Selects tuples from Customers where CustomerId is greater than 3.
Rename (ρ)(Rho)
Rename is a unary operation used for renaming attributes of a relation.
ρ (a/b)R will rename the attribute ‘b’ of relation by ‘a’.
Example
Table A Table B
1 1 1 1
1 2 1 3
A ∪ B gives
Table A ∪ B
column 1 column 2
1 1
1 2
1 3
Intersection
An intersection is defined by the symbol ∩
A∩B
Defines a relation consisting of a set of all tuple that are in both A and B. However, A and B
must be union-compatible.
Visual Definition
of Intersection
Example:
A∩B
Table A ∩ B
column 1 column 2
1 1
Example
A-B
Table A – B
column 1 column 2
1 2
1. Connecting to Oracle
2. Disconnecting from Oracle
3. Committing changes to the database table
4. Rollback
Closing Transactions
Using COMMIT
A COMMIT ends the current transaction and makes permanent any changes made
during the transaction. All transaction locks acquired on tables are released.
Syntax:
COMMIT;
Using ROLLBACK
A ROLLBACK does exactly the opposite of COMMIT. It ends the transaction but
undoes any changes made during the transaction. All transaction locks acquired on tables
are released.
Syntax:
Creating a Savepoint
Savepoint marks and saves the current point in the processing of a transaction.
Syntax:
SAVEPOINT savepoint_name;
Exercise:
Product_master
Bal_stock Number 3
Product_requisite
Qty Number 3
Update the Bal_stock in the Product_master table for each requisite in the Product_requisite table.
Based on the prod_id, decrease the Bal_stock in the Product_master table by the quantity
in the Product_requisite table. The updation is completed only when the corresponding
record in the Product_requisite table is deleted.
1. If at any given point, the value in Bal_stock becomes negative, the entire update
operation for all prod_id should be rollback.
2. If at any given point, the value in Bal_stock becomes negative, the update
operation for that particular prod_id should rollback.
1.4 Data Control language
1.4 Data Control language
Grant
Objects that are created by the user are owned and controlled by that user.
• If a user wishes to access any of the objects belonging to another user, the owner of the object
will have to give permission to access to that user.
• Oracle allows to give all privileges of object. Privileges means some operations to be perform
on the object.
Privileges are:
1. Insert - Allow the Grantee to add records to the table with the INSERT command.
2. Update - Allow the Grantee to modify records to the table with the UPDATE command.
3. Delete- Allow the Grantee to remove records to the table with the DELETE command.
4. Select- Allow the Grantee to display records to the table with the SELECT command.
5. Index- Allow the Grantee to create an index on the table with the CREATE INDEX command.
6. Alter- Allow the Grantee to change the table definition with the ALTER TABLE command.
Syntax:
With Grant Option allows the grantee to in turn grant object privileges to other user.
Example:
In this example Smith get all the data manipulation permissions on the table SYBCA.
Syntax:
Example:
In this example Smith get permissions only for display, remove and stored new data in the table
SYBCA.
Example:
Give the user Harsh all data manipulation privileges on the table SYBCA along with the option
to further grant permission on the SYBCA table to other users.(Owner is Harshil).
In against Harsh can give permission to other user to access SYBCA table.
For Example:
Here Megh get the permission of all privileges on harshil’s table SYBCA by Harsh.
To access Table belonging to another user.
Syntax:
Ownername.Objectname
To Insert record:
REVOKE
• Privileges once given can be denied to a user using the REVOKE command.
• A user of an object who is not the owner, but has been granted the GRANT privilege, has a
power to REVOKE the privileges from a grantee.
SYNTAX:
REVOKE
OBJECT PRIVILEGES
ON OBJECTNAME
FROM USERNAME;
Example:
REVOKE
ALL
ON SYBCA
FROM SMITH;