Question
SQL CHECK CONSTRAINT AND TEST CASE... SQL Query Here are the tables: CREATE TABLE Movies( movieID INT, name VARCHAR(30) NOT NULL, year INT, rating CHAR(1),
SQL CHECK CONSTRAINT AND TEST CASE...
SQL Query
Here are the tables:
CREATE TABLE Movies(
movieID INT,
name VARCHAR(30) NOT NULL,
year INT,
rating CHAR(1),
length INT,
totalEarned NUMERIC(7,2),
PRIMARY KEY(movieID),
UNIQUE(name, year)
);
CREATE TABLE Showings(
theaterID INT,
showingDate DATE,
startTime TIME,
movieID INT,
priceCode CHAR(1),
PRIMARY KEY(theaterID, showingDate, startTime),
FOREIGN KEY(theaterID) REFERENCES Theaters,
FOREIGN KEY(movieID) REFERENCES Movies
);
CREATE TABLE Tickets(
theaterID INT,
seatNum INT,
showingDate DATE,
startTime TIME,
customerID INT,
ticketPrice NUMERIC(4,2),
PRIMARY KEY(theaterID, seatNum, showingDate, startTime)
);
the tasks are to write a check constraint as such:
3. In Showings, if movieID is not NULL, then priceCode must also not be NULL.
AND then i need to write an update statement that makes sure it fails per the constraint.
i've written:
ALTER TABLE Showings ADD CHECK ((movieID <> NULL) OR (priceCode <> NULL)); for the constraint
and
UPDATE Showings
SET priceCode = 1
WHERE movieID is not NULL; for the failing test.
i believe this is right, but the update statement is not failing like it is supposed to.
can someone see if i'm doing anything wrong or please explain how to correctly write it?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started