Question: What's wrong with my code? I am working in postgres and keep getting errors when I try to insert data. Please help. 3 . Create
What's wrong with my code?
I am working in postgres and keep getting errors when I try to insert data. Please help.
Create a trigger function on the CUSTOMER table called resetpassword that will set the Password column to the word RESET when a new row is inserted into the table. Create a trigger to use the trigger function. Then, insert a new row into CUSTOMER with the following values:
Customerid: do NOT include the customerid on the insert. It will be updated automatically
Emailaddress: your own email address
Password: NewPass
Firstname: your first name
Lastname: your last name
Shippingaddressid:
Billingaddressid:
After the insert, do: select from customer where emailaddress replacing with the email that you entered above, and screenshot the resulting row showing that the trigger worked correctly the Password column should have RESET
CREATE OR REPLACE FUNCTION resetpassword
RETURNS TRIGGER AS $$
BEGIN
NEW.password : 'RESET';
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER resetpasswordtrigger
BEFORE INSERT ON customer
FOR EACH ROW
EXECUTE FUNCTION resetpassword;
Insert into CUSTOMER emailaddress, password, firstname, lastname, shippingaddressid billingaddressid
values xxxxxxxxxxxxxxx 'NewPass', xxxxxxx;
Select from customer
where emailaddress xxxxxxxxxxx;
ERROR: Key shippingaddressid is not present in table "address".insert or update on table "customer" violates foreign key constraint "customershippingaddressidfkey"
ERROR: insert or update on table "customer" violates foreign key constraint "customershippingaddressidfkey"
SQL state:
Detail: Key shippingaddressid is not present in table "address".
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
