Optimize the query in the select script using alter table

Assignment Help Database Management System
Reference no: EM13166207

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;

 

 

Reference no: EM13166207

Questions Cloud

Which pair is written with first member having the higher : Which pair is written with the first member having the higher boiling point?
Draw a lewis structure for h2nnh2 : Draw a Lewis Structure for C3O2. Draw a Lewis Structure for C2H3NO5
State what concentration of ca remains in solution : If 2.55 g of NaOH were added to a 100.0 mL solution containing 0.10 M Ca(NO3)2, what concentration of Ca 2+ remains in solution?
The grid is populated randomly : Initially, the grid is populated randomly with occupied and empty cells. Once the initial grid has been created, the program loops. Each iteration of the loop represents a tick or time step in the environment.
Optimize the query in the select script using alter table : 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.
What is the approximate ph after adding the sodium acetate : If you are given sodium acetate and asked to make a .5 M acetate buffer at pH 4.75, will you have to add acid, base, or nothing in order to achieve the proper pH? What is the approximate pH after adding the sodium acetate?
Consider the standard heats of formation : Consider the following standard heats of formation: Standard Heat of formations for the substances:CO2(g) = -393.5 kJ/mol PbO(s) = -151.6 kJ/mol CO(g)
Before each sort, write psudo-code : Ceate a single cpp ?le (FILE=MAIN2.cpp) containing all three elementry sorts(bubble, insertion, selection). Before each sort, write psudo-code and invarient analysis of the sort in block comment style. Add the code from 3.). Generate a list of 100..
How much potassium nitrate will perciapitate : A supersaturated solution of potassium nitrate is formed by adding 150 g KNO3 to 100 g water, heating until the solute completely dissolves is agitated, how much potassium nitrate will perciapitate.

Reviews

Write a Review

Database Management System Questions & Answers

  Prepare a database using microsoft access

Using Microsoft Access, prepare a database and save it as Acme Inc. Prepare the following tables: Employees and Products. Field names for Employees table are first name,

  Creating use case to describe typical sales process

Create use case to describe a typical sales process. Then make a sequence diagram for use case.

  Explain data for each candidate of eight constituencies

supplies % of votes each candidate is likely to receive, based on popularity rating. Actual number of votes received is that percentage of General votes. You should enter data for each candidate in each of the eight constituencies.

  Prove-leaves of binary search tree are located in bottom

Examples for small n are given bellow, where a small square box represents an unsuccessful search. Prove that leaves of any binary search tree are located in the bottom two levels.

  Dimensions and attributes in a star schema model

Explain the use of facts, dimensions and attributes in a star schema model. Explain the use of facts, dimensions and attributes in a star schema model.

  Er diagram of cardinality and modality

ER Diagram of cardinality and modality bank management system and discription of bank management system

  Converting user form into 1nf and 2nf

Complete database exercise by converting user form located the evaluation procedures section of the syllabus into 1NF and 2NF.

  Construct a data warehouse bus matrix

First construct a Data Warehouse Bus Matrix to identify the company's business processes and any likely Data Marts and design the star schema for any Data Marts you have identified.

  Develop view for sum of number ordered multiplied by price

Develop a view named OrdTot. It comprises the order number and order total for each order presently on file. (Order total is sum of the number ordered multiplied by quoted price.

  Select suitable statistical measure to compare consistency

Select an appropriate statistical measure to compare consistency of sales. Make the calculations and write a report. In your calculations, include the mean sales for each salesperson.

  Determine functional dependencies of table

Using your knowledge of Premiere Products, determine the functional dependencies that exist in the following table.

  Timetabling system - write an sql function

With the new UNSW timetabling system, the LIC of each course is required to specify what facilities they require in their classrooms as one of the inputs to the timetabling process. Write an SQL function to provide a list of rooms that contain a g..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd