我真的想知道如何使用这些项创建触发器。 我有这6个表,我想知道如何创建销售订单触发器。 Extendedprice来自(sizeprice * quantity)+ ExtratoppingPrice 我希望触发器在order_item中插入Extendedprice的值。 非常感谢帮助我解决这些困难的任何人T ^ T
Create TABLE CUSTOMER(
CustomerID int NOT NULL,
CustomerFirstName char(40) NOT NULL,
CustomerLastName char(40) NOT NULL,
Email char(40) NOT NULL,
CustomerAddress char(100) NOT NULL,
Phone char(20) NOT NULL,
CONSTRAINT CUSTOMER_PK PRIMARY KEY (CustomerID)
);
Create TABLE BASE_TYPE(
BaseCode int NOT NULL,
BaseDescription char(40) NOT NULL
CONSTRAINT BASE_TYPE_PK PRIMARY KEY (BaseCode)
);
Create TABLE PIZZA_SIZE(
SizeCode int NOT NULL,
SizeType char(10) NOT NULL,
SizePrice numeric(10,2) NOT NULL,
CONSTRAINT PIZZA_SIZE_PK PRIMARY KEY (SizeCode)
);
Create TABLE EXTRA_TOPPING(
ExtraToppingCode int NOT NULL,
ExtraToppingDetail char(20) NOT NULL,
ExtraToppingPrice numeric(10,2) NOT NULL
CONSTRAINT EXTRA_TOPPING_PK PRIMARY KEY(ExtraToppingCode)
);
CREATE TABLE PIZZA(
PizzaID int NOT NULL,
PizzaTopping char(40) NOT NULL,
BaseCode int NOT NULL,
SizeCode int NOT NULL,
CONSTRAINT PIZZA_PK PRIMARY KEY (PizzaID),
CONSTRAINT BASE_TYPE_FK1 FOREIGN KEY (BaseCode)
REFERENCES BASE_TYPE(BaseCode)
ON UPDATE CASCADE
ON DELETE NO ACTION,
CONSTRAINT PIZZA_SIZE_FK FOREIGN KEY (SizeCode)
REFERENCES PIZZA_SIZE(SizeCode)
ON UPDATE CASCADE
ON DELETE NO ACTION
);
Create TABLE SALES_ORDERS(
SalesOrderNumber int NOT NULL,
CustomerID int NOT NULL,
OrderDate datetime NOT NULL,
CONSTRAINT SALES_ORDERS_PK PRIMARY KEY (SalesOrderNumber),
CONSTRAINT CUSTOMER_FK1 FOREIGN KEY (CustomerID)
REFERENCES CUSTOMER(CustomerID)
ON UPDATE CASCADE
ON DELETE NO ACTION,
);
CREATE TABLE ORDER_ITEM(
SalesOrderNumber int NOT NULL,
PizzaID int NOT NULL,
ExtraToppingCode int NULL,
Quantity numeric NOT NULL,
ExtendedPrice numeric(10,2) NULL,
CONSTRAINT ORDER_ITEM_PK1 PRIMARY KEY (SalesOrderNumber,PizzaID),
CONSTRAINT ORDER_ITEM_FK1 FOREIGN KEY (SalesOrderNumber)
REFERENCES SALES_ORDERS(SalesOrderNumber)
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT ORDER_ITEM_FK2 FOREIGN KEY (PizzaID)
REFERENCES PIZZA(PizzaID)
ON UPDATE CASCADE
ON DELETE NO ACTION,
CONSTRAINT ORDER_ITEM_FK3 FOREIGN KEY (ExtraToppingCode)
REFERENCES EXTRA_TOPPING(ExtraToppingCode)
ON UPDATE CASCADE
ON DELETE NO ACTION
);