Professional Documents
Culture Documents
THEORY :-
4. Derived Attribute :- Derived attributes are the attributes that do not exist in the
physical database, but their values are derived from other attributes present in
the database.
7. Single Attribute :- An attribute that has only single value for an entity is known as
single valued attribute.
Problem Statement:-
Construct an ER diagram for a Resume Builder application.which has number of
users where the user can login and create their Resume.The Resume contains user
details which includes qualifications, experience, skills , etc
ER diagram :-
CONCLUSION :- THUS , WE HAVE STUDY ABOUT ALL TYPE OF ATTRIBUTE & HOW
TO DRAW ER diagram
Experiment NO 2
Theory :-
A male marries 0 or 1 female and vice versa as well. So it is 1:1 cardinality with
partial participation constraint from both. First Convert each entity and relationship
to tables. Male table corresponds to Male Entity with key as M-Id. Similarly Female
table corresponds to Female Entity with key as F-Id. Marry Table represents
relationship between Male and Female (Which Male marries which female). So it
will take attribute M-Id from Male and F-Id from Female.
Case 3: Binary Relationship with n: 1 cardinality
In this scenario, every student can enroll only in one elective course but for an
elective course there can be more than one student. First Convert each entity and
relationship to tables. Student table corresponds to Student Entity with key as S-Id.
Similarly Elective_Course table corresponds to Elective_Course Entity with key as
E-Id. Enrolls Table represents relationship between Student and Elective_Course
(Which student enrolls in which course). So it will take attribute S-Id from and
Student E-Id from Elective_Course.
Case 4: Binary Relationship with m: n cardinality
In this scenario, every student can enroll in more than 1 compulsory course and for
a compulsory course there can be more than 1 student. First Convert each entity
and relationship to tables. Student table corresponds to Student Entity with key as
S-Id. Similarly Compulsory_Courses table corresponds to Compulsory Courses
Entity with key as C-Id. Enrolls Table represents relationship between Student and
Compulsory_Courses (Which student enrolls in which course). So it will take
attribute S-Id from Person and C-Id from Compulsory_Courses.
Case 5: Binary Relationship with weak entity
In this scenario, an employee can have many dependants and one dependant can
depend on one employee. A dependant does not have any existence without an
employee (e.g; you as a child can be dependant of your father in his company). So
it will be a weak entity and its participation will always be total. Weak Entity does
not have key of its own. So its key will be combination of key of its identifying entity
(E-Id of Employee in this case) and its partial key (D-Name).
First Convert each entity and relationship to tables. Employee table corresponds to
Employee Entity with key as E-Id. Similarly Dependants table corresponds to
Dependant Entity with key as D-Name and E-Id. Has Table represents relationship
between Employee and Dependants (Which employee has which dependants). So
it will take attribute E-Id from Employee and D-Name from Dependants.
TABLES :-
User Table
Username Image Mobile No
user_Id
Username is primary
Login Table
ID Username Password
Resume Table
User R_Type R_name
Detail Table
ID_No Name Mobile No Certificate
Experience Table
No of year Job Type Company Name Last Company
Character Certificate
Skill Table
Specialization Skill Name
Skill_type
Primary key
Foreign Key
CONCLUSION :- THUS , WE STUDY TO CREATE Map ER Model to Relational
Schema Model IN THIS EXPERIMENT.
Experiment No :-3
Aim:- Performing DDL command.
Solution :-
1) Create Command:-
1) Theory :- This command is to create the table in the database.so as
to store the value in receptive table.
2) Syntax :- CREATE TABLE Registration
(ID int,
Name varchar(255),
Username varchar(255),
Password varchar(255)
);
3) Example:-
2) Rename Command:-
1) Theory:- This command is use to rename any name
that has to change.
2) Syntax:- ALTER TABLE Registration
CHANGE COLUMN Password TO PWD INT;
3) Example:-
a) Before execution
b) After execution
3) Truncate Command :-
1) Theory:- The TRUNCATE TABLE command deletes the data inside a table,
but not the table itself.
b) After execution:-
TRUNCATE TABLE Registration;
4) Alter Command:-
1) Theory:- ALTER TABLE statement is used to add, delete, or modify
columns in an existing table.The ALTER TABLE statement is also used to add and
drop various constraints on an existing table.
2) Syntax:-
1) Adding Column
ALTER TABLE Registration ADD phone_no varchar(255);
2) Drop column :-
1) ALTER TABLE Registration DROP COLUMN phone_no;
3) MODIFY COLUMN:-
1) ALTER TABLE Registration ALTER COLUMN PWD bigint(255);
5) Drop Table:-
1) Theory :- The DROP TABLE statement is used to drop an
existing table in a database.
2) UPDATE:-
UPDATE login SET name = 'dhruv sheth' Where name = 'Dhruv Sheth'
BEFORE AFTER
3) DELETE:-
DELETE FROM login WHERE (id = '4' or id = '7')
BEFORE AFTER
4) Delete All :
SYNTAX :-
• Select * FROM <tableName>;
• SELECT * <column1, column2,....,column n> FROM <table_name>;
• SELECT * FROM <tableName> WHERE <condition>;
• SELECT * FROM <tableName> WHERE <condition1> [AND|OR]
<condition2>;
OUTPUT :-
1. SELECT dname , age FROM login WHERE ID = 1 or city = 4;
Before After
2. SELECT * FROM ‘login’ WHERE name like ‘d%’;
Before After
3. SELECT * FROM ‘login’ WHERE name LIKE ‘H%’ AND username like
'_C%’;
Before After
Before After
5. Aggregate Function : In Database management system an
aggregate function is a function where the values of multiple rows are
grouped together as input on certain criteria to form a single value of
more significant meaning.
Before After
Before After
c) Avg () : Average is use to calculate average value of the specified
column from the records of the table.
Syntax : SELECT avg(ID) from login;
Before After
Before After
Before After
3. Group By Clause :-
The Group By Clause is often use to arrange the identical duplicate
data into groups with the select statement.
Syntax : -
SELECT name , SUM(Id) FROM login GROUP BY name
Before After
4. Distinct Clause : -
The Distinct Clause is used to filter unique records out of the duplicate
records that satisfy the query criteria.
Syntax :-
SELECT DISTINCT(name) , ID from login
Before After
2. > : The operator > selects the rows which values are greater than the given
value.
CODE:
SELECT `ID`, `fname`, `mname`, `lname`,`mno`,`username`,`age`,`gender`,`pwd`
FROM reg WHERE age>20
OUTPUT:
After Execution
3. = : This operator selects the rows whose values are equals to the given
value.
CODE:
SELECT `ID`, `fname`, `mname`, `lname`,`mno`,`username`,`age`,`gender`,`pwd`
FROM reg WHERE age=20
OUTPUT:
After Execution
4. >= : the operator >= is used to select the data which are equal or greater
than given value.
CODE:
SELECT `ID`, `fname`, `mname`, `lname`,`mno`,`username`,`age`,`gender`,`pwd`
FROM reg WHERE age>=20
OUTPUT:
After Execution
5. <= : the operator <= selects the rows which have the values equals or less
than equal to the given value.
CODE:
SELECT `ID`, `fname`, `mname`, `lname`,`mno`,`username`,`age`,`gender`,`pwd`
FROM reg WHERE age<=20
OUTPUT:
After Execution
6. IN Operator : IN operator associated with the condition and it selects the
rows which satisfies the condition.
CODE:
SELECT * Form ‘reg’ WHERE ID IN(SELECT ID FROM reg WHERE age<25);
OUTPUT:
After Execution
7. Between Operator :
SELECT `ID`, `fname`,`username`, `age`, `pwd` FROM reg WHERE age BETWEEN 18
AND 25;
OUTPUT:
After Execution
CONCLUSION: Thus we learnt and successfully performed nested and complex
query in sql.
Experiment No : 8
Aim: To perform various join operation like inner join, right join, left join, full
outer join.
Theory:
A JOIN clause is used to combine rows from two or more tables, basaed on a
related column between them.
Different types of SQL JOINs
• Inner join
• Left join
• Right join
• Full Outer join
Here are the different types of the JOINs in SQL:
Registration table:-
Login table:-
1. Inner JOIN: Returns records that have matching values in both tables
Syntax:
Select table1.column,table2.column...From table1 INNER JOIN table2 ON
condition.
CODE:
SELECT reg.ID,login.id,login.fname FROM login INNER JOIN reg ON login.id = reg.ID
Output:-
LEFT (OUTER) JOIN: Returns all records from the left table, and the matched
records from the right table
Syntax:-
Select table1.column,table2.column... From table1 LEFT JOIN table2 ON condition.
CODE:
SELECT login.id,reg.ID,reg.fname FROM login LEFT JOIN reg ON reg.ID = login.id
Output:-
RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched
records from the lefttable
Syntax:-
Select table1.column,table2.column... From table1 RIGHT JOIN table2 ON
condition.
CODE:
SELECT reg.ID,login.id,reg.fname FROM reg RIGHT JOIN login ON reg.ID = login.id
Output:-
FULL (OUTER) JOIN: Returns all records when there is a match in either left or
right table FULL OUTER JOIN
Syntax:-
Syntax for mysql:-
Select table1.column,table2.column... From table1 LEFT JOIN table2 ON condition.
UNION Select table1.column,table2.column... From table1 RIGHT JOIN table2 ON
condition.
Syntax for sql:-
Select table1.column,table2.column... From table1 FULL JOIN table2 ON
condition.
CODE:
SELECT login.id,reg.ID,login.fname FROM login FULL JOIN reg ON reg.ID = login.id
Output:-
id ID fname
1 1 dhruv
2 null Dhruv
3 3 chaitali
4 4 xyz
• Structure data in a way that users or classes of users find natural or intuitive.
• Restrict access to the data in such a way that a user can see and (sometimes) modify
exactly what they need and no more.
• Summarize data from various tables which can be used to generate reports.
For example, we will be using the student_details table to demonstrate and perform various
VIEW operations on it.
Sample Table
1. Creating Views : A view can be created using the CREATE VIEW statement.
Syntax:
Before Execution:
After Execution:
2. CREATE OR REPLACE VIEW: We can use this to create or replace view statement to
add or remove fields from a view.
CREATE OR REPLACE VIEW view_name AS
SELECT column1, column2.....
FROM table_name
WHERE condition;
Before Execution:
After Execution:
CONCLUSION: In this experiment we have studied and implemented VIEWS using SQL.
Experiment No : 10
Components of Triggers
BEFORE triggers run the trigger action before the triggering statement
is run. AFTER triggers run the trigger action after the triggering
statement is run.
Syntax:
create trigger [trigger_name]
[before | after]
{insert | update |
delete} on
[table_name]
[trigger_body]
Created a database called “triggers”.
Creating table for customers:
CREATE TABLE
customer_details (
AUTO_INCREMENT,
CNAME VARCHAR(20),
AGE INT(11),
CITY VARCHAR(30),
GENDER VARCHAR(20),
PRIMARY KEY(CID)
);
Query:
INSERT INTO `customer_details` (`CID`, `CNAME`, `AGE`, `CITY`,
`GENDER `) VALUES (1, 'RAM', 40, 'Mumbai', 'Male');
After operation
To use this variant we need one more table i.e, Percentage where the
trigger will store the results. Use the below code to create the
Percentage Table.
create table Final_age(per int );
Query:
CREATE TRIGGER
values(new.age);
Query:
INSERT INTO `customer_details` (`CID`, `CNAME`, `AGE`, `CITY`,
`GENDER`) VALUES (4, 'Mohan', 35, 'Pune', 'Male');
Explanation: Here when we insert data to the table, total_age trigger will store
the result in the Final_age table.