This project is a SQL Server-based Car Insurance Database designed to manage and analyze data related to customers, cars, insurance policies, accidents, claims, and payments. It includes a comprehensive schema, useful views, triggers, stored procedures, and sample data for demonstration and testing.
- Manage customer, car, and insurance policy data
- Track car ownership and accident records
- File and manage insurance claims and payments
- Automatically trigger data validation and logging
- View statistics and historical data using stored procedures and views
The database includes the following core tables:
- Customer – Stores customer details
- Car – Stores car details
- InsurancePolicy – Holds insurance policy data
- Ownership – Tracks car ownership history
- Accident – Stores accident records
- Claim – Manages insurance claims
- Payment – Manages claim-related payments
vw_ActivePolicies– Lists active insurance policiesvw_CustomerClaimsHistory– Shows customers' past claims and accident data
trg_UpdatePolicyStatus– Automatically setsPolicyStatus(Active, Expired, Future)trg_ValidateCarLicenseDates– Ensures license end date isn’t earlier than start datetrg_LogClaimStatusChanges– Logs claim status changes toClaimStatusLogtrg_SetInitialPaymentStatus– Automatically sets payment status to'Pending'if none is provided
Includes a variety of stored procedures to query and manipulate the database:
sp_CreateNewPolicy– Creates and inserts a new policysp_GetPremiumStatistics– Retrieves premium statistics by policy type
sp_FileNewClaim– Files a new insurance claimsp_AccidentsByModel– Counts accidents for a specific car modelsp_AccidentsInvolvedCount_2017– Counts unique owners involved in 2017 accidentssp_GetAccidentCountForAhmedMohamed– Accident count for a specific customersp_MaxAccidentModel_2017– Model with the most accidents in 2017sp_MinAccidentModel_2017– Model with the least accidents in 2017sp_GetModelsWithZeroAccidentsIn2017– Car models with no accidents in 2017sp_MostCommonAccidentType_2017– Most frequent accident type in 2017Retrieve_information– Retrieves customer info for cars involved in 2017 accidents
To help you get started, the script includes sample data for:
- 5 customers
- 10 cars
- 15 ownership entries
- 10 accident records
- Open SQL Server Management Studio.
- Run the script
car_insurance_db.sqlin the query editor. - (Optional) Uncomment the
CREATE DATABASEline if the database doesn’t exist. - Execute each section step-by-step or run the entire script.
This project is provided under the MIT License. Feel free to use, modify, and distribute it.
Designed and maintained by [Mohamed Nabil, Mohamed Ahmed, Amr Khaled, Mostafa Mahmoud, Mohamed Gafour, Nour Maged]. Contributions and feedback are welcome!