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...
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)...
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?
I am working on an assignment using SQL Server Management and I need to print an...
I am working on an assignment using SQL Server Management and I need to print an ERD to a single page as a PDF file. I am not sure how to do this especially because the diagram is rather large... I am using SQL Server Management Studio I have created an Entity relationship diagram for AdventureWorks that includes all product tables. There are many tables.How do I print it to a single page?
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: 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.
Homework: Populate Sales Order tables. Write SQL to : 1. insert 5 records in each table:...
Homework: Populate Sales Order tables. Write SQL to : 1. insert 5 records in each table: Market, Region, ProductFamily, Manager (all Managers must have different % commissions, Commission is an attribute of the Manger). 2. Insert 5 records in Agent using all Managers 3. Insert 15 records in Product using  all ProductFamily 4. Insert 15 records in Customer using various Regions and Markets 5. Insert 50 records in SalesOrder using various Customers, Products, Agents Notes : ALL the Names ( Description)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT