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),...
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...
SQL Write the queries necessary to obtain the required information 1) Use sub query and “in”...
SQL Write the queries necessary to obtain the required information 1) Use sub query and “in” keyword to print the salesreps (ids) who have taken order for the companies ‘Zetacorp’ or ‘JCP Inc.’ . Duplicate rows are not allowed 2) Use sub query to find the id and the name of every sales rep that represents at least one customer with a credit limit of greater than $5000. 3) Use sub query and keyword “exists” to list the id and...
Summary The Ch08_ConstructCo database stores data for a consulting company that tracks all charges to projects....
Summary The Ch08_ConstructCo database stores data for a consulting company that tracks all charges to projects. The charges are based on the hours each employee works on each project. The structure and contents of the Ch08_ConstructCo database are shown in Figure P8.1. Use this database to answer the following problems. Database Schema The schema for the Ch08_ConstructCo database is shown below and should be used to answer the next several problems. Click this image to view it in its own...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT