Drill Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Grades: ID, P1, P2, P3 1.Display the.

Slides:



Advertisements
Similar presentations
TURKISH STATISTICAL INSTITUTE 1 /34 SQL FUNDEMANTALS (Muscat, Oman)
Advertisements

 Database is SQL1.mdb ◦ import using MySQL Migration Toolkit 
SQL (2).
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
SQL’s Data Definition Language (DDL) n DDL statements define, modify and remove objects from data dictionary tables maintained by the DBMS n Whenever you.
SQL SQL stands for Structured Query Language SQL allows you to access a database SQL is an ANSI standard computer language SQL can execute queries against.
Database – Part 2a Dr. V.T. Raja Oregon State University.
1ISM - © 2010 Houman Younessi Lecture 3 Convener: Houman Younessi Information Systems Spring 2011.
Chapter 7: SQL, the Structured Query Language Soid Quintero & Ervi Bongso CS157B.
1 Announcements Read 6.7 – 6.10 for Friday Homework 6, due Friday 10/29 Research paper –List of sources - due 10/29 Department Seminar –The Role of Experimentation.
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
1 IT420: Database Management and Organization SQL - Data Manipulation Language 27 January 2006 Adina Crăiniceanu
Database A collection of related data. Database Applications Banking: all transactions Airlines: reservations, schedules Universities: registration, grades.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
Agenda TMA01 M876 Block 3 – Using SQL Structured Query Language - SQL A non-procedural language to –Create database and relation structures. –Perform.
Announcements Read 6.7 – 6.10 for Wednesday Homework 6, due Friday 10/29 Project Step 4, due today Research paper –List of sources - due 10/29.
Oracle Database Administration Lecture 2 SQL language.
BACS--485 SQL 11 BACS 485 Structured Query Language.
SQL 101 for Web Developers 14 November What is a database and why have one? Tables, relationships, normalization SQL – What SQL is and isn’t – CRUD:
Using Special Operators (LIKE and IN)
Oracle DML Dr. Bernard Chen Ph.D. University of Central Arkansas.
SQL for Data Retrieval. Review Questions of Previous Class Q1. Show the sum of hours worked for project with ID 1200 (use ASSIGNMENT table) – Use “SUM”
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Getting to Know SQL. © Jim Hope 2002 All Rights Reserved Data Manipulation SELECT statement INSERT INTO statement UPDATE statement DELETE statement TRANSFORM.
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj RM/SQL Lecture 5 © Akhilesh Bajaj, 2000, 2002, 2003, All.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Reports and Queries Chapter 3 – Access text Reports – Page Queries – Page
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
SQL LANGUAGE and Relational Data Model TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
1 CSE 480: Database Systems Lecture 12: SQL (Nested queries and Aggregate functions)
Structured Query Language Introduction. Basic Select SELECT lname, fname, phone FROM employees; Employees Table LNAMEFNAMEPHONE JonesMark SmithSara
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
SQL advanced select using Oracle 1. 2 Select Simple –data from a single table Advanced –data from more tables join sub-queries.
1 IT420: Database Management and Organization SQL part 3 7 February 2006 Adina Crăiniceanu
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Getting to Know SQL. © Jim Hope 2004 All Rights Reserved Data Manipulation SELECT statement INSERT INTO statement UPDATE statement DELETE statement UNION.
1 SQL Insert Update Delete Create table Alter table.
An Introduction to SQL For CS Overview of SQL  It is the standard language for relational systems, although imperfect  Supports data definition.
Understand Tables and How to Create Them Database Administration Fundamentals LESSON 2.2.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
1 SY306 Web and Databases for Cyber Operations Set #13: SQL SELECT Grouping and sub-queries.
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
April 2002 Information Systems Design John Ogden & John Wordsworth 1 Database Design SQL (1) John Wordsworth Department of Computer Science The University.
Aggregating Data Using Group Functions. What Are Group Functions? Group functions operate on sets of rows to give one result per group.
Introduction to Database SEM I, AY Department of Information Technology Salalah College of Technology Chapter No.3 SQL.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Exam 2 Review. SQL – Create Table REMEMBER!! – Create table mxws.Contact ( ContactID INT(10) NOT NULL,.., primary key (contactID));
SQL LANGUAGE TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Southern Methodist University CSE CSE 2337 Introduction to Data Management Chapter 2.
 MySQL  DDL ◦ Create ◦ Alter  DML ◦ Insert ◦ Select ◦ Update ◦ Delete  DDL(again) ◦ Drop ◦ Truncate.
SQL Reminder Jiankang Yuan Martin Lemke. SQL Reminder - SELECT SELECT column_name1, column_name2, … FROM table_name SELECT * FROM table_name.
Chapter 11 – Data Manipulation: Relational Algebra and SQL1 Unit 9: Data Manipulation: Relational Algebra and SQL IT238: Data Modeling and Database Design.
Standard language for querying and manipulating data Structured Query Language Many standards out there: ANSI SQL, SQL92 (a.k.a. SQL2), SQL99 (a.k.a. SQL3),
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Teacher Workshop Database Design Pearson Education © 2014.
Structured Query Language
The Database Exercises Fall, 2009.
Working with Tables: Join, Functions and Grouping
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
Built in Functions Massaging the data.
Chapter 4 Summary Query.
CSC 453 Database Systems Lecture
Presentation transcript:

Drill Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Grades: ID, P1, P2, P3 1.Display the first and last name of all freshman 2.Display the ID of anyone who is failing a class. 3.Display the ID of anyone is failing all three classes. 4.Display all fields of all freshmen who are under 15 and all seniors who are over Display all upperclassmen who are in A course whose last name starts with ‘P’ 6.Display all students whose last name starts with S, that are between 15 and 19.

Drill Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Address: StudentID, StreetAddress, City, State, Zip HonorRoll: StudentID, GPA 1.Display the first and last name of all students in the Zip 2.Display the LastName and GPA of all Seniors on the Honor Roll 3.Display the cities where each student lives. (list each city once) 4.Display (alphabetically) the last names of all underclassmen. 5.Display the min, max, average of GPA, and total number of honor roll students.(use headers: lowest, highest, average, and total) 6.Display the Last Name and GPA of all students who live in ‘Md’. (hint: you need a join with 3 tables)

Drill #2 (classwork will be collected) Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Address: StudentID, StreetAddress, City, State, Zip HonorRoll: StudentID, GPA 1.Display the first and last name of all students who live in Baltimore and are older than Display the LName and GPA of all ‘A’ Course on the Honor Roll w/ a GPA between 3.8 and 4.0 whose last name starts with ‘P’. 3.Display the LName and GPA of all ‘B’ Course students in the zip (hint: you need a join with 3 tables)

Classwork Create a table called CLASS with the fields: ClassName Not Null Size (Number) Null Teacher (Max 20) Not Null Department (Max 20) Not Null Course (‘A’ or ‘B’) Null

Joins

Keys: Primary Key

Keys: Foreign Key

Joins

Dot Notation Use dot notation when performing a join between two tables with the same column names.

Classwork Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Grades: StudentID, P1, P2, P3 1.Display the full name of all freshman who are failing first period. 2.Display the grades of any student whose name starts with ‘S’.

Distinct

DISTINCT and ORDER BY SELECT DISTINCT [field],.. [field] FROM [table1], [table2] WHERE [condition],.., [condition] ORDER BY [field],.., [field] This will only return unique values for the “DISTINCT”

What does this query do?

SELECT DISTINCT [Field] alias,.. [Field] FROM [Table1] alias, [Table2] alias WHERE [condition] IN {SELECT … } ORDER BY [Field],.. [Field]

SUM, AVG, MIN, MAX, COUNT

SUM, AVG

MIN

COUNT(*)

CREATE Table

CREATE TABLE Tablename ( Field1 datatype [not null OR null],.. Fieldn);

DataTypes

ALTER TABLE

ALTER TABLE ADD ALTER TABLE ADD (field datatype);

INSERT

INSERT INTO …VALUES INSERT INTO [table] VALUES (field1, field2…);

DELETE

UPDATE/SET

GROUP BY Use the GROUP BY Function with Agregate functions (SUM, MIN, MAX, AVG, COUNT) What do you think this query does?

GROUP BY/ HAVING To put conditions on a GROUP BY use the HAVING

Subqueries A subquery is a query within a query. They are general used in the WHERE (condition) statement. SELECT LName FROM Student WHERE StudentID IN (SELECT StudentID FROM HonorRoll);

What does the following SQL statement do?

Entity Relationship Model

SQL so far SELECTDISTINCT, Alias, dot notation FROM Table Alias, (Joins) WHERE IN, IN (SELECT …), BETWEEN AND, Field <> != >= <= Functions: Min(), Max(), Sum(), Avg(), Count(*) Tables: Create, Alter, Insert, Delete, Update