Exp 5 and 9
Exp 5 and 9
5.Normalization
Sales
Primary key: ( Prod_Id,Sup_Id)
But the above table is not in 2NF because there is a partial dependency
Sales:
Product:
Prod_Id Prod_name
Sup_Id Sup_Name
Product and Supplier tables are in 3NF but Sales table is not in 3NF because there is a transitive
dependency
Sales:
Cust_nam
Prod_Id Sup_Id Price Cust_Id Date
e
Cust_Id->Cust_name
that is a non key attribute determines an attribute value that non key attribute Cust_nmae
transitively dependent on primary key, this is not allowed in 3NF.
Sales:
Customer:
Cust_Id Cust_name
Product:
Prod_Id Prod_name
Supplier:
Sup_Id Sup_Name
Experiment:
9.Procedures
Procedure (Stored Procedure)
DELIMITER &&
BEGIN
Declaration_section
Executable_section
END &&
DELIMITER ;
Parameter Explanations
The procedure syntax has the following parameters:
INOUT parameters
It is a combination of IN and OUT parameters. It means the calling program can pass the
argument, and the procedure can modify the INOUT parameter, and then passes the new value
back to the calling program.
Syntax:
Example on procedures:
create the following table and insert data
Code:
DELIMITER &&
BEGIN
END &&
DELIMITER ;
Execution:
CALL get_merit_student();
Output:
Program on Procedures with IN Parameter
2. Create a procedure to to display n number of records
In this procedure, we have used the IN parameter as 'var1' of integer type to accept a number from
users.
Its body part fetches the records from the table using a SELECT statement and returns only those
rows that will be supplied by the user.
It also returns the total number of rows of the specified table. See the procedure code:
DELIMITER &&
BEGIN
END &&
DELIMITER ;
Execution:
CALL get_student(4);
output:
Program on Procedures with OUT Parameter
3.Create a procedure to find the highest marks
In this procedure, we have used the OUT parameter as the 'highestmark' of integer type. Its body
part fetches the maximum marks from the table using a MAX() function. See the procedure code:
DELIMITER &&
BEGIN
END &&
DELIMITER ;
Execution:
CALL display_max_mark(@M);
SELECT @M;
output: