Professional Documents
Culture Documents
Contents
PROBLEM STATEMENT
SQL QUERIES
PROBLEM STATEMENT
The project is focused on Insurance Management System, which shows information about
different parts of insurance company, such as Agent, Customer, Policy, Employee, Claim
Handling and other related concepts, such as Claim, Premium, and different kinds of Insurance
policies.
The objective of the project here, is to implement a database management system, such that, it
uses the different tables to evaluate the performance of Insurance company.
Using this database can help insurance companies in order to answer some questions such as:
How many customers they already have?
How many policies they have?
How many customers have more than one policy?
Which kind of policy sold the highest?
How much is the premium that the company got from customer?
How many policies have been claimed?
Recognize customers that have more policies.
Recognize customers that have more valuable policies.
Calculate high/low risk customers.
Calculate best policies, which cost more premium and have less claim, and also number
of policy sold that includes those factors.
Calculate average time to recompense for damage.
DELIMITER //
CREATE procedure ClaimCustomer( IN claim int(20),OUT customer_name varchar(20) )
Begin
set customer_name =(select concat(first_name,' ',last_name) from person
where Person_Id = (
select person_id from Customer
where Customer_ID = (
select customer_id from policy
where Policy_ID = (
select Policy_ID from Claim
where Claim_ID = claim))));
END; //
DELIMITER ;
call ClaimCustomer(217217,@v);
select @v;
Triggers:
DELIMITER //
CREATE DEFINER = CURRENT_USER TRIGGER
`insurance_management`.`policy_BEFORE_UPDATE` BEFORE UPDATE ON `policy` FOR
EACH ROW
BEGIN
insert into policy_log
set policy_id = old.policy_id,
agent_id = old.agent_id,
customer_id = old.customer_id,
premium_id = old.premium_id,
date = now();
END;//
DELIMITER ;
--
-- Table structure for table `Address`
--
--
-- Dumping data for table `Address`
--
--
-- Table structure for table `Agent`
--
--
-- Dumping data for table `Agent`
--
--
-- Table structure for table `Agent_Customer`
--
--
-- Dumping data for table `Agent_Customer`
--
--
-- Table structure for table `Claim`
--
--
-- Dumping data for table `Claim`
--
--
-- Table structure for table `Claim_not_paid`
--
--
-- Table structure for table `Customer`
--
--
-- Dumping data for table `Customer`
--
--
-- Table structure for table `Employee`
--
--
-- Dumping data for table `Employee`
--
--
-- Table structure for table `Health_Policy`
--
--
-- Dumping data for table `Health_Policy`
--
--
-- Table structure for table `Policy_Type`
--
--
-- Dumping data for table `Policy_Type`
--
--
-- Dumping data for table `Premium`
--
--
-- Table structure for table `Report`
--
--
-- Dumping data for table `Report`
--
--
-- Table structure for table `Vehicle_Policy`
--
--
-- Dumping data for table `Vehicle_Policy`
--
--
-- Table structure for table `Vehicle_Type`
--
--
-- Dumping data for table `Vehicle_Type`
--
--
-- Temporary view structure for view `agent_details`
--
--
-- Table structure for table `claim_handling`
--
--
-- Dumping data for table `claim_handling`
--
--
-- Table structure for table `home_policy`
--
--
-- Dumping data for table `home_policy`
--
--
-- Table structure for table `insurance_Company`
--
--
-- Dumping data for table `insurance_Company`
--
--
-- Table structure for table `office`
--
--
-- Dumping data for table `office`
--
--
-- Table structure for table `person`
--
--
-- Dumping data for table `person`
--
--
-- Table structure for table `policy`
--
--
-- Dumping data for table `policy`
--
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
--
-- Table structure for table `policy_log`
--
--
-- Dumping data for table `policy_log`
--
--
-- Table structure for table `report_log`
--
--
-- Dumping data for table `report_log`
--
--
-- Dumping events for database 'insurance_management'
--
--
-- Dumping routines for database 'insurance_management'
--
/*!50003 DROP PROCEDURE IF EXISTS `CalculatePremium` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode =
'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZER
O_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGI
NE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `CalculatePremium`( IN agent
varchar(20),OUT premium Float )
Begin
set premium =(select sum(pre.amount)
from policy po,premium pre
where po.premium_id = pre.premium_id
and po.agent_id = agent
group by po.agent_id
order by agent_id);
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `ClaimCustomer` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode =
'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZER
O_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGI
NE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ClaimCustomer`( IN claim
int(20),OUT customer_name varchar(20) )
Begin
set customer_name =(select concat(first_name,' ',last_name) from person
where Person_Id = (
select person_id from Customer
where Customer_ID = (
select customer_id from policy
where Policy_ID = (
select Policy_ID from Claim
where Claim_ID = claim))));
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
--
-- Final view structure for view `agent_details`
--