Question

In: Computer Science

Create a table book_store with columns Book_id VARCHAR(255) NOT NULL, Book_Name VARCHAR(255) NOT NULL, Book_genre VARCHAR(255)...

Create a table book_store with columns Book_id VARCHAR(255) NOT NULL,

Book_Name VARCHAR(255) NOT NULL,

Book_genre VARCHAR(255) NOT NULL,

Status VARCHAR(255) NOT NULL,

PRIMARY KEY (Book_id)

Create a table book with columns Book_id VARCHAR(255) NOT NULL,

Book_Name VARCHAR(255) NOT NULL,

Book_release integer,

Book_price integer ,

Publisher Varchar(10),

Book_genre VARCHAR(255) NOT NULL,

PRIMARY KEY (Book_id)

CREATE TABLE price_logs with columns id INT(11) NOT NULL AUTO_INCREMENT,

Book_id VARCHAR(255) NOT NULL,

Old_Book_price DOUBLE NOT NULL,

New_Book_price DOUBLE NOT NULL,

updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

updated_by varchar(30) NOT NULL,

PRIMARY KEY (id),

KEY Book (Book_id),

CONSTRAINT price_logs_ibfk_1 FOREIGN KEY (Book_id) REFERENCES Book (Book_id) ON DELETE CASCADE ON UPDATE CASCADE

4. Stored Procedure:

Return only top 3 when parameter TOP3 is passed, top 5 when TOP5 is passed else print entire book table.

DELIMITER //

CREATE PROCEDURE GetBooks( all_books varchar(10) )

BEGIN

<Write your code here >

END IF;

END // DELIMITER ;

call the procedure:

CALL GetBooks('ALL');

CALL GetBooks('TOP3');

CALL GetBooks('TOP5');

Solutions

Expert Solution

Create a table book_store with columns

create table book_store(

Book_id VARCHAR(255) NOT NULL,

Book_Name VARCHAR(255) NOT NULL,

Book_genre VARCHAR(255) NOT NULL,

Status VARCHAR(255) NOT NULL,

PRIMARY KEY (Book_id)
);

Create a table book with columns

create table book(
Book_id VARCHAR(255) NOT NULL,

Book_Name VARCHAR(255) NOT NULL,

Book_release integer,

Book_price integer ,

Publisher Varchar(10),

Book_genre VARCHAR(255) NOT NULL,

PRIMARY KEY (Book_id)
);

CREATE TABLE price_logs with columns

create table price_logs(
id INT(11) NOT NULL AUTO_INCREMENT,

Book_id VARCHAR(255) NOT NULL,

Old_Book_price DOUBLE NOT NULL,

New_Book_price DOUBLE NOT NULL,

updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

updated_by varchar(30) NOT NULL,

PRIMARY KEY (id),

KEY Book (Book_id),

CONSTRAINT price_logs_ibfk_1 FOREIGN KEY (Book_id) REFERENCES Book (Book_id) ON DELETE CASCADE ON UPDATE CASCADE
);

STORED PROCEDURE CODE:

This portion to be written in place of <Write your code here >

IF all_books = 3 THEN
SELECT * FROM book LIMIT 3;
ELSIF all_books = 5 THEN
SELECT * FROM book LIMIT 5;
ELSE
SELECT * FROM book;
END IF;

For any doubts feel free to ask.


Related Solutions

CREATE TABLE youtubevideos( url VARCHAR(150), title VARCHAR(50), description VARCHAR(200), comid INTEGER NOT NULL, postuserVARCHAR(50) NOT NULL,...
CREATE TABLE youtubevideos( url VARCHAR(150), title VARCHAR(50), description VARCHAR(200), comid INTEGER NOT NULL, postuserVARCHAR(50) NOT NULL, postdate DATE, PRIMARY KEY (email), FOREIGN KEY (comid) REFERENCES Comedians(comid), FOREIGN KEY (postuser) REFERENCES Users(email)); CREATE TABLE Users( email VARCHAR(50), password VARCHAR(50), firstname VARCHAR(50), lastname VARCHAR(50), gender CHAR(1), age INTEGER, PRIMARY KEY (email)); CREATE TABLE Comedians( comid INTEGER, firstname VARCHAR(50), lastname VARCHAR(50), birthday DATE, VARCHAR(50), PRIMARY KEY(comid)); CREATE TABLE Reviews( reviewid INTEGER NOT NULL AUTO_INCREMENT, remark VARCHAR(100), rating CHAR(1), //P.F.G.E author VARCHAR(50) NOT NULL,...
CREATE TABLE Branch ( branchNo VARCHAR(4), address VARCHAR(50), city VARCHAR(30), state VARCHAR(2), phone VARCHAR(20), PRIMARY KEY...
CREATE TABLE Branch ( branchNo VARCHAR(4), address VARCHAR(50), city VARCHAR(30), state VARCHAR(2), phone VARCHAR(20), PRIMARY KEY (branchNo)); INSERT INTO Branch VALUES('B001','366 Tiger Ln','Los Angeles','CA','213-539-8600'); INSERT INTO Branch VALUES('B002','18 Harrison Rd','New Haven','CT','203-444-1818'); INSERT INTO Branch VALUES('B003','55 Waydell St','Essex','NJ','201-700-7007'); INSERT INTO Branch VALUES('B004','22 Canal St','New York','NY','212-055-9000'); INSERT INTO Branch VALUES('B005','1725 Roosevelt Ave','Queens','NY','718-963-8100'); INSERT INTO Branch VALUES('B006','1471 Jerrold Ave','Philadelphia','PA','267-222-5252'); CREATE TABLE Staff ( staffNo VARCHAR(4), fName VARCHAR(20), lName VARCHAR(20), position VARCHAR(20), sex VARCHAR(1), age INTEGER, salary NUMBER(8,2), phone VARCHAR(20), address VARCHAR(50), city VARCHAR(20),...
This is the database CREATE TABLE AIRCRAFT ( AC_NUMBER varchar(5) primary key, MOD_CODE varchar(10), AC_TTAF double,...
This is the database CREATE TABLE AIRCRAFT ( AC_NUMBER varchar(5) primary key, MOD_CODE varchar(10), AC_TTAF double, AC_TTEL double, AC_TTER double ); INSERT INTO AIRCRAFT VALUES('1484P','PA23-250',1833.1,1833.1,101.8); INSERT INTO AIRCRAFT VALUES('2289L','DC-90A',4243.8,768.9,1123.4); INSERT INTO AIRCRAFT VALUES('2778V','MA23-350',7992.9,1513.1,789.5); INSERT INTO AIRCRAFT VALUES('4278Y','PA31-950',2147.3,622.1,243.2); /* -- */ CREATE TABLE CHARTER ( CHAR_TRIP int primary key, CHAR_DATE date, AC_NUMBER varchar(5), CHAR_DESTINATION varchar(3), CHAR_DISTANCE double, CHAR_HOURS_FLOWN double, CHAR_HOURS_WAIT double, CHAR_TOT_CHG double, CHAR_OIL_QTS int, CUS_CODE int, foreign key (AC_NUMBER) references AIRCRAFT(AC_NUMBER) ); INSERT INTO CHARTER VALUES(10001,'2008-02-05','2289L','ATL',936,5.1,2.2,354.1,1,10011); INSERT INTO CHARTER VALUES(10002,'2008-02-05','2778V','BNA',320,1.6,0,72.6,0,10016);...
Consider the following table definitions create table node( node_id integer primary key, node_color varchar(10)); create table...
Consider the following table definitions create table node( node_id integer primary key, node_color varchar(10)); create table edge( edge_id integer primary key, origin_id integer, destination_id integer, foreign key (origin_id) references node(node_id), foreign key (destination_id) references node(node_id)); What is the result of the following query? select node_id, node_color, destination_id from node, edge; An inner join of the tables node and edge that lists origin node_id and node_color together with the node_id of the destination node for all those nodes that have outgoing...
USE SQL CREATE TABLE IF NOT EXISTS football_games ( visitor_name VARCHAR(30),       /* Name of the visiting...
USE SQL CREATE TABLE IF NOT EXISTS football_games ( visitor_name VARCHAR(30),       /* Name of the visiting team                     */ home_score SMALLINT NOT NULL,   /* Final score of the game for the Buffs         */ visitor_score SMALLINT NOT NULL,/* Final score of the game for the visiting team */ game_date DATE NOT NULL,        /* Date of the game                              */ players INT[] NOT NULL,         /* This array consists of the football player ids (basically a foreign key to the football_player.id) */ PRIMARY KEY(visitor_name, game_date)...
create table node( node_id integer primary key, node_color varchar(10)); create table edge( edge_id integer primary key,...
create table node( node_id integer primary key, node_color varchar(10)); create table edge( edge_id integer primary key, origin_id integer, destination_id integer, foreign key (origin_id) references node(node_id), foreign key (destination_id) references node(node_id)); write an SQL query that lists all those nodes that have edges with a destination node that has color 'red'.
Create a table showing the payment of a mortgage of $239,000 month by month. Create columns...
Create a table showing the payment of a mortgage of $239,000 month by month. Create columns for: - Time (in years) - Interest (for that month) - Payment (always the same value) - Payment against principal - Remaining Principal The mortgage is to last 33 years, and the nominal interest rate is 6.03% (a) What is the monthly payment? (b) What is the interest paid at the end of the 9th month? (c) How much of the principal is paid...
1. Write the statements to create a table named REQUIREMENTS. The table has the following columns:...
1. Write the statements to create a table named REQUIREMENTS. The table has the following columns: credits number (primary key) and degree name. 2. Write the statements to create a table named CANDIDATE with the following columns names. Pick the best column type: student_id, first name, last name, credits and graduation date. The credits column is a foreign key to the credits column in the REQUIREMENTS table. 3. Write the statement(s) to Insert 2 rows in your REQUIREMENTS table. Make...
CREATE TABLE DRIVER( ENUM         DECIMAL(12) NOT NULL, LNUM         DECIMAL(8)    NOT NULL,...
CREATE TABLE DRIVER( ENUM         DECIMAL(12) NOT NULL, LNUM         DECIMAL(8)    NOT NULL, STATUS         VARCHAR(10) NOT NULL, CONSTRAINT DRIVER_PKEY PRIMARY KEY(ENUM), CONSTRAINT DRIVER_UNIQUE UNIQUE(LNUM), CONSTRAINT DRIVER_FKEY FOREIGN KEY(ENUM) REFERENCES EMPLOYEE(ENUM), CONSTRAINT DRIVER_STATUS CHECK ( STATUS IN ('AVAILABLE', 'BUSY', 'ON LEAVE')) ); (1)   Modify a consistency constraint of the sample database such that after a modification         it is possible to record in the database information about the drivers who are sick.   */ CREATE TABLE TRUCK(...
Create a table with two columns. Name the table First Initial _ Last Name (e.g. John...
Create a table with two columns. Name the table First Initial _ Last Name (e.g. John Dow will create table j_dow). You have to audit all DML statements on your table. To do this you write two triggers: 1. To log any DML statements that users might run on this table. The results must be stored in the First Initial _ Last Name _ Log table (e.g. John Dow will create table j_dow_log). The table should have unique event ID,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT