16
Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ Page | 1 The short answer questions will be spot checked and graded for completion, but not checked for accuracy. I encourage you to form a study group; get together to prepare for exams. Once your homework and labs are graded and returned, I encourage you to compare answers others in your study group who have also had the lab, or homework, graded and returned. You may not share this work outside the class; it is a violation of academic integrity to share your work with others outside the class. It is a violation of academic integrity to receive the software engineering work completed by other students. If there are short answer questions, you must answer at least 90% of these questions correctly! I/We realize that the penalty for turning in work that is not my own, or assisting others in doing so, can range from an "F" in the class to dismissal from Trinity University. Print Name ____________________________________________ Time Required = ______.____ Hrs. Signature/Pledge ______________________________________________________________________ MySQL #1 Lab Individual/Duo Lab 25 Points Connection & Theory 1] ___________________________________________________________________________________ Write the line of code to start MySQL, from the command line, in one of the cs labs. 2] ___________________________________________________________________________________ SQL is an acronym for _?_. 3] ___________________________________________________________________________________ How do you launch a windows command window. 4] ___________________________________________________________________________________ DBMS is an acronym for _?_. SHOW x 1] ___________________________________________________________________________________ Write the line of SQL code to display a list of all of the databases. 2] ______ {T/F} All SQL Queries are case sensitive. CREATE DATABASE 1] ___________________________________________________________________________________Write the SQL command to create a database, called Trinity 2] ___________________________________________________________________________________Write the SQL command to create a database, called Library?? (replace the ?? with your initials)

MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 1

The short answer questions will be spot checked and graded for completion, but not checked for accuracy. I encourage you to form a study group; get together to prepare for exams. Once your homework and labs are graded and returned, I encourage you to compare answers others in your study group who have also had the lab, or homework, graded and returned. You may not share this work outside the class; it is a violation of academic integrity to share your work with others outside the class. It is a violation of academic integrity to receive the software engineering work completed by other students. If there are short answer questions, you must answer at least 90% of these questions correctly!

I/We realize that the penalty for turning in work that is not my own, or assisting others in doing so, can range from an "F" in the class to dismissal from Trinity University.

Print Name ____________________________________________ Time Required = ______.____ Hrs.

Signature/Pledge ______________________________________________________________________

MySQL #1 Lab

Individual/Duo Lab 25 Points

Connection & Theory

1] ___________________________________________________________________________________ Write the line of code to start MySQL, from the command line, in one of the cs labs.

2] ___________________________________________________________________________________ SQL is an acronym for _?_.

3] ___________________________________________________________________________________ How do you launch a windows command window.

4] ___________________________________________________________________________________ DBMS is an acronym for _?_.

SHOW x

1] ___________________________________________________________________________________ Write the line of SQL code to display a list of all of the databases.

2] ______ {T/F} All SQL Queries are case sensitive.

CREATE DATABASE

1] ___________________________________________________________________________________Write

the SQL command to create a database, called Trinity

2] ___________________________________________________________________________________Write

the SQL command to create a database, called Library?? (replace the ?? with your initials)

Page 2: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 2

DROP DATABASE x

1] ___________________________________________________________________________________Write

the SQL Command to delete database LibraryTH.

2] ___________________________________________________________________________________Write

the SQL Command to delete database Trinity.

USE

1] ___________________________________________________________________________________Write

the line of SQL code to make LibraryTH the current database.

2] ___________________________________________________________________________________Write

the line of SQL code to make Trinity the current database.

CREATE TABLE

1] Now that Trinity is your current database, write the block SQL code to create table Universities; it is to

have an auto incrementing ID, a Name, a City, and a State.

Page 3: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 3

2] Write the SQL code to create to create the Users table (shown in the MySQL Workbench table above).

DROP TABLE

1] ___________________________________________________________________________________Write

the SQL Command to delete table Universities.

2] ___________________________________________________________________________________Write

the SQL Command to delete table Faculty.

DESCRIBE x SHOW FIELDS IN x

1] Write the block of SQL code to add the Evan Barnett record, above, to the Users table.

2] Write the block of SQL code to add the Laural Bean record, above, to the Users table.

Page 4: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 4

3] Write the block of SQL code to add Trinity University to the Universities table.

INSERT INTO

1] Write the block of SQL code to add the Evan Barnett record, above, to the Users table.

2] Write the block of SQL code to add the Laural Bean record, above, to the Users table.

3] Write the block of SQL code to add Trinity University to the Universities table.

Page 5: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 5

Import Library1.sql Using MySQL Workbench

1] Place Library1.sql on your desktop.

2] Push the Open SQL Script File Button.

3] Go to the desktop and select file Library1.sql Push the Open Button.

4] You will notice that Library1 appears three times. When this database is restored, it will be called Library1 if you were to replace all three of these instances with MyLibrary , then the library restoration would create a database called MyLibrary

Page 6: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 6

5] Press the Lightning Bolt to execute the script. This will create the database.

6] All of the green check marks indicate success, but the database does not show up in the schema list until you refresh them.

7] Refresh the schema and Library1 appears.

Page 7: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 7

Library1 Database Use Library1 For The Remainder Of The Queries

1] ____________________ Library1 contains _?_ tables.

2] ____________________________________________________________________________________ The names of the tables in Library1 are _?_.

3] ____________________________________________________________________________________ Table Users has _?_ Records.

4] ____________________________________________________________________________________ Table Users has _?_ Fields.

5] ____________________________________________________________________________________ Table Books has _?_ Records.

6] ____________________________________________________________________________________ Table Books has _?_ Fields.

Table Library1.Users

Table Library1.Books

Page 8: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 8

SELECT * FROM

1] ___________________________________________________________________________________ Write

the line of SQL code to display all of the information about all of the Users.

2] ___________________________________________________________________________________ Write

the line of SQL code to display all of the information about all of the Books.

SELECT COUNT(*) FROM

1] ___________________________________________________________________________________ Write

the line of SQL code to display the number of Users records.

2] ___________________________________________________________________________________ Write

the line of SQL code to display the number of University records.

3] ___________________________________________________________________________________ Write

the line of SQL code to display the number of Users records in which the Last name is not NULL.

do not use WHERE in the query!

SELECT * FROM WHERE ID ?

1] ___________________________________________________________________________________ Write

the line of SQL code to display all of the information about all of the Users whose ID at least 20

2] ___________________________________________________________________________________ Write

the line of SQL code to display all of the information about all of the Users whose ID is 20

Page 9: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 9

3] Write the line of SQL code to display all of the information about all of the Users whose ID is at least 20

and no more than 40

4] ___________________________________________________________________________________ Write

the line of SQL code to display all of the information about all of the Users whose ID is not 20

5] ___________________________________________________________________________________ Write

the line of SQL code to display all of the information about all of the Users whose ID is an even number.

6] ___________________________________________________________________________________ Write

the line of SQL code to display the number of Users records whose ID is an odd number.

SELECT * FROM WHERE Last Like

1] ___________________________________________________________________________________ Write

the line of SQL code to display all of the information about all of the Users whose Last Name starts with

an 'A'

2] ___________________________________________________________________________________ Write

the line of SQL code to display all of the information about all of the Users whose Last Name starts with

an 'B'

3] ___________________________________________________________________________________ Write

the line of SQL code to display the number of Users records whose Last Name starts with a 'B'

4] Write the line of SQL code to display the number of Users records whose Last Name contains a 'B'

SELECT x, y, z FROM

1] Write a query that displays the ID, First, Last, & FullName of all Users.

Page 10: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 10

2] Write a query that displays the First, Last, & FullName, & ID of all Users.

3] Write a query that displays the ID, FullName, UserName, & Password of all Users Whose last name contains an 'A'

SELECT * FROM ORDER BY

1] Write a query that displays all of the information in the Users table in order by FullName.

2] Write a query that displays the ID and FullName of all Users table in order by ID.

3] Write a query that displays the ID and FullName of all Users table in descending order by ID.

3] Write a query that displays the ID, First, & Last of all Users whose ID is in the range 10 – 20 order by FullName. DO NOT USE BETWEEN!

Page 11: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 11

4] Write a query that displays the ID, First, & Last of all Users whose ID is in the range 10 - 20 order by FullName. USE BETWEEN!

5] Write a query that displays the ID, First, & Last of all Users whose ID in the range {2,4,6,8,…} in order by First name

6] Write a query that displays the ID, First, & Last of all Users whose ID in the range {3,6,9,12.,…} in descending order by Last.

7] Write a query that displays the ID, First, & Last of all Users whose ID are multiples of 2 or 5 in descending order by ID

Page 12: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 12

SELECT * FROM LIMIT X

1] ___________________________________________________________________________________ Execute the query below. Unfortunately, LIMIT is not supported in most databases, including MSSQL.

SELECT First

FROM Users LIMIT 3;

2] ___________________________________________________________________________________ Execute the query below. Unfortunately, LIMIT is not supported in most databases, including MSSQL.

SELECT First

FROM Users WHERE ID >= 10 LIMIT 3,2;

3] ___________________________________________________________________________________ The query below shows only the first user in the query view. Who is that person?

SELECT First

FROM Users LIMIT 0,1;

4] ___________________________________________________________________________________ The query below shows only the second user in the query view. Who is that person?

SELECT First

FROM Users LIMIT 1,1;

5] ___________________________________________________________________________________ The query below shows only the third user in the query view. Who is that person?

SELECT First

FROM Users LIMIT 2,1;

6] Write a query that displays all of the information about the twenty-first user in the Users table.

Query Output

Page 13: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 13

1] ___________________________________________________________________________________ Write the results from executing the query below:

SELECT 2 * 3 + 4 * 5

2] ___________________________________________________________________________________ Write the results from executing the query below:

SELECT 2 * (3 + 4) * 5

3] ___________________________________________________________________________________ Write the results from executing the query below:

SELECT pow(2,8)

Concatenate

1] Write a query that will display the results of combining all of the First and Last names of all Users TomHicks

2] ___________________________________________________________________________________ Write the results from executing the query below:

SELECT CONCAT (UserName, Password) FROM Users WHERE ID = 100

3] ___________________________________________________________________________________ Write the results from executing the query below:

SELECT CONCAT ("One", "=", "Two")

Left & Right

1] ___________________________________________________________________________________ Write the results from executing the query below:

SELECT Left ("Trinity University", 4)

Page 14: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 14

2] ___________________________________________________________________________________ Write the results from executing the query below:

SELECT Right ("Trinity University", 4)

Update

1] Write a query that replaces the first name, of the record whose ID is 6, with Dan.

2] Write a query that replaces the passwd of all of the Users with 'trinity';

3] Write a query that replaces the UserNames of all of the Users with blank ('').

4] Write a query that replaces the UserNames of all of the Users with the first-last (dash between);

5] Write a query that replaces the FullName of all of the Users with the Last, First (comma blank between);

Page 15: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 15

UPPER UCASE

1] ___________________________________________________________________________________ Write the results from executing the query below:

SELECT UCASE ("Trinity")

2] ___________________________________________________________________________________ Write the results from executing the query below:

SELECT UPPER ("University")

3] Write a query that displays the first and last name of all Users using upper case letters.

LOWER LCASE

1] ___________________________________________________________________________________ Write the results from executing the query below:

SELECT LCASE ("Trinity")

2] ___________________________________________________________________________________ Write the results from executing the query below:

SELECT UPPER ("University")

3] Write a query that displays the first and last name of all Users using lower case letters.

4] Write a query that replaces the EMail of all of the Users with blank ('').

Page 16: MySQL #1 Lab - Trinity Universitycarme.cs.trinity.edu/thicks/2320/Labs/MySQL1-HW.pdf · group who have also had the lab, or homework, graded and returned. You may not share this work

Server-Configuration-2-MySQL-1-HW.docx CSCI 3343 Initials ______ P a g e | 16

5] Write a query that replaces the EMail of all of the Users with the UserName plus @trinity.edu (all lower case). The UserName may be no more than 8 characters in length.

What To Turn In

1] All pages of this lab with questions completed.

- - - - - - - - - - - No Lab Is Complete Until Both Are Complete - - - - - - - - - - -

1] You sign & submit the Pledge form at the top of this lab!. No Lab Will Be Considered Complete until this is done. Late penalties will continue to accrue until the pledge form is submitted. a) Sign & Pledge

b) Record the amount of time you think you spent on this lab

c) Staple all pages of this lab. Fold in half length-wise (like a hot-dog). Put your name on the outside. Place it on the professor desk before the beginning of lecture

on the day it is due. The penalty for late homework will not exceed 25% off per day.

d) Short answer questions must be hand written, unless the professor has granted an exception for physical reasons.

2] Place all programming code associated with this program, if any, in the Professor’s Code Drop Box or on the Virtual System as directed.

I do not accept programs by mail; do not submit labs via email!