CREATE TABLE Vendors (
vend_id CHAR(10) NOT NULL
PRIMARY KEY
,
vend_name CHAR(50) NOT NULL,
vend_address CHAR(50) NULL
);
|
ALTER TABLE Vendors
ADD
CONSTRAINT PRIMARY KEY
(vend_id);
|
CREATE TABLE Orders (
order_num INTEGER NOT NULL PRIMARY KEY,
order_date DATETIME NOT NULL,
cust_id CHAR(10) NOT NULL
REFERENCES
Customers(cust_id)
);
|
ALTER TABLE Orders
ADD
CONSTRAINT
FOREIGN KEY (cust_id)
REFERENCES
Customers (cust_id)
|
ALCREATE TABLE OrderItems
( order_num INTEGER NOT NULL,
quantity INTEGER NOT NULL
CHECK (quantity > 0)
,
);
|
ADD CONSTRAINT CHECK (gender LIKE '[MF]')
|
CREATE INDEX
prod_name_ind
ON
PRODUCTS (prod_name);
|
CREATE TRIGGER customer_state
ON Customers
FOR INSERT, UPDATE
AS
UPDATE Customers
SET cust_state = Upper(cust_state)
WHERE Customers.cust_id = inserted.cust_id;
|