DBMS Final
DBMS Final
Composite attribute:
• Made up of more than one simple attribute.
• For example, student's address will contain, house no., street
name, pincode etc.
Derived attribute:
• Derived using other attributes.
• For example, average age of students in a class.
Attributes:
Single-valued attribute:
• They have a single value.
Multi-valued attribute:
• They can have multiple values.
Relation Database
• Collects different types of data sets
• Use tables, records, and columns.
• It is used to create a well-defined relationship
between database tables
• Relational databases can be easily stored.
• For example of relational databases such as
Microsoft SQL Server, Oracle Database,
MYSQL, etc
• A table has records (rows) and fields
(columns).
• Degree refers to the number of different
attributes or columns in a table
• Cardinality is used to count the total number
of tuples or rows in a table.
Different Types of Keys
• Primary Key
• Candidate Key
• Super Key
• Alternate Key
• Foreign Key
• Composite Key
+
Composite Key:
• Defined as combination of multiple columns
• These columns are used to identify all the
rows that are involved uniquely.
• Even though a single column can't identify
any row uniquely
• a combination of over one column can
uniquely identify any record.
Foreign key
• Is a column or columns of data in one table
that refers to the unique data values –
• often the primary key data -- in another table.
• Foreign keys link together two or more tables
in a relational database.
Relational Integrity Rules
Entity Integrity Rule:
• value of attribute of a primary key cannot be
null.
Referential Integrity Rule
• foreign key have a matching primary key.
• Reference from a table to another table
should be valid.
Relational Algebra and Calculus
Relational Algebra:
• It is a procedural language.
• The order is specified in which the operations
have to be performed.
• The basic operation included in relational
algebra are:
• 1. Select (σ) 2. Project (Π) 3. Union (U) 4. Set
Difference (-) 5. Cartesian product (X) 6.
Rename (ρ)
1. Selection(σ): It is used to select required tuples of
the relations.
3. Union(U): Union operation in relational algebra is
the same as union operation in set theory. Let there
are two tables: FRENCH and German
Student_Name Roll_Number Student_Name Roll_Number
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
Natural Join
• It joins two tables based on the same attribute
name and dataypes.
• The resulting table will contain all the attributes
of both tables
• But keep only one copy of each common column.
Syntax
SELECT * FROM table1 NATURAL JOIN table2;
SELECT *
FROM Student NATURAL JOIN Student_Marks;
1
1
1
Inner Join or Equi join
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