ISYS1055/1057 Database Concepts Week 9: Tute/Lab SQL Programming
|
|
- Nora Nelson
- 5 years ago
- Views:
Transcription
1 Go to Database à Add Database and assign a suitable name (say New Movies) to the new database you are about to create. School of Science/ Computer Science and Information Technology ISYS1055/1057 Database Concepts Week 9: Tute/Lab SQL Programming Semester Objective The objectives of this tute/lab session are: Develop advanced SQL programming skills: Ø CREATE, ALTER and DROP tables; Ø INSERT, UPDATE and DELETE rows in a table; Ø Create and use VIEWs; Ø Define and use TRIGGERs. It should appear on the database list of left pane, as well as on Database Chooser on the topcentre of the screen. It may not be open at this time. If not opened, open it by double clicking on the database name on the left pane. And thereafter, choose it from the Database Chooser. 1.1 Preparation Tasks You must already have completed Week 7 8 Tute/Lab session. If not, before attempting any of the activities in this sheet, make sure you are thoroughly competent with the basic SQL programming tasks included in the Week 7 8 Tute/Lab sheet. 2 Build a replica MOVIES database in your workspace The movies database is built to store information about movies, directors, and stars (i.e. actors and actresses) in a video store. In addition, it stores information on members (who got active memberships with the video store) and their borrowing transactions. A sketchy ER diagram for the movies database is given below. Director DirNumb {PK} DirName DirBorn DirDied Star StarNumb {PK} StarName BrthPlce StarBorn StarDied Directs MovStar 2.1 Create a blank database Movie MvNumb {PK} MvTitle YrMade MvType Crit MPAA Noms Awrd Open SQLite Studio and create a new (empty) database, as follows. Includes Member MmbNumb {PK} MmbName MmbAddr MmbCity MmbSt NumRent Bonus JoinDate By Borrow TxnNumb {PK} BorDte Now your database is ready to add new tables and populate them. 2.2 Building the schema using a script. In the Canvas, under Week 9 Module, you will find a zip file (SQL Scripts.zip). Download this zip file into your working directory and unzip it. It contains the following files. Borrow.sql Director.sql Member.sql Movie.sql Moviesddl.sql Movstar.sql Star.sql Moviesddl.sql SQL script contains DDL statements to build all the required tables, except Director. In this exercise, you learn how to load a (pre-built) SQL script from a file and run it on SQLite Studio. We first use Moviesddl.sql SQL script to create five tables: Borrow, Movie, Star, MovStar and Member. On SQLite Studio, click on Load SQL from File button from the top icons. Page 1 of 9 Page 2 of 9
2 Was your insertion successful? Choose Moviesddl.sql on the dialog box and run SQL statements on it. Now try it again with the following data. 25 Beautiful Lies 2010 DRAMA 4 M Was your insertion successful? What is the problem you encountered? Let s suppose that you have only a few attribute values for a new movie. Say, Christopher Robin was just released. 26 Christopher Robin 2018 DRAMA You will see that you have 5 tables created in your database space. 2.3 Populating the Movies Database. In the above step, you created the tables, but they are still empty. Repeat Run SQL from file option for populating these tables using Borrow.sql, Member.sql, Movie.sql, Movstar.sql, and Star.sql files. A simple SELECT statement can be used to make sure you have correctly created and populated these tables. FROM movie; FROM member; Insert new rows to existing tables Say, you want to add a new movie into the Movie relation. 25 A Beautiful Mind 2000 DRAMA 4 M Use INSERT INTO table_name VALUES(...) command to insert new tuples. INSERT INTO movie VALUES (25, A Beautiful Mind, 2000, DRAMA, 4, M, 6, 4, 5) Note that (1) we have values for ALL attributes; (2) they are listed in correct order as the list of attributes; and (3) character strings begin and end with single quotation marks. A common problem you encounter if you use a word processor to copy and paste these commands: Some word processors convert single quotation marks into open quote ( ) and end quote ( ) which are not valid in SQL. Make sure they are just single quotation marks as you typed on the keyboard. Discuss with your group how to insert a new row with NULL values for attributes that are unknown. Write down the complete SQL statement you used in this step. 2.5 Edit Existing Rows You can use UPDATE statement to change attribute values in a table. For example, if you wish to change the name of a movie: SCI FI 4 G To : A space odyssey 1968 SCI FI 4 G Use the following SQL statement: UPDATE movie SET mvtitle = 2001: A Space Odyssey WHERE mvtitle = 2001 ; Try the following update. UPDATE movie SET mvnumb = 10 WHERE mvnumb = 11; Was your update successful? What is the problem you encountered? 2.6 Delete Existing Rows Note that deletions must be used with utmost care. Especially when you delete rows from production-level databases, reversing the effects of a deletion is not always possible, and may even result in unexpected consequences. You can use DELETE statement to delete rows from a table. Always test the DELETE command by running it as a SELECT command prior to run the DELETE command. e.g. Delete all the stars from the Star table who haven't played in any movie (in the collection). First, test the rows that could impact by the deletion, as follows: Write down the complete SQL statement you used in this step. Page 3 of 9 Page 4 of 9
3 FROM star WHERE starnumb NOT IN (SELECT starnumb FROM movstar); If the above SQL displays the desired list for the deletion, now you can re-run the above SQL, by replacing with DELETE. DELETE FROM star WHERE starnumb NOT IN (SELECT starnumb FROM movstar); 2.7 Create a new table from scratch Director table. Now it s time to create the missing table. We will write a CREATE TABLE command to build it will following attributes: Dirnumb This attribute holds 3-digit director number Dirname This attribute holds director names, Names are up to 20 characters long. Dirborn This attribute holds the year a director was born. So, assume it is a 4-digit number. Dirdied same as the above dirborn. Explore the data types available in SQLite that you can use in your CREATE TABLE command. Visit: to review all of the possibilities. 1. What is the maximum precision (number of digits) of the NUMERIC type? 2. What is the difference between NUMERIC type and DECIMAL type? 3. What is the difference between VARCHAR and CHAR? 4. What is the maximum string length that can be accommodated in a VARCHAR attribute? 5. How dates and times are stored in SQLite? First create the table with no constraints, as follows: CREATE TABLE director ( dirnumb DECIMAL(3) NOT NULL, Dirname VARCHAR(20), Dirborn DECIMAL(4), dirdied DECIMAL(4), PRIMARY KEY (dirnumb) ); 2.8 Populate the Director table Now that the new table is created and required integrity constraints are enforced, use Director.sql script to populate the table. Were you able to insert all rows (8 rows in total)? If unsure, count. Now insert the following tuple to the movie relation. 27 Minority Report 2002 SCI FI 4 PG Why didn't the above insertion succeed? How do you fix this problem? 2.9 Alter the schema definition add columns Let s suppose we were asked to store directors birthplace, as similar to Stars. In order to add this attribute, we have to alter the schema of the table. ALTER TABLE director ADD COLUMN brthplce VARCHAR(20) ; Now, you may add some values to this new attribute, using UPDATE statement. E.g. UPDATE director SET birthplce = New York, USA WHERE dirnumb = 1; 2.10 Alter the schema definition add Constraint SQLite doesn t include all forms of table alterations. It limits alterations to table name changes, column name changes, and column addition. Other database systems, such as Oracle, allow more complex alterations, such as adding constraints. For example, adding a foreign key in Movie table: Between Movie and Director entities (in the underlying data model), there was a one-to-many relationship, resulting in a foreign key in Movie table. ALTER TABLE movie ADD Constraint fk_const FOREIGN KEY (dirnumb) REFERENCES director(dirnumb); Exercise: The above ALTER TABLE command doesn t work in SQLite. Suggest a workaround to add a foreign key to the movie table. 3 Creating and using Views 3.1 Creating a view In the lecture, we create a view to (virtually) store continent names, number of countries and total population. The required information was derived from Country table, using grouped aggregation. We started the definition of the view by writing up the required SQL script that gives you the desired result and then, use it as the basis of the view definition. CREATE VIEW continent(name, NumCountries, Population) AS SELECT c.continent, count(*),sum(c.population) FROM country c GROUP BY c.continent; Exercise: create a view called dir_awards, which stores the director number, name, total number of awards won, and the total number of nominations received. The last two attributes do not exist directly in the base tables, therefore, they have to be generated by aggregating some attributes in Page 5 of 9 Page 6 of 9
4 base tables. In this example, you can add up awards won by movies, after grouping movies based on the director. You can do the same for the award nominations, too. 3.2 Using a view Run the following query: FROM dir_awards; Now, try to do an insertion via the view. INSERT INTO dir_awards (dirnumb, dirname) VALUES (21, 'David Lane'); Were you successful? 4 Creating and using Triggers Triggers are procedures that are stored in the database and are implicitly run, or fired, when something happens. Triggers are created using the CREATE TRIGGER statement. A trigger will have a defined trigger event (an INSERT, DELETE or UPDATE action) and a trigger action. A trigger action can be one or more SELECT, INSERT, DELETE or UPDATE statements or an PL/SQL procedure. 4.1 BEFORE and AFTER Triggers We discussed in the lecture how we can use a BEFORE trigger to add log records when data on one or more tables are updated. We explored how we can record before and after population values stored in a log file (when population statistics are updated on Country table). Exercise: Time to time, movies receive new critics reviews and as a result, their average critic ratings change. In the database, this is handled by updating crit attribute of the corresponding movie. For auditing purposes, we must store these changes in a log record. Each log record should include: movie number, time stamp, old critic rating and the new rating. 1. Create a table to store log records 2. Create a trigger to generate log records whenever crit attribute in the Movie table is updated. 3. Test your trigger by changing the critic rating of the movie 2001 to 5. Advanced Exercise: In Movies table, we store the number of Oscar nominations and the number of Oscar awards that each movie won. To ensure data integrity, we must ensure the number of awards cannot exceed the number of nominations. Write a trigger stop any insertions or updates proceeding if such insertion or update violate the above rule. 4.2 INSTEAD OF Triggers INSTEAD OF trigger is a special kind of trigger, normally used when dealing with non-updatable views. For example, if a view is generated using a join between two base tables, such views cannot be used to insert into or update rows in the base table. In such circumstances, if you want to provide a transparent mechanism to insert and update base tables using the view, you can use an INSTEAD OF trigger. The following activity involves with the creation of the view -- dir_awards, which stores the director number, name, total number of awards won, and the total number of nominations received. The last two attributes do not exist directly in the base tables, therefore, they have to be generated by aggregating some attributes in base tables. In this example, we can add up awards won by movies by grouping movies based on the director. We can do the same for the award nominations, too. Start the exercise, by creating the view, as follows: (you must have done this in Section 3.1) CREATE VIEW dir_awards (dirnumb, dirname, awrd_total, noms_total) AS (SELECT director.dirnumb, dirname, SUM(awrd), SUM(noms) FROM director LEFT OUTER JOIN movie ON director.dirnumb = movie.dirnumb GROUP BY director.dirnumb,dirname); If you created the view correctly, you should be able to use it in SELECT statements: FROM dir_awards; Now, try to do an update via the view. UPDATE dir_awards SET dirname = Woody Allen WHERE dirname = Allen, Woody ; You will get an error message, indicating that's not allowed. [21:53:26] Error while executing SQL query on database 'world': cannot modify dir_awards because it is a view Create a trigger to update dirname attribute in the dir_awards view. After the activation, try to repeat the same update (which failed earlier). Can you do the update now? Check the contents in the base tables. 5 Advanced Activity: Facebook-Lite Let s assume that a decision has been made to develop a light version (called Facebook-Lite) of the ever-popular Facebook application. This light version has limited functionalities compared to the full version. Only core functionalities are to be retained. You are tasked with the design of the database backend. After a careful analysis, the following core functionalities are to be retained in the light version. The system stores information on members; each member is uniquely identified by and a full name, screen name, date of birth, gender, status and location are to be stored. Each member has a visibility level on Facebook-Lite (private, friends-only, or everyone). As in the case of Facebook, members form networks of friends. A friendship is always between two members. A member can send a friend request to another member. Once that member accepts the request, they become friends on Facebook-Lite. Each friendship has a start date. Members can make posts on Facebook-Lite. A post has a unique postid and a body and a timestamp. Facebook-Lite only allows textual posts. Other members can respond to posts. They can also respond to previous responses. Responses are identical to posts in structure, so, they share the same structure as in original post. Each response will have a parent post or a parent response. Page 7 of 9 Page 8 of 9
5 Members can like posts and responses. The system keeps track of likes, specifically the member who make the like and the corresponding post/ response. No other information is required on likes. 1. Draw an entity-relationship model to represent these requirements. Make sensible assumptions for cardinality and participation constraints where they are not clearly outlined in the description. 2. Map the above ER model into relations using 7-step mapping process. 3. Create a database using the schema you arrived at the (2) above. You must have constraints (key, entity integrity and referential integrity) defined with the tables you create. 4. Populate your tables with some data to test the functionality of your Facebook Lite application. Page 9 of 9
ISYS1055/1057 Database Concepts Week 7: Tute/Lab SQL Programming
School of Science/ Computer Science and Information Technology ISYS1055/1057 Database Concepts Week 7: Tute/Lab SQL Programming Semester 2 2018 1 Objective The objectives of this tute/lab session are:
More informationISYS1055/1057 Database Concepts Week 6: Tute/Lab SQL Programming
School of Science/ Computer Science and Information Technology ISYS1055/1057 Database Concepts Week 6: Tute/Lab SQL Programming Semester 2 2018 1 Objective The objectives of this tute/lab session are:
More informationMET CS 669 Database Design and Implementation for Business Term Project: Online DVD Rental Business
MET CS 669 Database Design and Implementation for Business Term Project: Online DVD Rental Business Objective Create an initial design for the database schema for an online DVD rental business that is
More informationData Modelling and Databases. Exercise Session 7: Integrity Constraints
Data Modelling and Databases Exercise Session 7: Integrity Constraints 1 Database Design Textual Description Complete Design ER Diagram Relational Schema Conceptual Modeling Logical Modeling Physical Modeling
More informationInformation Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language
Information Systems Engineering SQL Structured Query Language DDL Data Definition (sub)language 1 SQL Standard Language for the Definition, Querying and Manipulation of Relational Databases on DBMSs Its
More informationWeek 4 Tute/Lab Entity-Relationship (ER) Model
ISYS1055/1057 Database Concepts 2018 Semester 2 Week 4 Tute/Lab Entity-Relationship (ER) Model The objectives of this tute/lab session are: Learn about the entity-relationship model; Learn how to build
More informationDATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E)
1 DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 2 LECTURE OUTLINE Updating Databases Using SQL Specifying Constraints as Assertions and Actions as Triggers Schema Change Statements in
More informationRelational Model, Key Constraints
Relational Model, Key Constraints PDBM 6.1 Dr. Chris Mayfield Department of Computer Science James Madison University Jan 23, 2019 What is a data model? Notation for describing data or information Structure
More information1 INTRODUCTION TO EASIK 2 TABLE OF CONTENTS
1 INTRODUCTION TO EASIK EASIK is a Java based development tool for database schemas based on EA sketches. EASIK allows graphical modeling of EA sketches and views. Sketches and their views can be converted
More informationProgramming and Database Fundamentals for Data Scientists
Programming and Database Fundamentals for Data Scientists Database Fundamentals Varun Chandola School of Engineering and Applied Sciences State University of New York at Buffalo Buffalo, NY, USA chandola@buffalo.edu
More informationLab # 2. Data Definition Language (DDL) Eng. Alaa O Shama
The Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Database Lab Lab # 2 Data Definition Language (DDL) Eng. Alaa O Shama October, 2015 Objective To be familiar
More informationChapter 1 SQL and Data
Chapter 1 SQL and Data What is SQL? Structured Query Language An industry-standard language used to access & manipulate data stored in a relational database E. F. Codd, 1970 s IBM 2 What is Oracle? A relational
More informationORACLE DATABASE 12C INTRODUCTION
SECTOR / IT NON-TECHNICAL & CERTIFIED TRAINING COURSE In this training course, you gain the skills to unleash the power and flexibility of Oracle Database 12c, while gaining a solid foundation of database
More information3ISY402 DATABASE SYSTEMS
3ISY402 DATABASE SYSTEMS - SQL: Data Definition 1 Leena Gulabivala Material from essential text: T CONNOLLY & C BEGG. Database Systems A Practical Approach to Design, Implementation and Management, 4th
More informationCSE 530 Midterm Exam
CSE 530 Midterm Exam Name: (Print CLEARLY) Question Points Possible Points Earned 1 25 2 10 3 20 4 20 5 15 Total 90 1 Question 1 Heap Files Suppose we want to create a heap file with a page size of 512
More informationSQL: Data De ni on. B0B36DBS, BD6B36DBS: Database Systems. h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 3
B0B36DBS, BD6B36DBS: Database Systems h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 3 SQL: Data De ni on Mar n Svoboda mar n.svoboda@fel.cvut.cz 13. 3. 2018 Czech Technical University
More informationLab # 4. Data Definition Language (DDL)
Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Lab # 4 Data Definition Language (DDL) Eng. Haneen El-Masry November, 2014 2 Objective To be familiar with
More informationDatabase Applications (15-415)
Database Applications (15-415) The Relational Model Lecture 3, January 18, 2015 Mohammad Hammoud Today Last Session: The entity relationship (ER) model Today s Session: ER model (Cont d): conceptual design
More informationAssorted Topics Stored Procedures and Triggers Pg 1
Assorted Topics Stored Procedures and Triggers Pg 1 Stored Procedures and Triggers Ray Lockwood Points: A Stored Procedure is a user-written program stored in the database. A Trigger is a stored procedure
More informationINFORMATION TECHNOLOGY NOTES
Unit-6 SESSION 7: RESPOND TO A MEETING REQUEST Calendar software allows the user to respond to other users meeting requests. Open the email application to view the request. to respond, select Accept, Tentative,
More information4 Schema Definition with SQL / DDL (II)
4 Schema Definition with SQL / DDL (II) 4.3 SQL/DDL Constraints 4.3.1 Attribute and simple table constraints 4.3.2 Enforcing cardinality constraints and foreign keys 4.3.3 Deferred constraints 4.3.4 Assertions
More informationSQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210
SQL: Concepts Todd Bacastow IST 210: Organization of Data 2/17/2004 1 Design questions How many entities are there? What are the major entities? What are the attributes of each entity? Is there a unique
More informationTutorial 2: Relational Modelling
Tutorial 2: Relational Modelling Informatics 1 Data & Analysis Week 4, Semester 2, 2014 2015 This worksheet has three parts: tutorial Questions, followed by some Examples and their Solutions. Before your
More informationEnterprise Architect. User Guide Series. Database Models. Author: Sparx Systems. Date: 19/03/2018. Version: 1.0 CREATED WITH
Enterprise Architect User Guide Series Database Models Author: Sparx Systems Date: 19/03/2018 Version: 1.0 CREATED WITH Table of Contents Database Models Data Modeling Overview Conceptual Data Model Logical
More information7. Data Privacy Option for Oracle E-Business Suite
7. Data Privacy Option for Oracle E-Business Suite This section contains information on using the Optim Data Privacy option in conjunction with the Optim Test Data Management Solution for Oracle E-Business
More informationA7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be answered
More informationSQL DATA DEFINITION LANGUAGE
9/27/16 DATABASE SCHEMAS IN SQL SQL DATA DEFINITION LANGUAGE SQL is primarily a query language, for getting information from a database. SFWR ENG 3DB3 FALL 2016 But SQL also includes a data-definition
More informationEGCI 321: Database Systems. Dr. Tanasanee Phienthrakul
1 EGCI 321: Database Systems Dr. Tanasanee Phienthrakul 2 Chapter 10 Data Definition Language (DDL) 3 Basic SQL SQL language Considered one of the major reasons for the commercial success of relational
More informationMovieNet: A Social Network for Movie Enthusiasts
MovieNet: A Social Network for Movie Enthusiasts 445 Course Project Yanlei Diao UMass Amherst Overview MovieNet is a social network for movie enthusiasts, containing a database of movies, actors/actresses,
More informationCOSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1
COSC344 Database Theory and Applications Lecture 5 SQL - Data Definition Language COSC344 Lecture 5 1 Overview Last Lecture Relational algebra This Lecture Relational algebra (continued) SQL - DDL CREATE
More informationCS Final Exam Review Suggestions
CS 325 - Final Exam Review Suggestions p. 1 last modified: 2017-12-06 CS 325 - Final Exam Review Suggestions Based on suggestions from Prof. Deb Pires from UCLA: Because of the research-supported learning
More informationMahathma Gandhi University
Mahathma Gandhi University BSc Computer science III Semester BCS 303 OBJECTIVE TYPE QUESTIONS Choose the correct or best alternative in the following: Q.1 In the relational modes, cardinality is termed
More informationITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION
ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION JING YANG 2010 FALL Class 3: The Relational Data Model and Relational Database Constraints Outline 2 The Relational Data Model and Relational Database Constraints
More informationCHAPTER 6 SUMMARY. Objective 1: Identify Good Database Design
Objective 1: Identify Good Database Design CHAPTER 6 SUMMARY A database is an organized collection of data facts about people, events, things, or ideas related to a specific topic or purpose. Information
More informationDatabase Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.
Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No. # 5 Structured Query Language Hello and greetings. In the ongoing
More informationSQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1
SQL Fundamentals Chapter 3 Class 03: SQL Fundamentals 1 Class 03: SQL Fundamentals 2 SQL SQL (Structured Query Language): A language that is used in relational databases to build and query tables. Earlier
More informationHomework 2: E/R Models and More SQL (due February 17 th, 2016, 4:00pm, in class hard-copy please)
Virginia Tech. Computer Science CS 4604 Introduction to DBMS Spring 2016, Prakash Homework 2: E/R Models and More SQL (due February 17 th, 2016, 4:00pm, in class hard-copy please) Reminders: a. Out of
More informationChapter 4. The Relational Model
Chapter 4 The Relational Model Chapter 4 - Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations and relations in the relational model.
More informationThe Relational Model. Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC)
The Relational Model Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) Why Study the Relational Model? Most widely used model in Commercial DBMSs: Vendors: IBM, Microsoft,
More informationMovieNet: A Social Network for Movie Enthusiasts
MovieNet: A Social Network for Movie Enthusiasts 445 Course Project MovieNet is a social network for movie enthusiasts, containing a database of movies, actors/actresses, directors, etc., and a social
More informationTHE AUSTRALIAN NATIONAL UNIVERSITY. Mid-Semester Examination August 2006 RELATIONAL DATABASES (COMP2400)
THE AUSTRALIAN NATIONAL UNIVERSITY Mid-Semester Examination August 2006 RELATIONAL DATABASES (COMP2400) Reading Time: 10 minutes Writing Time: 1 hour Permitted Materials: One A4 sheet with notes on both
More informationCOSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 304 Introduction to Database Systems SQL DDL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Overview Structured Query Language or SQL is the standard query language
More informationITEC 101 LAB 9 USING A DATABASE: Tables and Queries
ITEC 101 LAB 9 USING A DATABASE: Tables and Queries In the last lab, we saw how a spreadsheet can be useful for organized storage of information. Some kinds of information, however, have more structure
More informationSQL Simple Queries. Chapter 3.1 V3.01. Napier University
SQL Simple Queries Chapter 3.1 V3.01 Copyright @ Napier University Introduction SQL is the Structured Query Language It is used to interact with the DBMS (database management system) SQL can Create Schemas
More informationADVANTAGES. Via PL/SQL, all sorts of calculations can be done quickly and efficiently without use of Oracle engine.
1 PL/SQL INTRODUCTION SQL does not have procedural capabilities. SQL does not provide the programming techniques of condition checking, looping and branching that is required for data before permanent
More informationMySQL. A practical introduction to database design
MySQL A practical introduction to database design Dr. Chris Tomlinson Bioinformatics Data Science Group, Room 126, Sir Alexander Fleming Building chris.tomlinson@imperial.ac.uk Database Classes 24/09/18
More informationUnit Assessment Guide
Unit Assessment Guide Unit Details Unit code Unit name Unit purpose/application ICTWEB425 Apply structured query language to extract and manipulate data This unit describes the skills and knowledge required
More informationStandard Query Language. SQL: Data Definition Transparencies
Standard Query Language SQL: Data Definition Transparencies Chapter 6 - Objectives Data types supported by SQL standard. Purpose of integrity enhancement feature of SQL. How to define integrity constraints
More informationThe Relational Model. Week 2
The Relational Model Week 2 1 Relations A relation is a more concrete construction, of something we have seen before, the ER diagram. name S.S.N students street city A relation is (just!) a table! We will
More informationProgramming the Database
Programming the Database Today s Lecture 1. Stored Procedures 2. Functions BBM471 Database Management Systems Dr. Fuat Akal akal@hacettepe.edu.tr 3. Cursors 4. Triggers 5. Dynamic SQL 2 Stored Procedures
More informationEE221 Databases Practicals Manual
EE221 Databases Practicals Manual Lab 1 An Introduction to SQL Lab 2 Database Creation and Querying using SQL Assignment Data Analysis, Database Design, Implementation and Relation Normalisation School
More informationBasant Group of Institution
Basant Group of Institution Visual Basic 6.0 Objective Question Q.1 In the relational modes, cardinality is termed as: (A) Number of tuples. (B) Number of attributes. (C) Number of tables. (D) Number of
More informationIntroduction to Data Management. Lecture #4 (E-R Relational Translation)
Introduction to Data Management Lecture #4 (E-R Relational Translation) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements v Today
More informationTutorial 1 Database: Introductory Topics
Tutorial 1 Database: Introductory Topics Theory Reference: Rob, P. & Coronel, C. Database Systems: Design, Implementation & Management, 6th Edition, 2004, Chapter 1. Review Questions 2 7, 9 10. Problems
More information1- a> [5pts] Create the new table by writing and executing a full SQL DDL statement based on the following schema:
1. [20pts] To track the history of financial information changes such as a driver s bank account, you are going to create a table to store the history of all bank account numbers. Once created, this table
More informationCSC 453 Database Technologies. Tanu Malik DePaul University
CSC 453 Database Technologies Tanu Malik DePaul University A Data Model A notation for describing data or information. Consists of mostly 3 parts: Structure of the data Data structures and relationships
More informationCS2300: File Structures and Introduction to Database Systems
CS2300: File Structures and Introduction to Database Systems Lecture 14: SQL Doug McGeehan From Theory to Practice The Entity-Relationship Model: a convenient way of representing the world. The Relational
More informationName: Database Systems ( 資料庫系統 ) Midterm exam, November 15, 2006
1 of 8 pages Database Systems ( 資料庫系統 ) Midterm exam, November 15, 2006 Time: 10:00 ~ 12:20 Name: Student ID: I herewith state that I understand and will adhere to the following academic integrity: I will
More informationCMPT 354 Views and Indexes. Spring 2012 Instructor: Hassan Khosravi
CMPT 354 Views and Indexes Spring 2012 Instructor: Hassan Khosravi Three level vision of a database 1.2 What are views Relations that are defined with a create table statement exist in the physical layer
More informationSQL: A COMMERCIAL DATABASE LANGUAGE. Complex Constraints
SQL: A COMMERCIAL DATABASE LANGUAGE Complex Constraints Outline 1. Introduction 2. Data Definition, Basic Constraints, and Schema Changes 3. Basic Queries 4. More complex Queries 5. Aggregate Functions
More informationCredit where Credit is Due. Last Lecture. Goals for this Lecture
Credit where Credit is Due Lecture 22: Database Design Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2002 Some material presented in this lecture is taken from section
More informationCS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13
CS121 MIDTERM REVIEW CS121: Relational Databases Fall 2017 Lecture 13 2 Before We Start Midterm Overview 3 6 hours, multiple sittings Open book, open notes, open lecture slides No collaboration Possible
More informationSQL Data Definition: Table Creation
SQL Data Definition: Table Creation ISYS 464 Spring 2002 Topic 11 Student Course Database Student (Student Number, Student Name, Major) Course (Course Number, Course Name, Day, Time) Student Course (Student
More informationTool Create Database Diagram Sql Server 2005 Management Studio
Tool Create Database Diagram Sql Server 2005 Management Studio How to Backup a Database using Management Studio / Restore SQL Server database. The backend version is not supported to design database diagrams
More informationOverview. Data Integrity. Three basic types of data integrity. Integrity implementation and enforcement. Database constraints Transaction Trigger
Data Integrity IT 4153 Advanced Database J.G. Zheng Spring 2012 Overview Three basic types of data integrity Integrity implementation and enforcement Database constraints Transaction Trigger 2 1 Data Integrity
More informationMidterm Review. Winter Lecture 13
Midterm Review Winter 2006-2007 Lecture 13 Midterm Overview 3 hours, single sitting Topics: Relational model relations, keys, relational algebra expressions SQL DDL commands CREATE TABLE, CREATE VIEW Specifying
More informationDesigning Tables for an Oracle Database System. From theory to practice
Designing Tables for an Oracle Database System Database Course, Fall 2004 From theory to practice The Entity- Relationship model: a convenient way of representing the world. The Relational model: a model
More informationSQL DATA DEFINITION LANGUAGE
SQL DATA DEFINITION LANGUAGE DATABASE SCHEMAS IN SQL SQL is primarily a query language, for getting information from a database. DML: Data Manipulation Language SFWR ENG 3DB3 FALL 2016 MICHAEL LIUT (LIUTM@MCMASTER.CA)
More informationExploring Microsoft Office Access Chapter 2: Relational Databases and Multi-Table Queries
Exploring Microsoft Office Access 2010 Chapter 2: Relational Databases and Multi-Table Queries 1 Objectives Design data Create tables Understand table relationships Share data with Excel Establish table
More informationLecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University
Lecture 3 SQL Shuigeng Zhou September 23, 2008 School of Computer Science Fudan University Outline Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views
More informationDebapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata
SQL 3 Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata Slides re-used, with minor modification, from Silberschatz, Korth and Sudarshan www.db-book.com Outline Join Expressions Views
More informationCLASS DISCUSSION AND NOTES
Mon CLASS DISCUSSION AND NOTES October 2009 Tue Wed Thu Fri 19 20 21 22 23 AH-6; PBL & Project Peer Evaluations Chap. 7 SQL/DB Construction AH-6; PBL & Project Peer Evaluations Chap. 7 SQL/DB Construction
More informationLecture 04: SQL. Wednesday, October 4, 2006
Lecture 04: SQL Wednesday, October 4, 2006 1 Outline The Project Nulls (6.1.6) Outer joins (6.3.8) Database Modifications (6.5) 2 The Project Application: Boutique online music and book store Project:
More informationIn mathematical terms, the relation itself can be expressed simply in terms of the attributes it contains:
The Relational Model The relational data model organises data as 2-dimensional tables or relations. An example of one such relation would be STUDENT shown below. As we have seen in the wine list example,
More informationMySQL for Developers Ed 3
Oracle University Contact Us: 0845 777 7711 MySQL for Developers Ed 3 Duration: 5 Days What you will learn This MySQL for Developers training teaches developers how to plan, design and implement applications
More informationMySQL for Developers Ed 3
Oracle University Contact Us: 1.800.529.0165 MySQL for Developers Ed 3 Duration: 5 Days What you will learn This MySQL for Developers training teaches developers how to plan, design and implement applications
More informationOracle SQL. murach s. and PL/SQL TRAINING & REFERENCE. (Chapter 2)
TRAINING & REFERENCE murach s Oracle SQL and PL/SQL (Chapter 2) works with all versions through 11g Thanks for reviewing this chapter from Murach s Oracle SQL and PL/SQL. To see the expanded table of contents
More informationCSC 261/461 Database Systems Lecture 6. Fall 2017
CSC 261/461 Database Systems Lecture 6 Fall 2017 Use of WITH The WITH clause allows a user to define a table that will only be used in a particular query (not available in all SQL implementations) Used
More informationOracle Database 10g Express
Oracle Database 10g Express This tutorial prepares the Oracle Database 10g Express Edition Developer to perform common development and administrative tasks of Oracle Database 10g Express Edition. Objectives
More informationExtracting and Storing PDF Form Data Into a Repository
Extracting and Storing PDF Form Data Into a Repository This use case describes how to extract required information from a PDF form document to populate database tables. For example, you may have users
More informationT-SQL Training: T-SQL for SQL Server for Developers
Duration: 3 days T-SQL Training Overview T-SQL for SQL Server for Developers training teaches developers all the Transact-SQL skills they need to develop queries and views, and manipulate data in a SQL
More informationFollow these steps to get started: o Launch MS Access from your start menu. The MS Access startup panel is displayed:
Forms-based Database Queries The topic presents a summary of Chapter 3 in the textbook, which covers using Microsoft Access to manage and query an Access database. The screenshots in this topic are from
More informationCourse Modules for MCSA: SQL Server 2016 Database Development Training & Certification Course:
Course Modules for MCSA: SQL Server 2016 Database Development Training & Certification Course: 20762C Developing SQL 2016 Databases Module 1: An Introduction to Database Development Introduction to the
More informationThe DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.
Managing Data Data storage tool must provide the following features: Data definition (data structuring) Data entry (to add new data) Data editing (to change existing data) Querying (a means of extracting
More informationRelational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )
Topics Relational Model Linda Wu Relational model SQL language Integrity constraints ER to relational Views (CMPT 354 2004-2) Chapter 3 CMPT 354 2004-2 2 Why Study the Relational Model? Most widely used
More informationCSCI 1100L: Topics in Computing Lab Lab 07: Microsoft Access (Databases) Part I: Movie review database.
CSCI 1100L: Topics in Computing Lab Lab 07: Microsoft Access (Databases) Purpose: The purpose of this lab is to introduce you to the basics of creating a database and writing SQL (Structured Query Language)
More informationCOMP3311 Database Systems
The University Of New South Wales Final Exam June 2004 COMP3311 Database Systems Time allowed: 3 hours Total number of questions: 7 Total number of marks: 150 Textbooks, study notes, calculators, mobile
More informationSECTION 1 DBMS LAB 1.0 INTRODUCTION 1.1 OBJECTIVES 1.2 INTRODUCTION TO MS-ACCESS. Structure Page No.
SECTION 1 DBMS LAB DBMS Lab Structure Page No. 1.0 Introduction 05 1.1 Objectives 05 1.2 Introduction to MS-Access 05 1.3 Database Creation 13 1.4 Use of DBMS Tools/ Client-Server Mode 15 1.5 Forms and
More informationMySQL for Beginners Ed 3
MySQL for Beginners Ed 3 Duration: 4 Days What you will learn The MySQL for Beginners course helps you learn about the world's most popular open source database. Expert Oracle University instructors will
More informationWhere Are We? Next Few Lectures. Integrity Constraints Motivation. Constraints in E/R Diagrams. Keys in E/R Diagrams
Where Are We? Introduction to Data Management CSE 344 Lecture 15: Constraints We know quite a bit about using a DBMS Start with real-world problem, design ER diagram From ER diagram to relations -> conceptual
More informationAsst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa
ICS 321 Spring 2011 Constraints, Triggers, Views & Indexes Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 04/04/2011 Lipyeow Lim -- University of Hawaii
More informationdoc. RNDr. Tomáš Skopal, Ph.D. RNDr. Michal Kopecký, Ph.D.
course: Database Systems (NDBI025) SS2017/18 doc. RNDr. Tomáš Skopal, Ph.D. RNDr. Michal Kopecký, Ph.D. Department of Software Engineering, Faculty of Mathematics and Physics, Charles University in Prague
More informationCOSC Assignment 2
COSC 344 Overview In this assignment, you will turn your miniworld into a set of Oracle tables, normalize your design, and populate your database. Due date for assignment 2 Friday, 25 August 2017 at 4
More informationB.C.A DATA BASE MANAGEMENT SYSTEM MODULE SPECIFICATION SHEET. Course Outline
B.C.A 2017-18 DATA BASE MANAGEMENT SYSTEM Course Outline MODULE SPECIFICATION SHEET This course introduces the fundamental concepts necessary for designing, using and implementing database systems and
More informationThe Relational Model 2. Week 3
The Relational Model 2 Week 3 1 We have seen how to create a database schema, how do we create an actual database on our computers? professor(pid : string, name : string) course(pid : string, number :
More informationInformatics 1: Data & Analysis
Informatics 1: Data & Analysis Lecture 3: The Relational Model Ian Stark School of Informatics The University of Edinburgh Tuesday 24 January 2017 Semester 2 Week 2 https://blog.inf.ed.ac.uk/da17 Lecture
More informationWhere are we? Week -4: Data definition (Creation of the schema) Week -3: Data definition (Triggers) Week -1: Transactions and concurrency in ORACLE.
Where are we? Week -4: Data definition (Creation of the schema) Week -3: Data definition (Triggers) Week -2: More SQL queries Week -1: Transactions and concurrency in ORACLE. But don t forget to work on
More informationManual Trigger Sql Server Update Column Changed
Manual Trigger Sql Server Update Column Changed You can rename a table column in SQL Server 2016 by using SQL Server Topic Status: Some information in this topic is preview and subject to change in You
More informationThe Structured Query Language Get Started
The Structured Query Language Get Started Himadri Barman 0. Prerequisites: A database is an organized collection of related data that can easily be retrieved and used. By data, we mean known facts that
More informationSchool of Information and Computer Technology Sirindhorn International Institute of Technology Thammasat University
School of Information and Computer Technology Sirindhorn International Institute of Technology Thammasat University ITS351 Database Programming Laboratory Laboratory #4: Database Design & Administration
More information