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

  Knowledge and data warehousing

Design a dimensional model for analysing Purchases for Adventure Works Cycles and implement it as cubes using SQL Server Analysis Services. The AdventureWorks OLTP sample database is the data source for you BI analysis.

  Design a database schema

Design a Database schema

  Entity-relationship diagram

Create an entity-relationship diagram and design accompanying table layout using sound relational modeling practices and concepts.

  Implement a database of courses and students for a school

Implement a database of courses and students for a school.

  Prepare the e-r diagram for the movie database

Energy in the home, personal energy use and home energy efficiency and Efficient use of ‘waste' heat and renewable heat sources

  Design relation schemas for the entire database

Design relation schemas for the entire database.

  Prepare the relational schema for database

Prepare the relational schema for database

  Data modeling and normalization

Data Modeling and Normalization

  Use cases perform a requirements analysis for the case study

Use Cases Perform a requirements analysis for the Case Study

  Knowledge and data warehousing

Knowledge and Data Warehousing

  Stack and queue data structure

Identify and explain the differences between a stack and a queue data structure

  Practice on topic of normalization

Practice on topic of Normalization

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