Question

In: Computer Science

Part #2: Creating a table Background: Prior to storing data in a RDBMS, a table with...

Part #2: Creating a table

Background: Prior to storing data in a RDBMS, a table with suitable schema must be created.

Exercise: Create a table with your ID (e.g.: derricker) with the following procedure

  1. If needed, log onto MySQL RDBMS using the mysql command-line.
  2. Create a table to store person information (namely: id, name, and email) by appropriately changing ID in the following command:

mysql> CREATE TABLE id (

   id    INTEGER NOT NULL,

   name VARCHAR(64) NOT NULL,

   email VARCHAR(32) NOT NULL,

   PRIMARY KEY (id)

);

  1. If the table is successfully created, you should get the message "Query OK, 0 rows affected". If you get an error, get help from to resolve the error.

F

NOTE: You will need to complete this part of the exercises successfully prior to proceeding with remainder of this exercise. So, if you get error messages ensure you get help from your instructor to resolve the error.

Part #3: Insert some data into your table

Background: One of the key operations of working with a database is inserting new values into the database. This is accomplished using SQL insert statement.

Exercise: Insert sample data into your ID table that you created in the previous step with the following command:

  1. If needed, log onto MySQL RDBMS using the mysql command-line introduced earlier.
  2. Insert a row into the table using the SQL insert statement below:

INSERT INTO id (id, name, email) VALUES (100, 'John Doe', '[email protected]');

  1. Check to ensure that you get "Query OK, 1 row affected" as the response indicating 1 row was successfully inserted. If you get errors get help from your instructor to resolve the issue.
  2. Suitably modify the insert command to insert the following 3 rows to your table:

id

name

email

200

'Mary Doe'

[email protected]

300

'James Bond'

[email protected]

400

'Superman'

[email protected]

F

NOTE: You will need to complete this part of the exercises successfully prior to proceeding with remainder of this exercise. So if you get error messages ensure you get help from your instructor to resolve the error.

Part #4: Experiment with SQL queries

Background: Querying data using SQL involves coding suitable SELECT statements with necessary columns and conditions.

Exercise: Using the SELECT statements discussed in class, code the SQL statement for the following queries:

  1. Develop a SQL query to list all rows in your table (copy-paste your SQL statement and output in the space below):
  1. Develop a SQL query to list just name of persons with ID less than 400 (copy-paste your SQL statement and output in the space below):

  1. Develop a SQL query to list id and name of persons that have the word 'Doe' in their name using the LIKE comparison operator (copy-paste your SQL statement and output in the space below):

  1. Develop a SQL query to list id and name of persons, with data sorted by name (copy-paste your SQL statement and output in the space below):

Solutions

Expert Solution

1. To create a table, follow the table syntax in mysql.

Let the table name be Sam.

CREATE TABLE Sam
(SID int,Name varchar(64),Email varchar(32));

You will get a Query ok message.

I have inserted a sample extra data with the name samy.

INSERT into Sam(SID,Name,Email)Values('200','Mary Doe','[email protected]');

You will get a message 1 Row Affected once you insert data.

INSERT into Sam(SID,Name,Email)Values('300','James Bond','[email protected]');

You will get a message 1 Row Affected once you insert data.

INSERT into Sam(SID,Name,Email)Values('400','Superman','[email protected]');

You will get a message 1 Row Affected once you insert data.

To select all the rows from the statement, use the following code

SELECT * from Sam;

The result will show the table sam we created along with the data, I will upload the w3school try version output as i dont have mysql in my system.

To display only the names of person with id less than 400, run the following code.

SELECT Name from Sam where SID<'400';

The output will give the name of all except superman whose id is not less than 400. The single inverted coma is important, without it, the result will show all the table rows.

SELECT SID,Name from Sam where Name LIKE '%Doe';

The % operator is used to indicate any name with our match pattern Doe . Without this operator the result will show no match found.

Order by is the command used for sorting in mysql. The command is as follows.

SELECT Sid,Name FROM Sam ORDER BY Name;

Here the name is sorted.


Related Solutions

EXPERIMENT 2: CREATING A PHYLUM KEY Data Tables Table 2: Phylum Taxonomic Key Prorifera Cnideria Platyhelminthes...
EXPERIMENT 2: CREATING A PHYLUM KEY Data Tables Table 2: Phylum Taxonomic Key Prorifera Cnideria Platyhelminthes Annelida Arthropoda Mollusca Echinodermata Chordata Questions 4. Were any of the features used in more than one phyla? If so, give an example of an organism from each phyla that shares the feature. 5. List three features from Table 1 that describe a Monarch butterfly (Danaus plexippus). Using the features you listed, determine what phyla it is classified in. PLEASE TYPE ANSWERS
Part #4: Data normalization: Background: Data in a relational database is stored in a normalized form....
Part #4: Data normalization: Background: Data in a relational database is stored in a normalized form. Data normalization or just normalization is a strategy used to organize data into multiple related tables to reduce data redundancy while preserving data integrity. Exercise: Normalize the student data in the University table (sample data is shown further below) into 3 tables, namely, Student, Department, and Course. You do not need to populate data. Just illustrate the schema for the 3 tables. You may...
Discuss the use of datafile systems associated with data marts/data warehouses in a RDBMS platform. Write...
Discuss the use of datafile systems associated with data marts/data warehouses in a RDBMS platform. Write a minimum of three well-formed scholarly paragraphs that include a topic sentence, several body sentences (aim for three to five), and a closing, summary, or transition sentenc
What features of query cache or Data cache serve to improve RDBMS performance
What features of query cache or Data cache serve to improve RDBMS performance
The following table contains data for the U.S. balance of payments in a prior year. Answer...
The following table contains data for the U.S. balance of payments in a prior year. Answer the question on the basis of this information. All figures are in billions of dollars. U.S. goods exports +$793 U.S. goods imports -1573 U.S. exports of service +280 U.S. imports of services -222 Net investment income +5 Net transfers -81 Capital account -5 Foreign purchases of assets in the U.S. +1198 U.S. purchases of foreign assets -395 Refer to the table above. The data...
TABLE 2. ROTATION DATA FOR THE ANDROMEDA GALAXY TABLE 2. ROTATION DATA FOR THE ANDROMEDA GALAXY...
TABLE 2. ROTATION DATA FOR THE ANDROMEDA GALAXY TABLE 2. ROTATION DATA FOR THE ANDROMEDA GALAXY Radius (arcminutes) Orbital Velocity (km/s) Radius (pc) Orbital Period (years) Radius (AU) Total Mass ( billions of solar masses) 2 25 12 70 22 150 46 210 70 305 80 335 96 310 100 305 120 295 140 285 160 290 180 290 Fill in blanks please
For the solutions that you will prepare in Step 1 of Part 1 (using Table 2 data), calculate the [FeSCN2+]
PRE-LAB EXERCISE For the solutions that you will prepare in Step 1 of Part 1 (using Table 2 data), calculate the [FeSCN2+]. Presume that all of the SCN-ions react. In Part I of the experiment, mol of SCN = mol of FeSCN2+. You will need the calculated (FeSCN2+] in Step 6. Record these values in the grey rows in Table 1 and Table 1.1 in the Data and Calculations section Table 1 Concentration of [FeSCN2+) in the Test Standard Solutions Note: * Use...
QUESTION 2 Suppose you are creating a truth table with 3 inputs (a, b, and c)...
QUESTION 2 Suppose you are creating a truth table with 3 inputs (a, b, and c) and 1 output (F). If an 'x' symbol indicates "don't care" (the value of the input does not effect the output), how many input combinations are covered by the single row of a truth table shown below? a b c F x 1 x 1 - 1 - 2 - 3 - 4 - None of the above QUESTION 3 Suppose you have a...
State a data structure that is suitable for storing (i) the words in a dictionary to...
State a data structure that is suitable for storing (i) the words in a dictionary to facilitate searching (ii) the set of folders you have in your computer Explain your choices.
Let’s consider the following table storing the information about various dealers for various products. And it...
Let’s consider the following table storing the information about various dealers for various products. And it stores the dealer details along with the products we purchase from them and the product count. Dealer_ID Dealer_Name Product_ID Quantity D102 Jade Garden P121 66 D102 Jade Garden P103 188 D110 Tim Ho Wan P102 88 D105 Goose Manor P121 66 D104 Daikiya P110 288 D104 Daikiya P102 10 (a) Identify all Functional Dependencies for this relation. (4 points) (b) List all candidate keys...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT