Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask DBMS Expert


Home >> DBMS

optimize the query in the select script using Alter Table to add appropriate indexes. Also use Optimize and Explain to show how the performance of this query has improved.

How can we Keep Optimizing??

CREATE TABLE Cities

(

CityID SMALLINT NOT NULL PRIMARY KEY,

CityName VARCHAR(20) NOT NULL

)

ENGINE=INNODB;

 

 

INSERT INTO Cities

VALUES (101, 'Seattle'), (102, 'Redmond'), (103, 'Bellevue'),

(104, 'Kent'), (105, 'Kirkland');

 

CREATE TABLE Customers

(

CustID SMALLINT NOT NULL PRIMARY KEY,

CustFN VARCHAR(20) NOT NULL,

CustMN VARCHAR(20) NULL,

CustLN VARCHAR(20) NOT NULL

)

ENGINE=INNODB;

 

INSERT INTO Customers (CustID, CustFN, CustMN, CustLN)

VALUES (1,'Ralph', 'Frederick', 'Johnson'),

(2,'Hubert', 'T.', 'Weatherby'),

(3,'Anne', NULL, 'Thomas'),

(4,'Mona', 'J.', 'Cavenaugh'),

(5,'Peter', NULL, 'Taylor'),

(6,'Ginger', 'Meagan', 'Delaney');

 

CREATE TABLE CustCity

(

CustID SMALLINT NOT NULL,

CityID SMALLINT NOT NULL

)

ENGINE=INNODB;

 

 

INSERT INTO CustCity

VALUES (1, 104), (2, 101), (3, 104),

(4, 103), (5, 102), (6, 105);

 

SELECT CustLN, CityName

FROM Customers AS cu, CustCity AS cc, Cities AS ci

WHERE cu.CustID=cc.CustID AND ci.CityID=cc.CityID

AND CityName = 'Kent' ;

 

--------------------------------------

 

--------------------------------------

 

EXPLAIN SELECT CustLN, CityName

FROM Customers AS cu, CustCity AS cc, Cities AS ci

WHERE cu.CustID=cc.CustID AND ci.CityID=cc.CityID;

 

ALTER TABLE CustCity ADD PRIMARY KEY (CustID, CityID),

ADD FOREIGN KEY (CustID) REFERENCES Customers (CustID),

ADD FOREIGN KEY (CityID) REFERENCES Cities (CityID);

 

OPTIMIZE TABLE CustCity;

 

EXPLAIN SELECT CustLN, CityName

FROM Customers AS cu, CustCity AS cc, Cities AS ci

WHERE cu.CustID=cc.CustID AND ci.CityID=cc.CityID;

 

 

DBMS, Programming

  • Category:- DBMS
  • Reference No.:- M9456325

Have any Question?


Related Questions in DBMS

Assignment -scenario setup a mock phase 3 clinical trial

Assignment - Scenario: Setup a Mock Phase 3 Clinical Trial for evaluating the efficacy of a Blood Pressure/Weight Loss/ or Muscle Strength Enhancement supplement. Assume that the testing takes place at a physician's offi ...

Stored procedure please create the following stored

Stored procedure. Please create the following stored routines using CPS3740_2017S database using the tables in dreamhome database. xxxx is your email id 1) Implement a stored procedure p3Q21_xxxx to display the Branch ci ...

Assignment task -write and run sql statements to complete

Assignment Task - Write and run SQL statements to complete the following tasks Part A - DML 1. Show the details of the products where the product code starts with '22'. 2. Display the vendor details from areacode 615. 3. ...

Database and information retrieval assignment - data

Database and Information Retrieval Assignment - Data Privacy Essay Task - Write an essay (aim for 750 words) that addresses issues associated with data proivacy. Use the Australian Privacy Principles - discussed in class ...

Solve the following questions using oracle you are not

Solve the following questions using Oracle. You are not allowed to use the syntax of any DBMS other than Oracle. Make sure to upload an electronic copy of your solution to your CSC335 TRACE folder. Name the file hw4.sql. ...

In sql database questions phase-1 in 100 words what steps

In SQL Database Questions: Phase-1 In 100 words, what steps can one take to avoid losing work? Which command is used to save changes to the database? What is the syntax for this command? Phase-2 In 100 words, explain the ...

Question 1 describe 1nf 2nf 3nf2 explain why 4nf is a

Question: 1: Describe 1NF, 2NF, 3NF. 2: Explain why 4NF is a normal form more desirable than BCNF. The response must be typed, single spaced, must be in times new roman font (size 12) and must follow the APA format.

Database design amp development assignment -assignment

Database Design & Development Assignment - Assignment title - Design and Implement a Relational Database for a local Print and Ink Refill Business. Learning Outcome - Use an appropriate design tool to design a relational ...

Football association of zambia faz super leaguethe faz has

Football Association of Zambia (FAZ) Super League The FAZ has recently decided to reorganise their operations to support both existing and possibly expanded league operations in Zambia and part of preparation for the 201 ...

Sqlquery 1 how many products have standard price less than

SQL Query 1. How many products have standard price less than 1000? Query 2: Display all attributes for products made of "Cherry" from Product table w/o referring to column names. Query 3: Display all product names having ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As