Dæmahópur ágúst 2016 Matthías Karl Karlsson -

Slides:



Advertisements
Similar presentations
SQL Query Examples Database Management COP4540, SCS, FIU.
Advertisements

Oracle Labs ECS 242, 342, 360 –You can connect from home to the machines in the lab. –E.g.: ssh u-knoppix.csc.uvic.ca Execute “sh” to use the proper shell.
SQL This presentation will cover: A Brief History of DBMS View in database MySQL installation.
Database Modifications CIS 4301 Lecture Notes Lecture /30/2006.
SQL reviews. Stored Procedures Create Procedure Triggers.
Database Modifications, Data Types, Views. Database Modifications A modification command does not return a result as a query does, but it changes the.
Database Modifications, Data Types, Views. Database Modifications A modification command does not return a result as a query does, but it changes the.
Subqueries Example Find the name of the producer of ‘Star Wars’.
Indexes. An index on an attribute A of a relation is a data structure that makes it efficient to find those tuples that have a fixed value for attribute.
Instructor: Amol Deshpande  Data Models ◦ Conceptual representation of the data  Data Retrieval ◦ How to ask questions of the database.
Query Compiler By:Payal Gupta Roll No:106(225) Professor :Tsau Young Lin.
CMSC424: Database Design Instructor: Amol Deshpande
SQL. 1.SQL is a high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation details that would be necessary in.
CMSC424: Database Design Instructor: Amol Deshpande
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 7.
CMSC424: Database Design Instructor: Amol Deshpande
SQL SQL is a very-high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation details that would be necessary in.
Database Modifications A modification command does not return a result as a query does, but it changes the database in some way. There are three kinds.
Joins Natural join is obtained by: R NATURAL JOIN S; Example SELECT * FROM MovieStar NATURAL JOIN MovieExec; Theta join is obtained by: R JOIN S ON Example.
The Query Compiler 16.1 Parsing and Preprocessing Meghna Jain(205) Dr. T. Y. Lin.
CMSC424: Database Design Instructor: Amol Deshpande
CMSC424: Database Design Instructor: Amol Deshpande
SQL By: Toan Nguyen. Download Download the software at During the installation –Skip sign up for fast installation.
1 Relational Data Model CS 157B Nidhi Patel. 2 What is a Data Model? A notation for describing data or information A notation for describing data or information.
Chapter 6 The database Language SQL Spring 2011 Instructor: Hassan Khosravi.
Dr. T. Y. Lin | SJSU | CS 157A | Fall 2011 Chapter 6 THE DATABASE LANGUAGE SQL 1.
Relational Algebra Spring 2012 Instructor: Hassan Khosravi.
Introduction to Data Manipulation in SQL CIS 4301 Lecture Notes Lecture /03/2006.
Introduction to Indexes. Indexes An index on an attribute A of a relation is a data structure that makes it efficient to find those tuples that have a.
THE DATABASE LANGUAGE SQL
1 More SQL uDatabase Modification uDefining a Database Schema uViews.
Referential Integrity checks, Triggers and Assertions Examples from Chapter 7 of Database Systems: the Complete Book Garcia-Molina, Ullman, & Widom.
Advanced SQL Concepts - Checking of Constraints CIS 4301 Lecture Notes Lecture /6/2006.
© D. Wong Normalization  Purpose: process to eliminate redundancy in relations due to functional or multi-valued dependencies.  Decompose relation.
CS 157B Database Systems Dr. T Y Lin. Updates 1.Red color denotes updated data (ppt) 2.Class participation will be part of “extra” credits to to “quiz.
Dr. T. Y. Lin | SJSU | CS 157A | Fall 2011 Chapter 2 THE RELATIONAL MODEL OF DATA 1.
1 Chapter 6 More SQL uDatabase Modification uDefining a Database Schema uViews.
SQL Exercises – Part I April
The Relational Model of Data Prof. Yin-Fu Huang CSIE, NYUST Chapter 2.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 18 A First Course in Database Systems.
The Database Language SQL Prof. Yin-Fu Huang CSIE, NYUST Chapter 6.
CS 157B Database Systems Dr. T Y Lin. 1.2 Overview of a Database Management System Data-Definition Language Commands –Illustrated by three examples.
Databases : SQL Multi-Relations 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman.
1 SQL: Concept and Usage. 2 SQL: an Overview SQL (Structured Query Language) –Also be pronounced as “sequel” –A relational database language –Consists.
1 Constraints and Triggers in SQL. 2 Constraints are conditions that must hold on all valid relation instances SQL2 provides a variety of techniques for.
Subqueries CIS 4301 Lecture Notes Lecture /23/2006.
Vinnustofa fyrir umsjónarmenn rafræns efnis Grunnvirkni SFX
Chap 5. The DB Language (SQL)
THE DATABASE LANGUAGE SQL
Introduction to Structured Query Language (SQL)
THE RELATIONAL MODEL OF DATA
Chap 2. The Relational Model of Data
The Query Compiler Parsing and Preprocessing. Meghna Jain(205)
Open Badges Rafrænar viðurkenningar
THE RELATIONAL MODEL OF DATA
Um GeoGebra 4.0, 4.2 og 5.0. Samfélagið kringum GeoGebra
SQL: Concept and Usage.
Faglegir þættir og markaðstengd sjónarmið
Vinnustofa fyrir umsjónarmenn rafræns efnis Grunnvirkni SFX
SQL This presentation will cover: View in database MySQL installation
Gamalt vín á nýjum belgjum eða gamlir belgir með nýtt vín...
Markaðsfærsla þjónustu
Sigríður H. Gunnarsdóttir 27. febrúar 2008
Forðafræði svæðisins Vordís Eiríksdóttir
Innleiðing á ISN2016 Þórarinn Sigurðsson
Query Compiler By:Payal Gupta Shirali Choksi Professor :Tsau Young Lin.
Árangursrík stærðfræðikennsla byrjenda
Orðasöfn, gagnabankar og vefurinn
Er íslenskt skólakerfi "dýrt"?
Iðunn Kjartansdóttir Náms- og starfsráðgjafi
Presentation transcript:

Dæmahópur 4 31. ágúst 2016 Matthías Karl Karlsson - mattik@hi.is Gagnasafnsfræði Dæmahópur 4 31. ágúst 2016 Matthías Karl Karlsson - mattik@hi.is

Dæmi 1 Setjið upp sqlite. Náið í gagnagrunninn f1.db á heimasíðunni og opnið með sqlite. Keyrið skipunina SELECT * FROM Movie WHERE year > 1990 og birtið svarið. Vantar einhverjum aðstoð með uppsetningu?

SELECT * FROM Movie WHERE year > 1990; title year length inColor studioName producerC ------------------------ ---------- ---------- ---------- --------------- ---------- The Man Who Wasn't There 2001 116 0 USA Entertainm. 777 Star Trek: Nemesis 2002 116 1 Paramount 321 The Usual Suspects 1995 106 1 MGM 999

.tables / .table Movie MovieExec MovieStar

.schema CREATE TABLE Movie ( title varchar(25), year int, length int, inColor int, studioName varchar(15), producerC varchar(3) ); ...

mode column. header on. width X Y Z. read script. sql. open database .mode column .header on .width X Y Z... .read script.sql .open database.db

.mode column Pretty Woman|1990|119|1|Disney|999 The Man Who Wasn't There|2001|116|0|USA Entertainm.|777 Logan's run|1976||1||888 Star Wars|1977|124|1|Fox|555 Empire Strikes Back|1980|111|1|Fox|555 Star Trek|1979|132|1|Paramount|444 Star Trek: Nemesis|2002|116|1|Paramount|321 Terms of Endearment|1983|132|1|MGM|123 The Usual Suspects|1995|106|1|MGM|999 Gone With the Wind|1938|238|1|MGM|123

.mode column Pretty Woman 1990 119 1 Disney 999 The Man Who 2001 116 0 USA Entert 777 Logan's run 1976 1 888 Star Wars 1977 124 1 Fox 555 Empire Strik 1980 111 1 Fox 555 Star Trek 1979 132 1 Paramount 444 Star Trek: N 2002 116 1 Paramount 321 Terms of End 1983 132 1 MGM 123 The Usual Su 1995 106 1 MGM 999 Gone With th 1938 238 1 MGM 123

.header on Pretty Woman 1990 119 1 Disney 999 The Man Who 2001 116 0 USA Entert 777 Logan's run 1976 1 888 Star Wars 1977 124 1 Fox 555 Empire Strik 1980 111 1 Fox 555 Star Trek 1979 132 1 Paramount 444 Star Trek: N 2002 116 1 Paramount 321 Terms of End 1983 132 1 MGM 123 The Usual Su 1995 106 1 MGM 999 Gone With th 1938 238 1 MGM 123

.header on title year length inColor studioName producerC ------------ ---------- ---------- ---------- ---------- ---------- Pretty Woman 1990 119 1 Disney 999 The Man Who 2001 116 0 USA Entert 777 Logan's run 1976 1 888 Star Wars 1977 124 1 Fox 555 Empire Strik 1980 111 1 Fox 555 Star Trek 1979 132 1 Paramount 444 Star Trek: N 2002 116 1 Paramount 321 Terms of End 1983 132 1 MGM 123 The Usual Su 1995 106 1 MGM 999 Gone With th 1938 238 1 MGM 123

.width .width 1 1 1 1 1 1 t y l i s p - - - - - - P 1 1 1 D 9 T 2 1 0 U 7 L 1 1 8 S 1 1 1 F 5 E 1 1 1 F 5 S 1 1 1 P 4 S 2 1 1 P 3 T 1 1 1 M 1 T 1 1 1 M 9 G 1 2 1 M 1

.width .width 10 4 6 7 10 10 title year length inColor studioName producerC ---------- ---- ------ ------- ---------- ---------- Pretty Wom 1990 119 1 Disney 999 The Man Wh 2001 116 0 USA Entert 777 Logan's ru 1976 1 888 Star Wars 1977 124 1 Fox 555 Empire Str 1980 111 1 Fox 555 Star Trek 1979 132 1 Paramount 444 Star Trek: 2002 116 1 Paramount 321 Terms of E 1983 132 1 MGM 123 The Usual 1995 106 1 MGM 999 Gone With 1938 238 1 MGM 123

www.sqlite.org Documentation /cli.html ...

Dæmi 2 Berið saman að nota gagnagrunnskerfi til að geyma upplýsingar miðað við að lesa úr einfaldri textaskrá, t.d. TSV (Tab-separated values). Nefnið tvo kosti sem annað kerfið hefur umfram hitt. Hvernig væri hægt að halda utan um einkunnir nemenda í námskeiði með TSV textaskrá?

Kostir við gagnagrunnskerfi Leyfa flóknari fyrirspurnir Geta haldið utan um gríðarlega flókin gögn Tengja gögn á nytsamlegan hátt Gerð fyrir samskeiða vinnslu Lifa af náttúruhamfarir Allt geymt á diski

Kostir við einfalda textaskrá Einfaldari uppsetning (þ.e. schema). Þarft í rauninni ekki að búa yfir ákveðinni þekkingu til þess að skapa. Trúlega hraðvirkara Viðhald er einfaldara Trúlega þægilegra til þess að halda utan um lítið af gögnum sem breytast fram og aftur

Hvernig væri hægt að halda utan um einkunnir nemenda í námskeiði með TSV textaskrá? Nafn Netfang Einkunn Bjarni Bjarnason bb8@hi.is 8 Gunnar Gunnarsson gg9@hi.is 9 Helga Helgadóttir hh22@hi.is 10 ...

Heimadæmi 2 1. In Fig. 6 are instances of two relations that might constitute part of a banking database. Indicate the follwing: The attributes of each relation. The tuples of each relation. f ) A suitable domain for each attribute.

acctNo type balance 12345 savings 12000 23456 checking 1000 34567 25

firstName lastName idNo account Robbie Banks 901-222 12345 Lena Hand 805-333 23456

Heimadæmi 2 2. Find the address of MGM studios. Find Sandra Bullock‘s birthdate. Find all the stars that appeared either in a movie made in 1980 or a movie with „Love“ in the title. Find all executives worth at least $10,000,000. Find all the stars who either are male or live in Malibu (have string Malibu as a part of their address).

Movies(title, year, length, genre, studioName, producerC#) StarsIn(movieTitle, movieYear, starName) MovieStar(name, address, gender, birthdate) MovieExec(name, address, cert#, netWorth) Studio(name, address, presC#)

ATH: Fyrirspurnin þarf alltaf að skila réttu gildi miðað við lýsingu á gagnagrunni, ekki gögnin sem eru í honum. Ekki í lagi að skrifa SELECT * FROM ... og kíkja hvað svarið er. Gagnagrunnurinn f3.db er aðeins til hliðsjónar. Það er beðið um fyrirspurnir, ekki svör!