Question

Task 7.1.2. Create a view named nc_jobs which shows all the bookjob information for a job...

Task 7.1.2. Create a view named nc_jobs which shows all the bookjob information for a job with a jobtype of N for publisher with a creditcode of C.

CREATE TABLE publishers (
cust_id       CHAR(3) NOT NULL,
name        CHAR(10),
city        CHAR(10),
phone        CHAR(8),
creditcode    CHAR(1),
primary key (cust_id)
);


CREATE TABLE bookjobs (
job_id       CHAR(3) NOT NULL,
cust_id       CHAR(3),
job_date    DATE,
descr CHAR(10),
jobtype CHAR(1),
primary key (job_id),
foreign key (cust_id) references publishers (cust_id)
);


CREATE TABLE pos (
job_id      CHAR(3) NOT NULL,
po_id     CHAR(3) NOT NULL,
po_date       DATE,
vendor_id     CHAR(3),
primary key (job_id, po_id),
foreign key (job_id) references bookjobs (job_id)
);


CREATE TABLE po_items (
job_id       CHAR(3) NOT NULL,
po_id       CHAR(3) NOT NULL,
item_id       CHAR(3) NOT NULL,
quantity     SMALLINT,
primary key (job_id, po_id, item_id),
foreign key (job_id, po_id) references pos (job_id, po_id),
foreign key (item_id) references items (item_id)
);


CREATE TABLE items (
item_id    CHAR(3) NOT NULL,
descr    CHAR(10),
on_hand    SMALLINT,
price     DECIMAL(5,2),
primary key (item_id)
);


insert into publishers values ('A01', 'ART BOOKS', 'SYDNEY', '555-1234', 'N');
insert into publishers values ('B02', 'BIBLECO', NULL, '555-2468', 'C');
insert into publishers values ('C03', 'CABLE-EX', 'BRISBANE', '555-3690', 'N');
insert into publishers values ('D04', 'DIABLO CO', 'MELBOURNE', NULL, 'D');
insert into publishers values ('E05', 'EASYPRINT', 'PERTH', '555-5050', 'C');
insert into publishers values ('F06', 'FOX-PAW', 'HOBART', '555-6789', 'C');
insert into publishers values ('G07', 'GOLD PRESS', 'ADELAIDE', '555-7777', 'N');
insert into publishers values ('H08', 'HELP BOOKS', 'DARWIN', NULL, 'C');


insert into bookjobs values ('001', 'E05', '1990-04-04', 'TEXT BOOKS', 'R');
insert into bookjobs values ('002', 'E05', '1990-03-03', 'BUS REPORT', 'N');
insert into bookjobs values ('003', 'E05', '1989-12-25', 'COMMERCIAL', 'N');
insert into bookjobs values ('004', 'A01', '1990-01-01', 'PAMPHLETS', 'R');
insert into bookjobs values ('005', 'A01', '1989-11-23', 'GOVT', 'N');
insert into bookjobs values ('006', 'D04', '1988-07-04', 'CAMPAIGN', 'H');


insert into pos values ('002', 'AAA', '1990-05-20', 'ABC');
insert into pos values ('002', 'BBB', '1990-03-15', 'XYZ');
insert into pos values ('004', 'CCC', '1990-01-05', 'SOS');
insert into pos values ('004', 'DDD', '1990-01-01', 'ABC');
insert into pos values ('005', 'EEE', '1990-01-15', 'SOS');
insert into pos values ('005', 'FFF', '1989-12-01', 'ABC');
insert into pos values ('006', 'GGG', '1988-07-15', 'XYZ');


insert into items values ('P9', '9KG PAPER', 300, 25.25);
insert into items values ('P12', '12KG PAPER', 700, 49.99);
insert into items values ('P18', '18KG PAPER', 100, 100.00);
insert into items values ('IRN', 'INK-RESIN', 3, 500.00);
insert into items values ('IWS', 'INK-WRSOL', 5, 350.00);
insert into items values ('CBD', 'CARDBOARD', 47, 15.00);


insert into po_items values ('004', 'CCC', 'P9', 150);
insert into po_items values ('004', 'CCC', 'IRN', 4);
insert into po_items values ('004', 'DDD', 'P18', 100);
insert into po_items values ('002', 'AAA', 'P9', 50);
insert into po_items values ('002', 'AAA', 'IWS', 2);
insert into po_items values ('002', 'AAA', 'CBD', 17);
insert into po_items values ('002', 'BBB', 'CBD', 17);
insert into po_items values ('006', 'GGG', 'IRN', 2);

Homework Answers

Answer #1

Create a view named nc_jobs which shows all the bookjob information for a job with a jobtype of N for publisher with a creditcode of C.

Create view command

create view nc_jobs AS
SELECT b.job_id, b.cust_id, b.Job_date,b.descr,b.jobtype
FROM bookjobs as b
JOIN publishers as p on p.cust_id = b.cust_id
WHERE b.jobtype='N' and p.creditcode='C';

Explanation :

The given query requires data from two tables and display the data as one table.

For view creation command is: CREATE VIEW [view name] AS

SELECT statement will fetch attributes from bookjobs table

JOIN clause will join publishers and bookjobs based on cust_id

WHERE clause will specify the condition where jobytype is 'N' and creditcode of publisher is 'C'

SQL Command to view the records of nc_jobs

SELECT * FROM nc_jobs;

Output

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
-- Table construction (just 1 simplest possible way) CREATE TABLE PetType ( petTypeId VARCHAR(10) PRIMARY KEY,...
-- Table construction (just 1 simplest possible way) CREATE TABLE PetType ( petTypeId VARCHAR(10) PRIMARY KEY, animalType VARCHAR(20), breed VARCHAR(20) ); CREATE TABLE Owner ( ownerId VARCHAR(10) PRIMARY KEY, firstName VARCHAR(20), lastName VARCHAR(20) NOT NULL, homePhoneNumber VARCHAR(20), streetAddress VARCHAR(80), suburb VARCHAR(20), postcode VARCHAR(10) ); CREATE TABLE Pet ( petId VARCHAR(10) PRIMARY KEY, petName VARCHAR(20), sex CHAR(1) CHECK (sex IN ('M', 'F')), petTypeId VARCHAR(10) FOREIGN KEY REFERENCES PetType ); CREATE TABLE PetAndOwner ( ownerId VARCHAR(10), petId VARCHAR(10), PRIMARY KEY (ownerId, petId),...
1. For the Pet Database described in the previous practical, write an SQL statement with a...
1. For the Pet Database described in the previous practical, write an SQL statement with a subquery to list all the people in the Owner table who own more than one pet. should be a collum of the total number of pets owned, owner id, first name and last name -- DROP TABLE PetAndOwner, Pet, PetType, Owner; CREATE TABLE PetType ( petTypeId VARCHAR(10) PRIMARY KEY, animalType VARCHAR(20), breed VARCHAR(20) ); CREATE TABLE Owner ( ownerId VARCHAR(10) PRIMARY KEY, firstName VARCHAR(20),...
Please create the queries listed below using the books database under question 4. Thanks for the...
Please create the queries listed below using the books database under question 4. Thanks for the help 1. List the number of books, the minimum price, maximum price, and average sales of history books. The format of output is: Number Min Price Max Price Average Sale 2. List the number of books and the average number of pages published by pub_id P01. 3. List the number of books and the total sales of the books with price greater than $15....
Aggregation 1. List the following about history books: number of history books, the minimum price, maximum...
Aggregation 1. List the following about history books: number of history books, the minimum price, maximum price, and average sales. The format of output is: "Number" "Min Price" "Max Price" "Average Sale" 2. List the number of books and the average number of pages published by pub_id 01. 3. For each book type, list the the number of books and the average price. Sort the results by the number of books Functions 4. List the name(s) of the publisher(s) that...
SQL DATABASE Task 4 [1.5 marks] Create Index (0.5 marks) Currently, the database only contains a...
SQL DATABASE Task 4 [1.5 marks] Create Index (0.5 marks) Currently, the database only contains a small number of records. However, the data contained within it is expected to grow significantly in the future. Creating indexes on commonly searched columns is a way performance issues can be minimized. Write a command to create an index on student_name column of the student table. Create view – 1 mark Write a command to create a view to list the student ID and...
Find the total number of employees and the total number of dependents for every department (the...
Find the total number of employees and the total number of dependents for every department (the number of dependents for a department is the sum of the number of dependents for each employee working for that department). Return the result as department name, total number of employees, and total number of dependents Based on the following table: -- drop tables DROP TABLE EMPLOYEE CASCADE CONSTRAINTS; DROP TABLE DEPARTMENT CASCADE CONSTRAINTS; DROP TABLE DEPT_LOCATIONS CASCADE CONSTRAINTS; DROP TABLE PROJECT CASCADE CONSTRAINTS;...
SQL Data: you can just copy paste it into mysql to. CREATE DATABASE University;USE University; CREATE...
SQL Data: you can just copy paste it into mysql to. CREATE DATABASE University;USE University; CREATE TABLE Student (  sid INT PRIMARY KEY,  name VARCHAR(20) NOT NULL,  address VARCHAR(20) NOT NULL,  major CHAR(2)); CREATE TABLE Professor (  pid INT PRIMARY KEY,  name VARCHAR(20) NOT NULL,  department VARCHAR(10) NOT NULL); CREATE TABLE Course (  cid INT PRIMARY KEY,  title VARCHAR(20) NOT NULL UNIQUE,  credits INT NOT NULL,  area VARCHAR(5) NOT NULL); CREATE TABLE Transcript (  sid INT,  cid INT,  pid INT,  semester VARCHAR(9),  year YEAR,  grade CHAR(1) NOT NULL,  PRIMARY KEY (sid, cid, semester, year),  FOREIGN KEY (sid) REFERENCES Student...
/* myCompany.SQL Introduction to SQL Script file for ORACLE DBMS This script file creates the following...
/* myCompany.SQL Introduction to SQL Script file for ORACLE DBMS This script file creates the following tables: VENDOR, PRODUCT, CUSTOMER, INVOICE, LINE EMPLOYEE and loads the default data rows */ set echo on; set serveroutput on; select systimestamp from dual; show user; ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY'; DROP TABLE LINE CASCADE CONSTRAINTS; DROP TABLE INVOICE CASCADE CONSTRAINTS; DROP TABLE CUSTOMER CASCADE CONSTRAINTS; DROP TABLE PRODUCT CASCADE CONSTRAINTS; DROP TABLE VENDOR CASCADE CONSTRAINTS; DROP TABLE EMPLOYEE CASCADE CONSTRAINTS; CREATE TABLE...
/* myCompany.SQL Introduction to SQL Script file for ORACLE DBMS This script file creates the following...
/* myCompany.SQL Introduction to SQL Script file for ORACLE DBMS This script file creates the following tables: VENDOR, PRODUCT, CUSTOMER, INVOICE, LINE EMPLOYEE and loads the default data rows */ set echo on; set serveroutput on; select systimestamp from dual; show user; ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY'; DROP TABLE LINE CASCADE CONSTRAINTS; DROP TABLE INVOICE CASCADE CONSTRAINTS; DROP TABLE CUSTOMER CASCADE CONSTRAINTS; DROP TABLE PRODUCT CASCADE CONSTRAINTS; DROP TABLE VENDOR CASCADE CONSTRAINTS; DROP TABLE EMPLOYEE CASCADE CONSTRAINTS; CREATE TABLE...
CREATE TABLE Orders (Order# NUMBER(4), Customer# NUMBER(4), OrderDate DATE NOT NULL, ShipDate DATE, ShipStreet VARCHAR2(18), ShipCity...
CREATE TABLE Orders (Order# NUMBER(4), Customer# NUMBER(4), OrderDate DATE NOT NULL, ShipDate DATE, ShipStreet VARCHAR2(18), ShipCity VARCHAR2(15), ShipState VARCHAR2(2), ShipZip VARCHAR2(5), ShipCost NUMBER(4,2), CONSTRAINT orders_order#_pk PRIMARY KEY(order#), CONSTRAINT orders_customer#_fk FOREIGN KEY (customer#) REFERENCES customers(customer#)); INSERT INTO ORDERS VALUES (1000,1005,TO_DATE('31-MAR-09','DD-MON-YY'),TO_DATE('02-APR-09','DD-MON-YY'),'1201 ORANGE AVE', 'SEATTLE', 'WA', '98114' , 2.00); INSERT INTO ORDERS VALUES (1001,1010,TO_DATE('31-MAR-09','DD-MON-YY'),TO_DATE('01-APR-09','DD-MON-YY'), '114 EAST SAVANNAH', 'ATLANTA', 'GA', '30314', 3.00); INSERT INTO ORDERS VALUES (1002,1011,TO_DATE('31-MAR-09','DD-MON-YY'),TO_DATE('01-APR-09','DD-MON-YY'),'58 TILA CIRCLE', 'CHICAGO', 'IL', '60605', 3.00); INSERT INTO ORDERS VALUES (1003,1001,TO_DATE('01-APR-09','DD-MON-YY'),TO_DATE('01-APR-09','DD-MON-YY'),'958 MAGNOLIA LANE', 'EASTPOINT', 'FL', '32328', 4.00);...