Professional Documents
Culture Documents
Database System
Database System
Database System
CS
Database System Practical
Practical No:01
Course table:
CourseNo CourseName NumberOfCredit
201 FOSS 2
201 Database Systems 2
203 Green Technology 2
Same as above for remaining entities student Hostel and faculty
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Practical No:02
Selection: (σ)
It selects tuples that satisfy the given predicate/condition from a relation.
Notation – σp (r)
Where σ stands for selection predicate, r stands for relation/table and p stands for predicate/condition.
For example −
σsubject = "database"(Books)
Output − Selects tuples from books table where subject is 'database'.
Projection: (∏)
It projects column(s) that satisfy a given predicate.
Notation − ∏A1, A2, An (r)
Where A1, A2, An are attribute names of relation/table r.
Duplicate rows are automatically eliminated, as relation is a set.
For example −
∏subject,author (Books)
Output - Selects and projects columns named as subject and author from the relation Books.
Set Operations:
1. Union: (∪)
It performs binary union between two given relations/tables and is defined as −
r ∪ s = { t | t ∈ r or t ∈ s}
Notation − r U s
Where r and s are database relations/tables.
For a union operation to be valid, the following conditions must hold −
r, and s must have the same number of attributes.
Attribute domains must be compatible.
Duplicate tuples are automatically eliminated.
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
For example-
2. Intersection: (⋂)
It performs binary intersection between two given relations/tables and is defined as −
r ⋂ s = { t | t ∈ r and t ∈ s}
Notation – r ⋂ s
Where r and s are database relations/tables.
For a Intersection operation to be valid, the following conditions must hold −
r, and s must have the same number of attributes.
Attribute domains must be compatible.
Duplicate tuples are automatically eliminated.
For example-
σauthor=’abc’(Books Χ Articles)
Output − Yields a relation, which shows all the books and articles written by abc.
Join:
combinations of the Cartesian product which satisfy certain situations and so you can normally use a Join
operation instead of the Cartesian product operation.
There are various types of Join operation, each with subtle differences some more useful than others:
1. Conditional join
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Conditional join works similar to natural join. In natural join, by default condition is equal between
common attribute while in conditional join we can specify the any condition such as greater than, less
than, not equal etc.
For example:
Table-R Table-S
2. Equijoin
Equijoin combines tuples from different relations provided they satisfy the theta condition. The join
condition is denoted by the symbol c.
Notation - R1 ⋈c R2, R1 and R2 are relations having attributes (A1, A2,.., An) and (B1, B2,.. ,Bn) such
that the attributes don’t have anything in common, that is R1 ∩ R2 = Φ(NULL/EMPTY).
For example:
Student Subjects
11 Music
11 Sports
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Output:
Student_detail
3. Natural join:
Natural join does not use any comparison operator. It does not concatenate the way a Cartesian product
does. We can perform a Natural Join only if there is at least one common attribute that exists between
two relations. In addition, the attributes must have the same name and domain.
Natural join acts on those matching attributes where the values of attributes in both the relations are
same.
Courses HoD
CS01 Database CS
CS Alex
ME01 Mechanics ME
ME Maya
EE01 Electronics EE
EE Mira
Courses ⋈ HoD
Output:
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Division:
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Practical No:03
2. Creating a Database:
3. Creating Tables:
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Practical No:04
Altering a Table:
Truncating table:
Renaming Tables:
Dropping table:
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Practical No:05
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Practical No:06
Queries involving:
1. Date Functions:
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
2. String Functions:
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
3. Math Functions:
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Practical No:07
Join Queries:
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Inner Join:
Outer Join:
1. Left Join
2. Right Join:
3. Full Join:
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Practical No:08
Subqueries:
With IN clause:
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Practical No:09
Views
Creating Views:
Dropping views:
Ms. R. B. Gaikwad
F.Y.CS
Database System Practical
Practical No:10
DCL statements
Ms. R. B. Gaikwad