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

  Write table in dbdl notation after applying methodology

Proceed with all steps in information-level design to add this user view to existing cumulative design. Is this table in1st NF?___No____ . If Yes skip. If not, write Table in DBDL notation after applying the methodology we use for converting into 1NF..

  Write sql statement to retrieve all data sorted in order

Generate the view called RepairSummary which shows only RepairInvoiceNumber, TotalCost, and TotalPaid. Illustrate the SQL statement to retrieve all RepairSummary data sorted by TotalCost.

  Determine the cartesian product of sets

Determine the Cartesian product (A X B) of the given pair of sets. A => Set of first letter of names of countries = A = { R, S, T } B => Set of numbers denoting Postal codes = B = { 0001, 1001}.

  Produce budget reports for department at university

Consider system which produces budget reports for department at university. For whichever system you select, answer the following design questions. Who will use output?

  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.

  Design database design for boingx aircraft company

You have been asked to design database design for BoingX Aircraft Company (BAC), that has two products: TRX-5A and TRX-5B HUD (heads-up display) units.

  Same name to attributes which are in different tables

What about giving same name to attributes which are in different tables but are not same? For instance, "Description" in both a Course table and a Classroom table.

  Decompose relation into relations which are in bcnf

it is not essential to give violations which have more than one attribute on right side. Decompose the relation, as essential, into collection of relations which are in BCNF.

  Explaining emp table does not have assigned primary key

Developers have noticed that EMP table doesn't have an assigned primary key. EMP_ID column has been selected to be the primary key.

  Write problems and issues related with internet databases

Write down some of problems and issues related with internet databases? Consider security, performance, architecture issues.

  Entity-relationship diagram

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

  Describe the content, purpose, user access methods

describe the content, purpose, user access methods, and sources of data

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