Question

In: Computer Science

Question 1 – Inserting data to the CITY table Using the following DML statement: INSERT INTO...

Question 1 – Inserting data to the CITY table

Using the following DML statement:

INSERT INTO CITY (id, name, countrycode, district, population) VALUES (7000, ‘Guelph’, ‘CAN’, ‘Ontario’, 131794);

Query the CITY table to ensure this row was inserted correctly.

Provide screenshot of your ‘SELECT statement’ and resultset pane here

               Insert another row into the CITY table with the following values:

                              Id                           7002

                              Name                   Montebello

                              Countrycode       CAN

                              District                 Quebec

                              Population          983

Provide screenshot of your ‘INSERT statement’ and resultset pane here

Question 2 – Insert data to COUNTRY table

               Insert a row into the COUNTRY table with the following values:

                              Code                     SRB

                              Name                   Serbia

                              Continent            Europe

                              Region                 Eastern Europe

                              Surface Area       88361

                              IndepYear            2006

                              Population          6963764

Provide screenshot of your ‘INSERT statement’ and resultset pane here

Question 3 – Incorrect SQL statement

There are syntax errors in the following SQL statement.   Correct and execute the corrected SQL statement.

INSERT INTO Country( Code, Name, Continent, Region, SurfaceArea, IndepYear, Population )

VALUES( 'MNE, 'Montenegro', 'Europe', 'Eastern Europe' 13812, 2006, 622359 );

Provide screenshot of your ‘INSERT statement’ and resultset pane here

Question 4 – Update a row in COUNTRY table

It is often necessary to query the data to determine how best to filter on the correct row (s) to update.   Using the Select * from COUNTRY will display all the data and then you see all the data.

               Update the column – governmentform changing the value from Serbia to Republic

              But only for the country named Serbia

Note: this query should only update a single row

Provide screenshot of your ‘UPDATE statement’ and resultset pane here

Question 5 – Update a row in COUNTRY table

This ‘update’ is meant to change the ‘population’ of Canada to 37971020

Provide screenshot of your ‘UPDATE statement’ and resultset pane here

Question 6 – Deleting rows in the COUNTRYLANGUAGE table

Create the SQL statement which will delete any rows in COUNTRYLANGUAGE table where country is Canada.   Hint, you should see twelve (12) rows and its is best when ‘deleting’ data, to always query the data using the filter before running the ‘delete’ statement.

Provide screenshot of your ‘UPDATE statement’ and resultset pane here

Question 7 – Deleting rows in a table

Modify the data in the COUNTRYLANGUAGE table using the script provided – CanadianLanguages2020.sql

Once you have executed this script, write a query statement that will list all rows which have English and French as languages.

Provide screenshot of your ‘SELECT statement’ and resultset pane here

Question 8 – Updating the Official Language for Canada

Modify the rows in the COUNTRYLANGUAGE table so that all rows associated to Canada has their ‘isofficial’ indicator column set to one(1).

Provide screenshot of your ‘UPDATE statement’ and resultset pane here

Question 9 – Updating more than one column using a single SQL statement

Write a single SQL statement to change the population of Algeria to 43600000 and gnp to 684689.

Provide screenshot of your ‘UPDATE statement’ and resultset pane here

Solutions

Expert Solution

Below are the answers

Note as Table structire was not given, created my sample table strcture and executed the queries

Question 1

INSERT INTO CITY (id, name, countrycode, district, population) VALUES (7000, ‘Guelph’, ‘CAN’, ‘Ontario’, 131794);

Below is the screenshot of select statement

INSERT INTO CITY (id, name, countrycode, district, population) VALUES (7002, 'Montebello', 'CAN', 'Quebec', 983);

Below is the screenshot after inserting city with id 7002

**********************************************************************************

Question 2

Inserting data with given values

Insert

Result of inserted row

**********************************************************************************

Question 3

Correct insert query after fixing the eerors

INSERT INTO Country( Code, Name, Continent, Region, SurfaceArea, IndepYear, Population )

VALUES( 'MNE', 'Montenegro', 'Europe', 'Eastern Europe', 13812, 2006, 622359 );

Explanation end quate was missing after MNE – It should be 'MNE' and comma was missing after 'Eastern Europe'

**********************************************************************************

Question 4 -

Ans - Update Country set governmentform = 'Republic' where Name = 'Serbia'

Explanation

As above Country table was not having column governmentfrom column so aaded governmentfrom to the Country table for updating the same.

Below is the sample records in country table before updating governmentfrom

Update the column –   changing the value from Serbia to Republic. But only for the country named Serbia

Below is the update statement

Update Country set governmentform = 'Republic' where Name = 'Serbia'

Below is the screenshot

Below is the result after updation

**********************************************************************************

Question 5 -

Answer - Update country set Population = 37971020 where Name = 'Canada'

Explanation

Before updating the population

Update statement - Update country set Population = 37971020 where Name = 'Canada'

Below is the screenshot

Below is the screenshot of updated population for Canada

**********************************************************************************

Question 6 -

Answer - DELETE FROM COUNTRYLANGUAGE WHERE country='Canada'

Explanation

As COUNTRYLANGUAGE structure is not given so created sample COUNTRYLANGUAGE table with 2 columns LanguageId and country.

Before delete query below is the COUNTRYLANGUAGE table data

After delete query

DELETE FROM COUNTRYLANGUAGE WHERE country='Canada'

Below is the screenshot after delete query

**********************************************************************************

Question 7

Answer - select * from COUNTRYLANGUAGE where Language in ('English', 'French')

As table structure is not there assumed table structure with 2 columns Language and Country.

Below is the all record

Ans - select * from COUNTRYLANGUAGE where Language in ('English', 'French')

OR - select * from COUNTRYLANGUAGE where Language = 'English' or Language = 'French'

Output

**********************************************************************************

Question 8

Answer -

Update COUNTRYLANGUAGE

SET isofficial =

CASE WHEN Country = 'Canada' THEN 1

ELSE 0

END

****************************************************************************************

Question 9

Answer -

UPDATE country

   SET Population = CASE Name

                      WHEN 'Algeria' THEN 43600000

                      WHEN 'gnp' THEN 684689

                      ELSE Population

                      END

WHERE Name IN('Algeria', 'gnp');

Note for question 8 and 9 use queries as per your table structure. Use column names as per your table structure. As required table structure i don;t know so given the generic queries.


Related Solutions

DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as if it were being added to MySQL (please give explanations for each line of SQL code and a copy of the code as it would be entered into the query by itself: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
Question 1. Write the statement to increase the invoice_total by 25% using the INVOICES table for...
Question 1. Write the statement to increase the invoice_total by 25% using the INVOICES table for all vendors whose vendor_id is less than 100. Question 2. Write the statement to answer the following question: What is the total of the invoice_total amounts after the update. I need your statement and the result stated here. Question 3. Write the statements to list the customer ID and Order ID from the ORDERS table for all orders with order id greater than 700....
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
Using the data in the following? table, and the fact that the correlation of A and...
Using the data in the following? table, and the fact that the correlation of A and B is 0.02?, calculate the volatility? (standard deviation) of a portfolio that is 80% invested in stock A and 20% invested in stock B.              Stock A   Stock B 2005       -12           16 2006        13           20 2007          8           7 2008         -1         -1 2009          5        -12 2010          6          15 The standard deviation of the portfolio is?
Using the data in the following​ table, and the fact that the correlation of A and...
Using the data in the following​ table, and the fact that the correlation of A and B is 0.32​, calculate the volatility​ (standard deviation) of a portfolio that is 80% invested in stock A and 20% invested in stock B.    Stock A   Stock B 2005   -4   28 2006   19   20 2007   3   8 2008   -1   -8 2009   5   -9 2010   13   30
Using the data in the following​ table, and the fact that the correlation of A and...
Using the data in the following​ table, and the fact that the correlation of A and B is 0.39​, calculate the volatility​ (standard deviation) of a portfolio that is 70% invested in stock A and 30% invested in stock B. Realized Returns Year Stock A Stock B 2008 −8​% 27​% 2009 17​% 28​% 2010 1​% 11​% 2011 −3​% −2​% 2012 1​% −3​% 2013 8​% 26​% The standard deviation of the portfolio is _%?
All the question should be solved using IF statement Q1) List the Full Name, the city,...
All the question should be solved using IF statement Q1) List the Full Name, the city, and the state of all members, and order them by their first name in descending order (Z-A) if they are from 'KY' or by their last name in ascending order (A-Z) when they are from 'TN' state. Q2) List the total number of movies for each genre (FAMILY, ACTION, DRAMA, COMEDY). - Comment the following two lines if creating database in Mimir or Bluenose...
Valuation Using Income Statement Multiples The following table provides summary data for Target and its competitors,...
Valuation Using Income Statement Multiples The following table provides summary data for Target and its competitors, Kohl's and Wal-Mart. (in millions) Target Kohl's Wal-Mart Company assumed value -- $23,098 $237,306 Equity assumed value -- $22,470 $198,288 NOPAT $3,159 $1,152 $13,354 Net income $2,787 $1,109 $12,178 Net nonoperating obligations (assets) $10,109 $628 $39,018 Common shares outstanding 860 shares 321 shares 41 shares (a) Compute the price to NOPAT ratio for both Kohl's and Wal-Mart. Round your answers to two decimal places....
Question: Consider the following variation of insertion sort: For 1 ≤ i < n, to insert...
Question: Consider the following variation of insertion sort: For 1 ≤ i < n, to insert the element A[i] among A[0] ≤ A[1] ≤ … ≤ A[i-1], do a binary search to find the correct position for A[i]. a. How many key comparisons would be done in the worst case? b. How many times are elements moved in the worst case? c. What is the asymptotic order of the worst case running time?
Using the income statement, calculate the vertical and horizontal analysis and insert your answers in the...
Using the income statement, calculate the vertical and horizontal analysis and insert your answers in the appropriate spaces provided VERTICAL ANALYSIS HORIZONTAL ANALYSIS Statement of Operations Income Statement 2017 Percent 2018 percent CHANGE PERCENT Sales (net) 8,100,000 10,000,000 Cost of goods sold 5,300,000 6,000,000 Gross Margin 2,800,000 4,000,000 General Expense (1,050,000.00) (1,080,000) Depreciation Expense (300,000.00) (300,000) Operating Income 1,450,000.00 2,620,000 Interest Expense (40,000.00) (50,000) Income Taxes (35%) (507,500.00) (917,000.00) Net Income 902,500.00 1,653,000
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT