Question

In: Computer Science

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

SQL- Trigger

I have two tables (below) I need to write a trigger that would delete everything for a pid from the Appt table if the pid is deleted 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)
);

Solutions

Expert Solution

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)

}


Related Solutions

Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
Need SQL Tables Final Project should be included ER, NER, Table diagrams and SQL statements. The...
Need SQL Tables Final Project should be included ER, NER, Table diagrams and SQL statements. The final project is about developing an auction Web site. The details are as follows: BA is an online auction Web site. People can buy and sell items in this Web site. Buyers are people who like to buy items, and sellers are people who like to sell items. •Each seller can sell items. •Each item has a bidding start time, an end time, and...
SQL tables(like pinterest) should have those tables user board pictures, likes follow pins comments Please write...
SQL tables(like pinterest) should have those tables user board pictures, likes follow pins comments Please write SQL for those questions 1. two users are friends if each has liked at least three pictures from the other user’s boards. Output all pairs of friends. 2. For each picture, output the number of times it has been re-pinned. 3. names of all users who follow a board containing a picture with the description “cactus at sunset”. IV. names of all users who...
I have 3 tables, but I need that when the user logs in and enters his...
I have 3 tables, but I need that when the user logs in and enters his login and password, it shows me only the information of that client. But it is showing me the information of all the clients. Bank(mid,code,cid,sid,type,amount,mydate,note) from CPS300 This is the table where I want the information of a client to be seen Customers(id,name,login,password) from CPS200 Sources(id,name) from CPS200 --------------------------------------------------------------------------------------------------------------------------------- for now I have two queries, but I must correct the one for client authentication because...
Write the SQL DDL to create the following 5 tables for an App store: Publisher, Category,...
Write the SQL DDL to create the following 5 tables for an App store: Publisher, Category, App, AppVersion, AppVersionReview: A Publisher table where each publisher is identified by an integer id and has a name (up to 40 characters). (1 mark) A Category table where each category has an id (integer), a name (up to 50 characters), and a parentId to identify its parent category. The parentId should be a foreign key to the Category table. (1.5 marks) An App...
Using the HotelDB tables, provide the following result as a screen image. WRITE SQL to retrieve...
Using the HotelDB tables, provide the following result as a screen image. WRITE SQL to retrieve rows from any hotel with Family room types and price less than $150. use hoteldb; CREATE TABLE HOTEL ( hotelNo numeric primary key , name varchar(40) , address varchar(40) , city varchar(200) ); CREATE TABLE ROOM ( roomNo numeric Primary Key , hotelNo numeric References HOTEL , type varchar(20) , price dec(9,2) ); CREATE TABLE GUEST ( guestNo numeric primary key , name varchar(40)...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as if it were being added to MySQL (please give explanations for each line of SQL code and a copy of the code as it would be entered into the query by itself: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
Given two String arrays (named below), write the code that you would need in order to...
Given two String arrays (named below), write the code that you would need in order to copy the data from relatives into weddingInvitations in java. 1. relatives (which is loaded with data) 2. weddingInvitations (that is the same size as relatives)
Discuss the thresholds that trigger the need for an item of capital expenditure. What information would...
Discuss the thresholds that trigger the need for an item of capital expenditure. What information would you need to provide for the approval process? Why?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT