Previously everyone in the class used the mysql account: Username: csci340user Password: csci340pass

Similar documents
Previously everyone in the class used the mysql account: Username: csci340user Password: csci340pass

Multiple-Choice. 3. When you want to see all of the awards, even those not yet granted to a student, replace JOIN in the following

Database Systems Laboratory 5 Grouping, DCL & TCL

Chapter 8: Working With Databases & Tables

Top 88 Question Asked in Part I of MIS 150 EXAM #1 (Chapter 1-4, Appendix C) Exams questions gathered from old tests dating back to Fall 2000

Chapter 3. Introduction to relational databases and MySQL. 2010, Mike Murach & Associates, Inc. Murach's PHP and MySQL, C3

Relational Database Development

Relational Database Management Systems for Epidemiologists: SQL Part II

Multiple-Choice. 1. Which of the following is equivalent to a table? (3 pts.) a. record b. relation c. relationship d. constraint e.

Lecture11: Transaction Control Language Data Control Language

PHP: Cookies, Sessions, Databases. CS174. Chris Pollett. Sep 24, 2008.

Introduction to relational databases and MySQL

Referential integrity

'information_schema' When Using Lock Tables

Unit 5.2b - Security 1. Security. Unit 5.2b

Locate your Advanced Tools and Applications

Database Systems CSE 414

LECTURE11: TRANSACTION CONTROL LANGUAGE DATA CONTROL LANGUAGE

How To Remove Information_schema From Sql File

Referential Integrity and Other Table Constraints Ray Lockwood

Lab # 4. Data Definition Language (DDL)

Using MySQL on the Winthrop Linux Systems

SQL CSCI 201 Principles of Software Development

Oracle User Administration

Database Systems CSE 414

Networks and Web for Health Informatics (HINF 6220)

Quick Guide to Installing and Setting Up MySQL Workbench

CVYS Online Registration FAQ!

Module 3 MySQL Database. Database Management System

Database Management System 9

CGS 3066: Spring 2017 SQL Reference

Table of Contents. PDF created with FinePrint pdffactory Pro trial version

IT Certification Exams Provider! Weofferfreeupdateserviceforoneyear! h ps://

Chapter 13 : Informatics Practices. Class XI ( As per CBSE Board) SQL Commands. New Syllabus Visit : python.mykvs.in for regular updates

Indexes (continued) Customer table with record numbers. Source: Concepts of Database Management

Course Outline and Objectives: Database Programming with SQL

Teradata. This was compiled in order to describe Teradata and provide a brief overview of common capabilities and queries.

SQL Commands & Mongo DB New Syllabus

Mysql Workbench Cannot Drop Schema

Introducing Transactions

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

Relational Databases. Week 7 INFM 603

Databases CSCI 201 Principles of Software Development

Introduction to Database Systems CSE 444. Lecture #1 March 26, 2007

Chapter 1 SQL and Data

Name Class Account UNIVERISTY OF CALIFORNIA, BERKELEY College of Engineering Department of EECS, Computer Science Division J.

Islamic University of Gaza Faculty of Engineering Department of Computer Engineering Fall 2011 ECOM 4113: Database System Lab Eng.

Overview. Data Integrity. Three basic types of data integrity. Integrity implementation and enforcement. Database constraints Transaction Trigger

The appendix contains information about the Classic Models database. Place your answers on the examination paper and any additional paper used.

Example 1 - Create Horizontal View. Example 2 - Create Vertical View. Views. Views

More SQL: Complex Queries, Triggers, Views, and Schema Modification

Access Intermediate

Hash table example. B+ Tree Index by Example Recall binary trees from CSE 143! Clustered vs Unclustered. Example

CSCI-UA: Database Design & Web Implementation. Professor Evan Sandhaus Lecture #17: MySQL Gets Done

Introduction to Database Systems CSE 414. Lecture 26: More Indexes and Operator Costs

1.204 Computer Algorithms in Systems Engineering Spring 2010 Problem Set 2: Municipal Database Due: 12 noon, Wednesday, February 24, 2010

Today Learning outcomes LO2

School of Computing and Information Technology. Examination Paper Autumn 2016

How to use SQL to create a database

CMSC 461 Final Exam Study Guide

Database Security: Transactions, Access Control, and SQL Injection

Sql Server Check If Global Temporary Table Exists

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama

DB Creation with SQL DDL

Introduction to Database Systems

CSCI-UA: Database Design & Web Implementation. Professor Evan Sandhaus

More SQL: Complex Queries, Triggers, Views, and Schema Modification

This lab will introduce you to MySQL. Begin by logging into the class web server via SSH Secure Shell Client

CS2300: File Structures and Introduction to Database Systems

Chapter # 7 Introduction to Structured Query Language (SQL) Part I

Oracle Create Table Foreign Key On Delete No

Data Modelling and Databases. Exercise Session 7: Integrity Constraints

CSCE 4523 Introduction to Database Management Systems Final Exam Fall I have neither given, nor received,unauthorized assistance on this exam.

Intermediate SQL ( )

Relational Data Structure and Concepts. Structured Query Language (Part 1) The Entity Integrity Rules. Relational Data Structure and Concepts

CN4 - Design Specification

Careerarm.com. 1. What is MySQL? MySQL is an open source DBMS which is built, supported and distributed by MySQL AB (now acquired by Oracle)

Transaction Safe Feature in MySQL Databases

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

Oracle Syllabus Course code-r10605 SQL

Oracle. SQL(Structured Query Language) Introduction of DBMS. Build In Function. Introduction of RDBMS. Grouping the Result of a Query

Chapter 11 How to create databases, tables, and indexes

Multicolumn index, stored procedure, stored function, trigger, event, and transaction examples

CSC 215 PROJECT 2 DR. GODFREY C. MUGANDA

AO3 - Version: 2. Oracle Database 11g SQL

Lecture 17. Monday, November 17, 2014

Draft. Students Table. FName LName StudentID College Year. Justin Ennen Science Senior. Dan Bass Management Junior

Introduction to Computer Science and Business

- Database: Shared collection of logically related data and a description of it, designed to meet the information needs of an organization.

In-class activities: Sep 25, 2017

T-sql Check If Index Exists Information_schema

Concepts of Database Management Seventh Edition. Chapter 4 The Relational Model 3: Advanced Topics

1. Using Bitvise SSH Secure Shell to login to CS Systems Note that if you do not have Bitvise ssh secure shell on your PC, you can download it from

CISC437/637 Database Systems Final Exam

Department of Computer Science University of Cyprus. EPL342 Databases. Lab 2

Advance Database Systems. Joining Concepts in Advanced SQL Lecture# 4

Review -Chapter 4. Review -Chapter 5

3ISY402 DATABASE SYSTEMS

WEB SECURITY p.1

CSE 190D Spring 2017 Final Exam Answers

Transcription:

Database Design, CSCI 340, Spring 2016 SQL, Transactions, April 15 Previously everyone in the class used the mysql account: Username: csci340user Password: csci340pass Personal mysql accounts have been created for you. I used the first letter of your first name followed by your last name for both the username and password. For example, for me: Username: cschahczenski Password: cschahczenski Your personal mysql account has access to a database, with the same name. Within that database, you can create tables, views, indexes and grant privileges to other mysql users, on tables and views in the database. Login to katie. From katie, login to your personal mysql account, and see what databases you have access to. mysql u cschahczenski p cschahczenski SHOW DATABASES; Use the database with your name and check that you can create tables within it. USE cschahczenski; CREATE TABLE TEST (testid INT PRIMARY KEY); SHOW TABLES; Recall that transactions are a logical unit of work which takes a database from a consistent state to a consistent state. (The database may be in an inconsistent state during the transaction.) 1. DBMS typically have multiple ways in which data can be stored. They can be stored using ordered/unordered flat files, ISAM, heap files, hash buckets, or B+ trees. Each form has its own particular advantages and disadvantages. The most commonly used forms are B+ trees and ISAM. To see the storage options for MySQL, give the following command within mysql. SHOW ENGINES; How may storage options are there for MySQL? 9 1

2. To see what storage engine is used for a table: SELECT ENGINE FROM information_schema.tables WHERE TABLE_SCHEMA = 'databasename' AND TABLE_NAME = 'tablename' What is the default storage engine for our implementation of mysql? InnoDB 3. Create a logical model for the following conceptual model. Video Store Only storing who checked out what Movie movieid name 1..1 copy of Copy copyid {P} copycondition checked out Customer customerid fname lname 2

4. Get the script from the website and use it to create tables in your database. Check that the tables are inserted correctly. Add two new movies into the database, also with a copy of each of these movies. What happens if you try inserting a copy of a movie into the database where the movie doesn t exist? Write the error statement here. ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`cmschahczenski`.`copy`, CONSTRAINT `movieconst` FOREIGN KEY (`movieid`) REFERENCES `Movie` (`movieid`) ON UPDATE CASCADE) Say that you are the boss and database administrator for a video rental store. When new copies of movies are purchased, you are the one who will add these to the database. Other employees of the video store can see if a copy of a movie is available and they can check movies out and back in. 5. You have decided to create a view for your employees to see a list of the movies in the store and the number of copies. Write the SELECT query which you would use to obtain the information below. Note that in rare cases, you have entered a movie into the database, but you don t yet have copies of the movie. These movies should appear in the list. Here are the results using the database extension given in the script. SELECT name as 'Movie', COUNT(copyId) as 'Number of Copies' GROUP BY Movie.movieId; 6. Write the SQL statements to create the view called AllMovies. CREATE VIEW AllMovies AS SELECT name as 'Movie', COUNT(copyId) as 'Number of Copies' FROM Movie LEFT OUTER JOIN Copy ON Movie.movieId=Copy.movieId GROUP BY Movie.movieId; 3

7. Since employees will be helping customers check out and return movies, you want to create a view for them to see what copies of movies are available for checkout. Write the SELECT query to obtain this information. Here are the results using the database extension given in the script. SELECT name AS 'name', Movie.movieId as "movieid", copyid as "copyid" WHERE (Movie.movieId, copyid) NOT IN (SELECT movieid, copyid FROM CheckOut); 8. Write the SQL statements to create the view called MoviesAvailable. CREATE VIEW MoviesAvailable AS SELECT name AS 'name', Movie.movieId as 'movieid', copyid as 'copyid' WHERE (Movie.movieId, copyid) NOT IN (SELECT movieid, copyid FROM CheckOut); 9. Select someone else in the class to work with. Say that this person is one of your employees. Try granting SELECT privileges to that person on the AllMovies view suing the following. GRANT SELECT ON databasename.tableorviewname TO otherusername; Is your partner able to see your tables? How are the tables identified? GRANT SELECT ON cmschahczenski.allmovies TO partner; 10. Grant the same person SELECT, INSERT, UPDATE and DELETE privileges on the CheckOut table using the following statement. GRANT SELECT, INSERT, UPDATE, DELETE ON databasename.tableorviewname TO otherusername; GRANT SELECT, INSERT, UPDATE, DELETE ON cmschahczenski.moviesavailble 4

TO partner; Experiment with transactions where you and your partner both perform check outs on the same movies. Use the commands: BEGIN WORK; (rather than BEGIN TRANSACTION;) COMMIT; ROLLBACK; Other useful commands: SAVE savepointname; ROLLBACK TO savepointname; BEGIN WORK;. SAVEPOINT savepointname;. How are conflicts handled? 5