Question

In: Computer Science

Pretend you are writing a SQL Code for a database with aHomeowners Insurance Company.Use...

Pretend you are writing a SQL Code for a database with a Homeowners Insurance Company.

Use Microsoft SQL to write a code for the following:

  1. Create a new table called Policy_Total. It will contain the number of policies in the policy table. Create a trigger that increments the policy total every time a policy is added. Create another trigger that decrements the policy total every time a policy is deleted.

  2. Create a stored procedure that compares the policy total field from the Policy Total Table to the number of policies in the Policy Table.

Solutions

Expert Solution

Below SQL code will create the table called Policy_Total:

CREATE TABLE Policy_Total(
   Num_Policies INT
);

Trigger to increment the policies:

CREATE TRIGGER IncrementPolicy
       ON Policy
AFTER INSERT
AS
BEGIN
       SET NOCOUNT ON;

       UPDATE Policy_Total
       SET Num_Policies = Num_Policies + 1;
END

Trigger to decrement the policies:

CREATE TRIGGER DecrementPolicy
       ON Policy
AFTER DELETE
AS
BEGIN
       SET NOCOUNT ON;

       UPDATE Policy_Total
       SET Num_Policies = Num_Policies - 1;
END

Stored Procedure to compare total policies

CREATE PROCEDURE comparePolicies
AS
   IF (SELECT COUNT(*) FROM Policy) = (SELECT Num_Policies FROM Policy_Total)
       SELECT 'Correct Policies'
   ELSE
       SELECT 'Incorrect Policies'
GO


Related Solutions

Which of the following is a database client software? Microsoft SQL Server 2017 Developer Microsoft SQL...
Which of the following is a database client software? Microsoft SQL Server 2017 Developer Microsoft SQL Server Management Studio Microsoft SQL Server Configuration Manager SQL Server Analysis Service Compared to Data Warehousing approach, the following are disadvantages of query-driven data integration approach, EXCEPT: __________. competition with local processing at source delay in query processing waste of storage space inefficient and potentially expensive for frequent queries What does OLAP stand for? Olympic Linear Algebra Problem On-Line Amazon Platform On-Line Analytical Processing...
writing pretend you are working in a hotel busness place describe how would you apply use...
writing pretend you are working in a hotel busness place describe how would you apply use ethic to be successfull as an employee in that workplace
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
Create the actual database using SQL syntax. This is completed using a Database Application (i.e Microsoft...
Create the actual database using SQL syntax. This is completed using a Database Application (i.e Microsoft Access, Oracle, or MySQL) as indicated by your professor. After creating the database – populate it with some data (could be made up). SQL syntax and the DB application will be discussed and taught in class. This is the final deliverable of the group project. Assignment is due by the due date as indicated by your professor. *Make sure to submit the completed database...
Database - SQL - Operations CS 203 Discrete Structure 2 Create a Microsoft Access Database consisting...
Database - SQL - Operations CS 203 Discrete Structure 2 Create a Microsoft Access Database consisting of the following two tables: Part_needs and Parts_Inventory Part_needs Supplier Part_number Project 23 1092 1 23 1101 3 23 9048 4 31 4975 3 31 3477 2 32 6984 4 32 9191 2 33 1001 1 Parts_Inventory Part_number Project Quantity Color_code 1001 1 14 8 1092 1 2 2 1101 3 1 1 3477 2 25 2 4975 3 6 2 6984 4 10...
You should try this code in Microsoft SQL Server to get the practice of using the...
You should try this code in Microsoft SQL Server to get the practice of using the command line and getting syntax errors. You can submit to me your sql files or just copy and paste of your code in a word document. I may try to run it, so make sure it is error free. Or you can show screen shots of code running. Write SQL CREATE Table statement to create the following table with  Owner ID  as a surrogate key.  Owner ID...
You should try this code in Microsoft SQL Server to get the practice of using the...
You should try this code in Microsoft SQL Server to get the practice of using the command line and getting syntax errors. You can submit to me your sql files or just copy and paste of your code in a word document. I may try to run it, so make sure it is error free. Or you can show screen shots of code running. Write SQL CREATE Table statement to create the following table with  Owner ID  as a surrogate key.  Owner ID...
Draw an ER diagram with these attributes ( ER diagram for SQL for a library database)...
Draw an ER diagram with these attributes ( ER diagram for SQL for a library database) DRAW ER DIAGRAM AS ONE FULL LIBRARY SYSTEM, NOT DIFFERENT FOR EACH ATTRIBUTE. Attributes :           Customer Cust_ID: key identifier, required, simple, single valued Cust_Name{ first name, last name}: Key Identifier, simple;composite, multivaried   Address{street, city,zip,state}: Customer address, required, composite, single can be derived from zip (placeholder, there should be another attribute here to represent the books taken out by the customer. Not sure.)           Inventory Book_ID:...
SQL DATABASE Task 2 [10.5 marks] using the AdditionCollege database For task 2, we have provided...
SQL DATABASE Task 2 [10.5 marks] using the AdditionCollege database For task 2, we have provided you with the creation script for the AdditionCollege database. Run this script in MySQL Workbench to create the database. You should execute your query solutions to extract the necessary information. The script is based on the following schematic: Unit (Unit_code, Staff_id, [UnitName]) Staff (Staff_id, StaffName, Position, Gender) Taught_by (Unit_code, Staff_id, weekday) Student (Student_id, Student_name, Address, Gender) TuteGroup (TuteGroup_code, Unit_code, DayHrCode, Room_Nr) TuteGroup_List (TuteGroup_code, Student_id)...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based on your entities defining The attributes within each table The primary and foreign keys within each table *****Show your database tables, tables attributes, primary and foreign keys***** Do not forget to check the lesson slides and videos that show you how to convert an ER/EER into a database schema, and how to create a database and tables using MS SQL Server.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT