DBMS
DBMS
Ram 01 Vivek 13
Mohan 02 Geeta 17
Vivek 13 Shyam 21
Geeta 17 Rohan 25
Student_Name
π(Student_Name)FRENCH U π(Student_Name)GERMAN Ram
Mohan
Vivek
Geeta
Shyam
Rohan
• 6. Rename(ρ): Rename is a unary operation
used for renaming attributes of a relation.
• ρ(a/b)R will rename the attribute 'b' of the
relation by 'a'.
• 7. Cross Product(X): Cross-product between
two relations. Let’s say A and B, so the cross
product between A X B will result in all the
attributes of A followed by each attribute of B.
Each record of A will pair with every record of
B.
• A B
Name Age Sex ID Course
Ram 14 M
1 DS
Sona 15 F
2 DBMS
Kim 20 M
Ram 14 M 1 DS
Ram 14 M 2 DBMS
Sona 15 F 1 DS
Sona 15 F 2 DBMS
Kim 20 M 1 DS
Kim 20 M 2 DBMS
Types of Join operations
1. Natural Join
2. Outer Join
3. Equi Join
A natural join is the set of tuples of all
combinations in R and S that are equal on their
common attribute names. It is denoted by ⋈.
The outer join operation is an extension of the join
operation. It is used to deal with missing information.
Left outer join:
• Left outer join contains the set of tuples of all
combinations in R and S that are equal on their
common attribute names.
• In the left outer join, tuples in R have no
matching tuples in S.
• It is denoted by ⟕.
• Example: Using the above EMPLOYEE table and
FACT_WORKERS table
• EMPLOYEE ⟕ FACT_WORKERS
EMPLOYEE ⟖ FACT_WORKERS
• 3. Equi join:
• It is also known as an inner join. It is the most
common join. It is based on matched data as
per the equality condition. The equi join uses
the comparison operator(=).
Data Definition Language
• Create: Syntax: CREATE table table_name
(
Column1 datatype (size),
column2 datatype (size),
columnN datatype(size)
);
Here table_name is name of the table, column is the name of
column
• CREATE TABLE Customer( CustomerID INT
PRIMARY KEY, CustomerName VARCHAR(50),
LastName VARCHAR(50), Country
VARCHAR(50), Age int(2), Phone int(10) );
Output:
•
Insert Data into Table
• Insert into Table_name(Column1, Column2,
Column3)
Values (Value1, value2, value3);
• Example: INSERT INTO Customer (CustomerID,
CustomerName, LastName, Country, Age, Phone)
VALUES (1, 'Shubham', 'Thakur', 'India','23','xxxxxxxxxx'),
(2, 'Aman ', 'Chopra', 'Australia','21','xxxxxxxxxx'), (3,
'Naveen', 'Tulasi', 'Sri lanka','24','xxxxxxxxxx'), (4,
'Aditya', 'Arpan', 'Austria','21','xxxxxxxxxx'), (5, 'Nishant.
Salchichas S.A.', 'Jain', 'Spain','22','xxxxxxxxxx');
• DROP is used to delete a table.
• DROP TABLE table_name;
• TRUNCATE statement is a Data Definition
Language (DDL) operation that is used to mark
the extent of a table for deallocation (empty
for reuse). The result of this operation quickly
removes all data from a table.
• TRUNCATE TABLE table_name;
Alter command:
• ADD is used to add columns to the existing
table.
• ALTER TABLE table_name ADD
(Columnname_1 datatype, Columnname_2
datatype, …Columnname_n datatype);
• Example:
• Alter table customer add email varchar(255);
• DROP COLUMN is used to drop columns in a
table. Deleting the unwanted columns from
the table.
• Syntax: ALTER TABLE table_name
DROP COLUMN column_name;
• Properties
• A relation R is in 5NF if and only if it satisfies
the following conditions:
• 1. R should be already in 4NF.
2. It cannot be further non loss decomposed
(join dependency).
Transaction Management