SQL- Trigger I have two tables (below) I need to write a trigger that would delete everything...

Free

80.2K

Verified Solution

Question

Programming

SQL- Trigger

I have two tables (below) I need to write a trigger that woulddelete everything for a pid from the Appt table if the pid isdeleted from the patient table.

Create table Appt(
               pid numeric Foreign Key references patient(pid),
               ptname varchar(50) Foreign Key references patient(name),
               dob date Foreign Key references patient(dob),
               dr varchar(20),
               appdate date,
               apptime time,
);

and

Create table Patient(
               pid numeric primary key,
               name varchar(50),
               dob date,
               pdr varchar(20),
               phnum numeric(10),
             email varchar(50),
               addr varchar(50)
);

Answer & Explanation Solved by verified expert
4.4 Ratings (606 Votes)

Below is the changes you need to done

ON DELETE CASCADE trigger is used to perform such action.

Create table Appt(
                pid numeric Foreign Key references patient(pid),
                ptname varchar(50) Foreign Key references patient(name) ON DELETE CASCADE,
                dob date Foreign Key references patient(dob),
                dr varchar(20),
                appdate date,
                apptime time,
);

and

Create table Patient(
                pid numeric primary key,
                name varchar(50),
                dob date,
                pdr varchar(20),
                phnum numeric(10),
              email varchar(50),
                addr varchar(50)

}


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students