Rdbms
Rdbms
NO:
Result:
Thus, the creation of a database and sql queries to retrieve information from the
university registrar’s office database was implemented and verified
successfully.
EXP NO:
Aim :
To illustrate the working of stored procedure , functions and triggers
DELIMITER \
BEGIN
Declaration_section
Executable_section
END \
DELIMITER;
CALL procedure_name(parameter(s))
Query
DELIMITER \
CREATE PROCEDURE get_merit_student ()
BEGIN
SELECT * FROM student_info WHERE marks > 70;
SELECT COUNT(stud_code) AS Total_Student FROM student_info;
END \
DELIMITER;
CALL get_merit_student();
Background Knowledge of Functions:
CREATE FUNCTION function_name [ (parameter datatype [, parameter dataty
pe]) ]
RETURNS return_datatype
BEGIN
Declaration_section
Executable_section
END;
Query
DELIMITER \
BEGIN
DECLARE c INT;
SET c=(a+b);
RETURN c;
END\
DELIMITER;
Select AddTwoNos(3,4);
The data modification event include insert, update, delete driven by an INSERT,
DELETE, UPDATE, and MERGE statement.
Triggers are stored in the database at once. There are 2 types of triggers-
Syntax of Triggers
(AFTER|BEFORE) (INSERT|UPDAATE|DELETE)
BEGIN
--variable declarations
--trigger code
END;
Query
CREATE TRIGGER t1
BEFORE INSERT
SET new.total=new.qtysold*new.price;
End\
DELIMITER;
Result:
Thus, the stored procedure, function and triggers was successfully executed and
verified.
EXP.NO:
Write a query for given table,
a) Find common city
b) Join two tables
Aim:
To write a query for given tables using UNION and INTERSECT.
Solution:
Syntax for UNION:
SELECT column_list FROM table1
UNION
SELECT column_list FROM table2;
Query:
Result
Thus, the UNION and INTERSECT operator was executed from given table
and verified.
EXP.NO.
Read data using SELECT statement
The table shown below shows data in movierentals table
we want to get the number of times that the movie with id 2 has been rented out
and omit the duplicates id’s, we want to know the year in which the oldest
movie in our library was released, we want to get the year that the latest movie
in our database was released, we want total number of memberships, we want
to find the average of membership_number, I want to sort movierentals by
membership_number in descending order
Aim:
To perform various Aggregate function and clauses using SELECT statement
for given scenario.
Syntax:
1.Count
SELECT COUNT(Field_name) FROM table_name where conditions;
2.Distinct
SELECT DISTINCT (Field_name) FROM table_name;
3.MIN
SELECT MIN (Field_name) FROM table_name;
4.MAX
SELECT MAX(Field_name) FROM table_name;
5.SUM
SELECT SUM(Field_name) FROM table_name;
6.AVG
SELECT AVG(Field_name) FROM table_name;
7.ORDER BY
SELECT Field_list FROM table_name where conditions ORDER BY
expression[ASC|DESC]
8.GROUP BY
SELECT Field_list aggregate_function (Field_name) FROM table_name where
conditions GROUP BY Field_list
Solution
Query
SELECT COUNT (movie_id) FROM movierentals WHERE movie_id = 2;
SELECT DISTINCT movie_id FROM movierentals;
SELECT MIN (year_released) FROM movies;
SELECT MAX (year_released) FROM movies;
SELECT SUM (membership_number) FROM movierentals;
SELECT AVG (membership_number) FROM movierentals;
SELECT reference_number, membership_number FROM movierentals ORDER BY
membership_number DESC;
SELECT movie_id, COUNT (movie_id) FROM movierentals GROUP BY movie_id;
Result:
Thus, the aggregate functions and clauses was executed from given scenario and
implemented.
Exp.NO
Query Multiple tables with join statements
Solution:
Syntax for Simple join:
SELECT columns FROM table1 INNER JOIN table2 ON table1.column = table2.column;