How do i create this trigger? CREATE A TRIGGER CALLED \"TESTDRIVE\" When a new t
ID: 3545692 • Letter: H
Question
How do i create this trigger?
CREATE A TRIGGER CALLED "TESTDRIVE"
When a new test drive is recorded, the related record in INVENTORY should indicate the vehicle is available for sale (i.e. the value for available for sale is 1)
Below are the tables
CREATE TABLE INVENTORY(
InvenCode CHAR(7) NOT NULL UNIQUE,
dealerNum CHAR(4) NOT NULL,
vinNum CHAR(17) NOT NULL,
newUsed CHAR(1) NOT NULL,
dateArrDealership SMALLDATETIME NOT NULL,
dateAvailInStock SMALLDATETIME NULL,
dateSold SMALLDATETIME NULL,
listPrice SMALLMONEY NOT NULL,
extColor VARCHAR(10) NOT NULL,
intColor VARCHAR(10) NOT NULL,
vhCode CHAR(7) NOT NULL,
AvailSale BIT NOT NULL
CREATE TABLE TESTDRIVE(
TestDrcode CHAR(7) NOT NULL UNIQUE,
custNum CHAR(8) NOT NULL,
Datetestdr SMALLDATETIME NOT NULL,
Durtestdr DECIMAL NULL,
InvenCode CHAR(7) NOT NULL
Explanation / Answer
CREATE TRIGGER yourNewTrigger ON TESTDRIVE AFTER INSERT AS BEGIN UPDATE INVENTORY SET AvailSales = 1 WHERE Inventory.InvenCode = (Select InvenCode FROM inserted.InvenCode) ENDGO Note: The inserted table stores copies of the affected rows during INSERT and UPDATE statements. During an insert or update transaction, new rows are added simultaneously to both the inserted table and the trigger table. The rows in the inserted table are copies of the new rows in the trigger table.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.