Dbe 2-10
Dbe 2-10
Dbe 2-10
Create Database:
CREATE DATABASE EMPLOYEEDB
Use Database:
USE EMPLOYEEDB
Create Table:
1. WORK_DEPARTMENT
CREATE TABLE WORK_DEPARTMENT(
W_ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
SALARY_RANGE INT,
PRIMARY KEY (W_ID)
);
2. EMPLOYEE
CREATE TABLE EMPLOYEE(
E_ID INT NOT NULL,
FNAME VARCHAR(255) NOT NULL,
LNAME VARCHAR(255),
GENDER VARCHAR(255),
AGE INT,
ADDRESS VARCHAR(255),
EMAIL VARCHAR(255),
BASIC_SALARY INT NOT NULL,
W_ID INT NOT NULL,
PRIMARY KEY (E_ID) ,
FOREIGN KEY (W_ID) REFERENCES WORK_DEPARTMENT(W_ID)
);
Experiment No. 2 Create and Alter Tables
3. LEAVETBL
CREATE TABLE LEAVETBL(
L_ID INT NOT NULL,
LEAVE_DAYS INT NOT NULL,
L_DATE DATE NOT NULL,
E_ID INT NOT NULL,
PRIMARY KEY (L_ID),
FOREIGN KEY (E_ID) REFERENCES EMPLOYEE(E_ID)
);
4. ALLOWANCE:
CREATE TABLE ALLOWANCE(
A_ID varchar(20) NOT NULL,
A_NAME varchar(250) NOT NULL,
A_VALUE INT,
PRIMARY KEY (A_ID));
5. DEDUCTION:
CREATE TABLE DEDUCTION(
D_ID varchar(20) NOT NULL,
D_NAME varchar(250) NOT NULL,
D_VALUE INT,
PRIMARY KEY (D_ID));
6. Payroll:
CREATE TABLE PAYROLL(
E_ID INT NOT NULL,
L_ID INT,
A_ID varchar(20),
D_ID varchar(20),
FOREIGN KEY (E_ID) REFERENCES EMPLOYEE(E_ID),
FOREIGN KEY (L_ID) REFERENCES LEAVETBL(L_ID),
FOREIGN KEY (A_ID) REFERENCES ALLOWANCE(A_ID),
FOREIGN KEY (D_ID) REFERENCES DEDUCTION(D_ID)
);
Experiment No. 2 Create and Alter Tables
Alter Table:
1. Add Column:
ALTER TABLE PAYROLL ADD COLUMN DATE DATE NOT NULL, ADD
COLUMN YEAR VARCHAR(10)
3. Modify Datatype
ALTER TABLE PAYROLL MODIFY COLUMN YEARS INT;
4. Drop Column
ALTER TABLE PAYROLL DROP COLUMN YEARS;
Experiment No. 3 Insert And Update Query
INSERT VALUES
1. WORK_DEPARTMENT
INSERT INTO WORK_DEPARTMENT VALUES(1,'MANAGER',30000);
INSERT INTO WORK_DEPARTMENT VALUES(2,'ANALYST',25000);
2. EMPLOYEE
INSERT INTO EMPLOYEE
VALUES(1,'UMESH','DUKKURWANDKAR','MALE',21,'KOLHAPUR','UMESH@GMAIL.COM',3
0000,1);
3. LEAVETBL
INSERT INTO LEAVETBL VALUE(1,5,DATE '2022-09-02',1);
INSERT INTO LEAVETBL VALUE(2,2,DATE '2022-09-02',2);
4. ALLOWANCE
INSERT INTO ALLOWANCE VALUE("A1","HRA",10);
INSERT INTO ALLOWANCE VALUE("A2","DA",5);
INSERT INTO ALLOWANCE VALUE("A3","TA",7);
5. DEDUCTION
INSERT INTO DEDUCTION VALUE("D1","IT",10);
INSERT INTO DEDUCTION VALUE("D2","PF",12);
INSERT INTO DEDUCTION VALUE("D3","PT",3);
Experiment No. 3 Insert And Update Query
6. PAYROLL
INSERT INTO
PAYROLL(E_ID,L_ID,A_ID,D_ID,DATE) VALUE(1,1,'A1','D1',DATE '2022-09-02');
INSERT INTO
PAYROLL(E_ID,L_ID,A_ID,D_ID,DATE) VALUE(1,1,'A2','D2',DATE '2022-09-02');
INSERT INTO
PAYROLL(E_ID,L_ID,A_ID,D_ID,DATE) VALUE(1,1,'A3','D3',DATE '2022-09-02');\
INSERT INTO
PAYROLL(E_ID,L_ID,A_ID,D_ID,DATE) VALUE(2,2,'A1','D1',DATE '2022-09-02');
INSERT INTO
PAYROLL(E_ID,L_ID,A_ID,D_ID,DATE) VALUE(2,2,'A2','D3',DATE '2022-09-02');
UPDATE VALUES
1. UPDATE LEAVETBL SET LEAVE_DAYS=9 WHERE L_ID=2;
SELECT
➢ SELECT * FROM EMPLOYEE;
DELETE
➢ DELETE FROM LEAVETBL WHERE L_ID=6
• AFTER DELETE
Experiment No. 4 Select, Delete, Drop Query and Clause
DROP TABLE
➢ DROP TABLE EMPNAMES
CLAUSE
1. GROUP BY:
SELECT COUNT(E_ID), A_ID
FROM PAYROLL
GROUP BY A_ID;
2. HAVING:
➢ SELECT COUNT(E_ID), A_ID
FROM PAYROLL
GROUP BY A_ID
HAVING COUNT(E_ID) >= 2;
3. AGGREGATE
PAYROLL
i. COUNT
SELECT COUNT(L_ID) FROM LEAVETBL;
LEAVETBL
ii. SUM
SELECT SUM(LEAVE_DAYS) FROM LEAVETBL;
iii. AVG
SELECT AVG(LEAVE_DAYS) FROM LEAVETBL;
iv. MAX
SELECT MAX(LEAVE_DAYS) FROM LEAVETBL;
v. MIN
SELECT MIN(LEAVE_DAYS) FROM LEAVETBL;
Experiment No. 5 Create Index Command
CREATE INDEX
1. Single-Column Index:
➢ CREATE INDEX EMAILS ON EMPLOYEE (EMAIL);
➢ SELECT EMAIL FROM EMPLOYEE;
2. Unique Index:
➢ CREATE UNIQUE INDEX UEMAILS ON EMPLOYEE (EMAIL);
➢ SELECT EMAIL FROM EMPLOYEE;
3. Composite Index’
➢ CREATE index CEMAILS ON EMPLOYEE (EMAIL, GENDER);
➢ SELECT EMAIL,GENDER FROM EMPLOYEE;
SHOW INDEX
DROP INDEX
➢ DROP INDEX CEMAILS ON EMPLOYEE;
CREATE VIEW
➢ CREATE VIEW EMPLOYEE_DETAILS AS
SELECT E_ID, FNAME, LNAME, EMAIL, ADDRESS
FROM EMPLOYEE
WHERE AGE>20;
UPDATE VIEW
➢ CREATE OR REPLACE VIEW EMPLOYEE_DETAILS AS
SELECT EMPLOYEE.E_ID, EMPLOYEE.FNAME, EMPLOYEE.LNAME,
EMPLOYEE.EMAIL, EMPLOYEE.ADDRESS, EMPLOYEE.BASIC_SALARY,
PAYROLL.NETSALARY
FROM PAYROLL INNER JOIN Employee ON (Employee.E_ID=Payroll.E_ID)
WHERE NETSALARY>=25000;
DROP VIEW:
➢ DROP VIEW EMPLOYEE_DETAILS; #view dropped
Experiment No. 7 Canonical Cover
Program:
import java.util.*;
public class Canonical{
static HashMap<String,String> map=new HashMap<String,String>();
public static String removeDuplicates(String input){
String result = "";
for (int i = 0; i < input.length(); i++) {
if(!result.contains(String.valueOf(input.charAt(i))))
result += String.valueOf(input.charAt(i));
}
return result;
}
//2nd step
Experiment No. 7 Canonical Cover
System.out.println("By Closure...");
key=map.keySet().toArray(new String[0]);
value=map.values().toArray(new String[0]);
for(int i=0;i<key.length;i++){
if(key[i].length()>=2){
key=addX(key.length, key, key[i].substring(0,1));
value=addX(value.length, value, value[i]);
key[i]=key[i].substring(1,2);
}
}
for(int i=0;i<key.length;i++){
System.out.println(key[i]+"->"+value[i]);
}
//3rd
System.out.println("Removing same Attributes By Union...");
map.clear();
AddtoMap(key,value);
//4th step
System.out.println("Checking Transistivity...");
key=map.keySet().toArray(new String[0]);
value=map.values().toArray(new String[0]);
for(int i=0;i<key.length;i++){
if(key[i].length()>=2){
key=addX(key.length, key, key[i].substring(0,1));
value=addX(value.length, value, value[i]);
key[i]=key[i].substring(1,2);
}
}
for(int i=0;i<key.length;i++){
if(value[i].length()>1){
for(int j=0;j<key.length;j++){
if((value[i].contains(key[j]+value[j])) || ((new
StringBuffer(value[i])).reverse()).toString().contains(key[j]+value[j]))
value[i]=key[j];
}
}
System.out.println(key[i]+"->"+value[i]);
}
map.clear();
System.out.println("Final Canonical Cover Fc is:");
AddtoMap(key,value);
}
}
Experiment No. 7 Canonical Cover
Output:
Experiment No. 8
if(isset($_GET['Delete']))
{
echo "<script>alert('Deleted');</script>";
$con=new mysqli("localhost","root","","EMPLOYEEDB");
$r1=$_GET['r1'];
$q="DELETE from employee WHERE E_ID=$r1";
$con->query($q) ;
$con->close();
echo "<script>window.location.href = 'index.php';</script>";
}
Experiment No. 8
$con=new mysqli("localhost","root","","EMPLOYEEDB");
$q="SELECT * from EMPLOYEE";
$result=$con->query($q);
echo "<h1>EMPLOYEE DETAILS</h1>";
echo "<center>";
echo "<table border='5'>";
echo "<tr>";
echo "<th>Roll
no</th><th>WBP</th><th>PWP</th><th>ETI</th><th>MAD</th><th>EDP</th><th>MG
T</th><th>Edit</th><th>Delete</th></tr>";
while($row=$result->fetch_assoc())
{
echo "<form action='' method='get'>";
echo "<input type='hidden' name='r1' value=".$row['E_ID'].">";
echo "</td><td>";
echo "<input type='text' name= 'r' value =".$row['E_ID'].">";
echo "</td><td>";
echo "<input type='text' name='m1' value=".$row['FNAME'].">";
echo "</td><td>";
echo "<input type='text' name='m2' value=".$row['LNAME'].">";
echo "</td><td>";
echo "<input type='text' name='m3' value=".$row['AGE'].">";
echo "</td><td>";
echo "<input type='text' name='m4' value=".$row['ADDRESS'].">";
echo "</td><td>";
echo "<input type='text' name='m5' value=".$row['EMAIL'].">";
echo "</td><td>";
echo "<input type='text' name='m6' value=".$row['BASIC_SALARY'].">";
echo "</td><td>";
echo "<input type='submit' name='edit' value='Edit'>";
echo "</td><td>";
echo "<input type='submit' name='Delete' value='Delete'>";
echo "</td></tr>";
}
echo "</table>";
echo "<br><br><input type='submit' name='Insert' value='INSERT'
style='border:2PX SOLID #000; heigth:100px; width:100px;'>";
echo "</center>";
echo "</form>";
?>
Experiment No. 8
Insert.php
<?php
if(isset($_GET["view"]))
{
echo "<script>window.location.href = 'index.php';</script>";
}
if(isset($_GET["Insert"]))
{
$r=$_GET['r'];
$m1=$_GET['m1'];
$m2=$_GET['m2'];
$m3=$_GET['m3'];
$m4=$_GET['m4'];
$m5=$_GET['m5'];
$m6=$_GET['m6'];
$o=new mysqli("localhost","root","");
$o->select_db("EMPLOYEEDB");
$s=$o->query("INSERT INTO EMPLOYEE values($r, '$m1', '$m2',$m3,'$m4',
'$m5',$m6)");
if($s)
{
echo "<script>alert('Inserted');</script>";
}
else
{
echo "<script>alert('Check values again Duplicate E_ID not
Allowed');</script>";
}
$o->close();
echo "<script>window.location.href = 'insert.php';</script>";
}
echo "<center>";
echo "<h1>INSERT EMPLOYEE DETAILS</h1>";
echo "<table border='5'>";
echo "<tr>";
echo
"<th>E_ID</th><th>FNAME</th><th>LNAME</th><th>AGE</th><th>ADDRESS</th><t
h>EMAIL</th><th>BASIC_SALARY</th><th>INSERT</th></tr>";
{
echo "<form action='' method='get'>";
echo "<tr><td>";
echo "<input type='text' name= 'r' >";
echo "</td><td>";
echo "<input type='text' name='m1' >";
echo "</td><td>";
Experiment No. 8
Home page
Insert Page
Before Updating
After Updating
After Deleting
Experiment No. 9 Database Triggers
TRIGGERS:
INSERT
➢ CREATE TRIGGER AINSERT
BEFORE INSERT
ON Employee
FOR EACH ROW
SET NEW.Email="ABC@GMAIL.COM";
UPDATE
➢ DELIMITER $$
CREATE TRIGGER AGEGT16
BEFORE UPDATE
ON EMPLOYEE FOR EACH ROW
BEGIN
IF NEW.AGE< 16 THEN SET NEW.AGE = 16;
END IF;
END $$
DELIMITER ;
DROP TRIGGER
➢ DROP TRIGGER NETSAL
➢ SHOW TRIGGERS FROM EMPLOYEEDB;
Experiment No. 10 Database Stored Procedures
PROCEDURES:
PROCEDURE WITHOUT PARAMETER
➢ DELIMITER &&
CREATE PROCEDURE GET_EMPLOYEE_DETAILS()
BEGIN
SELECT E_ID,FNAME,LNAME,BASIC_SALARY FROM EMPLOYEE ;
SELECT E_ID,L_ID FROM PAYROLL;
SELECT COUNT(E_ID) AS TOTAL_PAYROLL FROM PAYROLL;
END &&
DELIMITER ;
➢ CALL GET_EMPLOYEE_DETAILS();
➢ CALL GET_COUNT(23000);
SHOW PROCEDURE:
➢ SHOW PROCEDURE STATUS;
DROP PROCEDURE:
DROP PROCEDURE GET_COUNT; #procedure droped