Docsity

Assignment 1 - Database Design - Spring 2008 | CMSC 424, Assignments of Principles of Database Management

Toggle sidebar
bg1
1
CMSC424 – Database Design
SQL Assignment (Parts A and B)
Spring 2008
Prof. Mihai Pop
TA: Sharath Srinivas
Part A Due Date: Feb 19, before 11:59 PM
Part B Due Date: Feb 26, before 11:59 PM
• The assignment is to be done by yourself.
• To start with, log in to a grace machine, run ”tap oraclient”. The SID is
”dbclass1”. This will initialize the environmental variables. Then run ”sqlplus”,
and log in using the user/password emailed to you. You can now start using it.
• Data: The dataset contains geographical information about the countries of the
world. The information was collected from several web sources, with the CIA
World Factbook (https://www.cia.gov/library/publications/the-world-factbook/)
being the prominent source.
• Schema Information: There are 16 tables in the schema. Most of the table and
column names are self-explanatory. The Schema diagram is provided on page 5
and 6 of this document. The ER diagram is provided on page 7. An appendix
which lists the meanings of the columns of the tables is on page 8, 9 and 10.
• Assumptions and Instructions:
1. The database has several geographical inaccuracies. But, for the questions in
this assignment it is sufficient if your answers are consistent with the
supplied dataset, even if they are not geographically correct.
2. Answer to the questions 1-16 must be a single query. You can make use of
temporary tables and nested sub-queries, but you cannot make use of two
different queries to solve one question. For questions 17-20, there is no
restriction on the number of queries you can use.
3. The country codes cannot be used for querying any of the tables. E.g., In the
“Economy” table the column “Country” is actually the country code and not
the name of the country. So, if you have to find the GDP of France, you
should make use of the “Country” table to get the code corresponding to
France and then use that code to retrieve the GDP of France from the
“Economy” table.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Assignment 1 - Database Design - Spring 2008 | CMSC 424 and more Assignments Principles of Database Management in PDF only on Docsity!

CMSC424 – Database Design

SQL Assignment (Parts A and B)

Spring 2008

Prof. Mihai Pop

TA: Sharath Srinivas

Part A Due Date: Feb 19, before 11:59 PM Part B Due Date: Feb 26, before 11:59 PM

  • The assignment is to be done by yourself.
  • To start with, log in to a grace machine, run ”tap oraclient”. The SID is ”dbclass1”. This will initialize the environmental variables. Then run ”sqlplus”, and log in using the user/password emailed to you. You can now start using it.
  • Data : The dataset contains geographical information about the countries of the world. The information was collected from several web sources, with the CIA World Factbook (https://www.cia.gov/library/publications/the-world-factbook/) being the prominent source.
  • Schema Information: There are 16 tables in the schema. Most of the table and column names are self-explanatory. The Schema diagram is provided on page 5 and 6 of this document. The ER diagram is provided on page 7. An appendix which lists the meanings of the columns of the tables is on page 8, 9 and 10.
  • Assumptions and Instructions:
    1. The database has several geographical inaccuracies. But, for the questions in this assignment it is sufficient if your answers are consistent with the supplied dataset, even if they are not geographically correct.
    2. Answer to the questions 1-16 must be a single query. You can make use of temporary tables and nested sub-queries, but you cannot make use of two different queries to solve one question. For questions 17-20, there is no restriction on the number of queries you can use.
    3. The country codes cannot be used for querying any of the tables. E.g., In the “Economy” table the column “Country” is actually the country code and not the name of the country. So, if you have to find the GDP of France, you should make use of the “Country” table to get the code corresponding to France and then use that code to retrieve the GDP of France from the “Economy” table.
  1. The string literals are case sensitive. In order to query on them make use of the SQL “LIKE” condition and the string enclosed within single quotes. The “%” symbol can be used as a wild card. E.g., select * from country where name like 'United States%';
  • Instructions to load the data: A compressed file containing the dataset and the instructions for loading it into Oracle will be provided. Go through the README file in dataset.tar.gz for instructions to load the data.
  • How to hand in your work: You should be making two separate submissions, one for Part A and one for Part B. Please included solutions to all the problems in a file named -A.sql for Part A, and a file named -B.sql for Part B. Use SQL-style comments at the start of each query to specify what question the query will solve. IMPORTANT: If you do not signify what problem a query addresses, you will receive no points for that query. Aside from comments made inline with your SQL queries, all other comments or notes to the TA should be made in a file named README. Do not include a spool of the output of your queries, we will run your queries to generate the output. You should probably only need to submit at most two files (the README and the file containing your SQL queries). Compress your files using tar, gzip, etc. Call your submission -sqlA.tar.gz (or whatever extension matches the compression method you used) for Part A, and - sqlB.tar.gz (or whatever) for Part B. Email your submission to [email protected]. Part A (4 pts each = 40 pts)
  1. Write a query to change your Oracle password. When submitting the answer, don’t write the new password (write ”****” instead).
  2. Figure out how to find out all the attributes and their types for a give table in SQL*Plus and write down the statements and the result on the “Organization” table. This kind of a statement is usually unique to the client, and is not part of standard SQL.
  3. Write a query to display the names, capitals and the population of all the countries in the world.
  4. Find the countries with the highest and the lowest population. The result should include the country name and its population.
  5. For all the cities in the world that are capitals of some country, display their longitude and latitude.
  1. Write a query to create a table “EURO_PERCENTAGE” with the following schema: Name Percentage Meaning of the columns: Name : Name of the country that lies within Europe Percentage : Percentage of Europe’s population living in that country. E.g., 10.55% of Europe’s population lives in Germany. This table lists only those countries that lie entirely or have at least some part of their territory within Europe. Further, for those countries that lie partially in Europe, you might assume that their entire population resides within the European border of that country.
  2. Find the countries that are 3 hops away from Turkey. (A country is one hop away from another country if they share a common border)
  3. Write a query to find the total number of people living in Asia. You can assume that the population of the countries is uniformly distributed. E.g., If 80% of Russian territory is inside Asia, you can assume that 80% of Russians live in Asia.

Schema Diagram

Country: City: Name Country Province Population Longitude Latitude Province: Economy: Population: Continent: borders: encompasses: Organization: Name Code Capital Province Area Population Name Country Population Area Capital CapProv Country GDP Agriculture Service Industry Inflation Country Population Infant_Mortality Name Area Country1 Country2 Length Country Continent Percetage Abbreviation Name City Country Province Established

E-R diagram

Appendix: Meanings of the database columns

Country: The countries of the world with some data. Name: The country name. Code: The country code Capital: The name of the capital Province: The province where the capital belongs to Area: The total area Population: The total population City: information about cities. Name: the name of the city Country: the country code where it belongs to Province: the name of the province where it belongs to Population: the population of the city Longitude: geographic longitude Latitude: geographic latitude Province: information about administrative divisions Name: the name of the administrative division Country: the country code where it belongs to Area: the total area of the province Population: population of the province Capital: the name of the capital Capprov: the name of the province where the capital belongs to Note that capprov is not necessarily the same as name. E.g., the municipality of Bagota ( Columbia) is a province of its own, and Bagota is the capital of the surrounding province Cudinamarca. Economy: economical information about the countries Country: the country code GDP: gross domestic product Agriculture: % of agriculture of the GDP Service: % of services of the GDP Industry: % of industry of the GDP Inflation: inflation rate (per annum) Population: information about the population of the countries Country: The country code Population_growth: population growth rate per annum (%) Infant_mortality: infant mortality (per 1000) Borders: i nformation about neighboring countries. Note that in this relation, for every pair of neighboring countries (A,B), only one tuple is given- thus the relation is not symmetric.

Analogous for geo_river merges_with: information about neighboring seas sea1: a sea sea2: a sea located: information about cities located at rivers, lakes and seas city: the name of the city country: the country code where the city belongs to province: the province where the city belongs to river: the river where it is located at lake: the lake where it is located at sea: the sea where it is located at Note that for a given city, there can be several lakes/seas/rivers where it is located at.