I have to create a trigger on the Claims table that is triggered whenever a new record is inserted into the Claims table. This trigger should store the customer name and the total amount_of_claim by that customer.
Claim_audits (audit table) have already been created.
Schema:
Claims id int(11) status_id int(11) customer_policy_id int(11) date_of_claim date amount_of_claim float > one or many to one(and only one) towards Customer_policy Customer_policy id int(11) policy_start_date date policy_renewal_date date policy_id int(11) customer_id int(11) agent_id(11) > one or many to one (and only one) towards Customer Customer id int(11) first_name varchar(30) last_name varchar(30) email varchar(30) address_id int(11) Output should look like this:
customer_name amount_of_claim abhinav 195000 This is what I have tried:
CREATE TRIGGER claim_audits on claims for insert as declare @custname varchar(25); declare @amount varchar(25); declare @action varchar(25); select @custname = first_name from customer c join inserted i on i.id=c.id; select @amount = i.amount_of_claim from inserted i; select @action = 'Updated customer claimed amount'; insert into claim_audits values(@custname , @amount , @action); select * from claim_audits; go
* from claim_auditsat the end? Its very bad practice to select within a trigger... what are you trying to accomplish.amount_of_claim floatfloat is approximate value. Usedecimalornumericinstead.