Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the commands following the instructions below. Click on Write Submssion an

ID: 3919983 • Letter: W

Question

Write the commands following the instructions below. Click on Write Submssion and copy and paste the commands into the submission box. This assignment should be completed by July 27th

Create a table called NEWPUBLISHERS that contains the pub ID, name, contact and the category, ISBN and title of the book published. Use the same data types as the corresponding columns in the publisher and books table. Do not copy the data from these tables, however.

In the CREATE TABLE command above, include the constraint that the pub ID is the primary key.

In the CREATE TABLE command above, include the contraints that the title and category are not null.

In the CREATE TABLE command above, include the constraint that the ISBN is a foreign key referencing the ISBN in the books table.

In the table creation assignment you created a table called EMPLOYEES. Alter this table so that the SSN is the primary key.

Explanation / Answer

Create a table called NEWPUBLISHERS that contains the pub ID, name, contact and the category, ISBN and title of the book published. Use the same data types as the corresponding columns in the publisher and books table. Do not copy the data from these tables, however.

In the CREATE TABLE command above, include the constraint that the pub ID is the primary key.

In the CREATE TABLE command above, include the contraints that the title and category are not null.

In the CREATE TABLE command above, include the constraint that the ISBN is a foreign key referencing the ISBN in the books table.

CREATE TABLE NEWPUBLISHERS
(
pub_id NUMBER(10),
name VARCHAR2(25),
contact NUMBER(10),
category VARCHAR2(25) NOT NULL,
ISBN NUMBER(13),
title VARCHAR2(50) NOT NULL,
CONSTRAINT pk_newpublishers PRIMARY KEY (pub_id),
CONSTRAINT fk_newpublishers FOREIGN KEY (ISBN) REFERENCES books(ISBN)
);

Note: I have created the table and assigned constraints as specified by you. you have not provided the datatypes of books and publisher table so I have assumed them. kindly make the respective changes if there are different datatypes in the publisher and books table.

as you may see i have added 3 constraints, not null. we can add not null constraint just after the declaration of the column

eg: category varchar2(25) not null

we may do the same with primary key and foreign key such as:

pub_id NUMBER(10) primary key

and

ISBN NUMBER(13) foreign key references books(isbn)

but this is not the generally used approach.

===========================================================================

In the table creation assignment you created a table called EMPLOYEES. Alter this table so that the SSN is the primary key

ALTER TABLE EMPLOYEES
ADD CONSTRAINT pk_employees PRIMARY KEY (SSN);

as table already exists so we are using alter table statement inorder to add a constraint.