Question

In: Computer Science

Would anyone know how to code this in SQL? I can't quite figure it out. The...

Would anyone know how to code this in SQL? I can't quite figure it out.

The following drop command is inserted for convenience so that if you need to recompile your code, it will drop the table

DROP TABLE Orders Cascade constraints

DROP TABLE OrderLine CASCADE CONSTRAINTS;

-- CREATE TABLE Orders

(

ordernum INTEGER PRIMARY KEY,

priority CHAR(10) NOT NULL,

cost INTEGER NOT NULL, /*

IC1: The priority is one of: high, medium, or low */

>>

/* IC2: The cost of a high priority order is above 2000. */

>>

/* IC3: The cost of a medium priority order is between 800 and 2200 (inclusive). */

>>

/* IC4: The cost of a low priority order is less than 1000. */

>>

Thank you in advance!

Solutions

Expert Solution

Here I am putting the constraints only:

CONSTRAINT IC1 CHECK (priority='high' OR priority='medium' OR priority='low'),
CONSTRAINT IC2to4 CHECK (
                         (priority = 'high'   AND cost > 2000) OR
                         (priority = 'medium' AND cost >= 800 AND cost <= 2200) OR
                         (priority = 'low'   AND cost > 1000) 
                       )

The Complete SQL create table query will look like:

CREATE TABLE Orders

(

ordernum INTEGER PRIMARY KEY,

priority CHAR(10) NOT NULL,

cost INTEGER NOT NULL, 

CONSTRAINT IC1 CHECK (priority='high' OR priority='medium' OR priority='low'),
CONSTRAINT IC2to4 CHECK (
                         (priority = 'high'   AND cost > 2000) OR
                         (priority = 'medium' AND cost >= 800 AND cost <= 2200) OR
                         (priority = 'low'   AND cost > 1000) 
                       )

);

Still any doubt do comment, else give a upvote. Thanks.


Related Solutions

I keep getting minor errors I can't figure out and I don't know how to convert...
I keep getting minor errors I can't figure out and I don't know how to convert decimal .10 to percentage 10% either.   With these functions defined now expand the program for a company who gives discounts on items bought in bulk. Create a main function and inside of it ask the user how many different items they are buying. For each item have the user input a price and quantity, validating them with the functions that you wrote. Use your...
C# Tip Calculator. I can't figure the code out for this assignment can I get some...
C# Tip Calculator. I can't figure the code out for this assignment can I get some help For this assignment, you'll create a simple tip calculator. Expected program flow: Ask the user for the bill total. Ask the user for the tip percent. Print the final output in the following format when the user enters 10 and 15 for the first two prompts: Total for bill $10.00 with a 15% tip is $11.50 Note that the money values should be...
I am supposed to map out the following and can't figure out how to do it!...
I am supposed to map out the following and can't figure out how to do it! Can somebody help? The experiment has to do with determining the simplest formula of potassium chlorate and to determine the original amount of potassium chlorate in a potassium chlorate-potassium chloride mixture by measuring the oxygen lost from decomposition. The chemical reaction is 2KClO3(s) ------> 2KCL(s) + 3 O2(g) I am supposed to map out 1. Mass of oxygen lost in the first part 2....
Can't figure out how to do this code with seperate main.cpp, inventory.cpp, inventory.h files, if you...
Can't figure out how to do this code with seperate main.cpp, inventory.cpp, inventory.h files, if you know how please help! in C++ Functional requirements: Create a linked list that holds a series of primary colors. The user inputs which colors are used and in which order.   Programming Requirements: Design your own dynamic linked list class (using pointers) to hold a series of primary colors The class should have the following member functions: append, insert (at a specific position, return -1...
I am getting an error at linen 57 and can't figure out how to fix it....
I am getting an error at linen 57 and can't figure out how to fix it. // Java program to read a CSV file and display the min, max, and average of numbers in it. import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; public class Main {     // method to determine and return the minimum number from the array     public static int minimum(int numbers[])     {         int minIdx = 0;         for(int i=1;i<numbers.length;i++)         {             if((minIdx...
I can't figure out how to create the decision tree with the sending a messaged situation!...
I can't figure out how to create the decision tree with the sending a messaged situation! The crew of Endurance can visit two planets (Mann’s and Edmunds’). They can choose to visit neither planets, one of the two planets, or both planets. The characteristics of Mann’s planet are below: • 30% chance of finding a perfectly habitable planet • can support all of Earth’s current population if it is • can support none of Earth’s population if it is not...
I can't seem to figure out what the hybridization of PF6(-) is. could someone explain how...
I can't seem to figure out what the hybridization of PF6(-) is. could someone explain how to find it correctly for me?
(Part a.) I can't figure out what amount Mike would deduct for 12 years. (Part b.)...
(Part a.) I can't figure out what amount Mike would deduct for 12 years. (Part b.) I can't figure out at all. Mike and Melissa form the equal MM LLC. Mike contributes cash of $40,000 and land (fair market value of $100,000, adjusted basis of $136,000), and Melissa contributes the assets of her sole proprietorship (value of $140,000, adjusted basis of $115,000). Mike purchased the land (value of $100,000; adjusted basis of $136,000) several years ago as an investment (capital)...
This is a question from Intro to Bayesian Statistics but I can't figure out what is...
This is a question from Intro to Bayesian Statistics but I can't figure out what is expected here. Derive the posterior distribution of obtaining heads in coin flips. The prior has p(θ = .25) = .25, p(θ = .50) = .50, and p(θ = .75) = .25. The data consist of a specific sequence of flips with 3 heads and 9 tails, so p(Data|θ) = θ^3 (1 − θ) ^9.
I can't figure out this math equation for "The Importance of the Price Elasticity of Demand:...
I can't figure out this math equation for "The Importance of the Price Elasticity of Demand: MC=P(1+(1/Ed)) My marginal cost(MC) is $50/month and that the price elasticity of demand (Ed) is -2.5, what price will maximize my firm's profits? $50=P(1+(1/-2.5))
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT