SQL continued CMSC 461 Michael Wilson. Right back into it  Recap:  Learned how to log in to PostgreSQL  Learned about PostgreSQL data types  Learned.

Slides:



Advertisements
Similar presentations
What is a Database By: Cristian Dubon.
Advertisements

Basic SQL Introduction Presented by: Madhuri Bhogadi.
SQL Data Definition II Stanislava Armstrong 1SQL Data Definition II.
Introduction to SQL Session 1 Retrieving Data From a Single Table.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Chapter 10 Queries and Updating Part C. SQL Copyright 2005 Radian Publishing Co.
WORKING WITH STRUCTURED DATA (1/3) Functional ICT.
SQL Review Tonga Institute of Higher Education. SQL Introduction SQL (Structured Query Language) a language that allows a developer to work with data.
 What is a formula in Excel?  A formula is statement written by the user to be calculated. Formulas can be as simple or as complex as the user wants.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
CSC271 Database Systems Lecture # 12. Summary: Previous Lecture  Row selection using WHERE clause  WHERE clause and search conditions  Sorting results.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
DATA MANIPULATION andCONTROL
Relational Algebra CMSC 461 Michael Wilson. Relational algebra  Before we get into SQL, want to take a look at what exactly SQL is really modeling 
Stored Procedure. Objective At the end of the session you will be able to know :  What are Stored Procedures?  Create a Stored Procedure  Execute a.
SQL CMSC 461 Michael Wilson. Finally, some code  This is where the theory and practice actually come together  Basically taking the relational algebra.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
Joins, views, and subqueries CMSC 461 Michael Wilson.
Adjective Groups and Phrases Grammar & Language. 1. I don’t know much about this topic. 2. I know a little about this topic. 3. I know a bit about this.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
Visual Programing SQL Overview Section 1.
SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.
INSERT Statement. 2 home back first prev next last What Will I Learn? Give examples of why it is important to be able to alter the data in a database.
Database UpdatestMyn1 Database Updates SQL is a complete data manipulation language that can be used for modifying the data in the database as well as.
Retrieving Data in PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Recognize the SQL statements that can.
INFANL01-3 ANALYSE 3 WEEK 3 March 2015 Institute voor Communication, Media en Informatietechnology.
N-ary Relations & Their Applications. 2 n-ary Relations Let A 1, A 2, …, A n be sets. An n-ary relation on these sets is a subset of A 1 x A 2 x … x A.
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
Matrix Multiplication The Introduction. Look at the matrix sizes.
Chapter 13 Triggers. Trigger Overview A trigger is a program unit that is executed (fired) due to an event Event such as updating tables, deleting data.
1 CS 430 Database Theory Winter 2005 Lecture 13: SQL DML - Modifying Data.
Relational Algebra Continued CMSC 461 Michael Wilson.
1 SQL Chapter 9 – 8 th edition With help from Chapter 2 – 10 th edition.
SQL LANGUAGE TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Writing Basic SQL SELECT Statements Lecture
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
IFS180 Intro. to Data Management Chapter 10 - Unions.
SQL and Relational Algebra Edel Sherratt Nigel Hardy Horst Holstein.
SQL Introduction SQL stands for “Structured Query Language” and can be pronounced as “SQL” or “sequel – (Structured English.
Session 1 Retrieving Data From a Single Table
Fundamentals of DBMS Notes-1.
Web Systems & Technologies
Database Access with SQL
CS 106 Computing Fundamentals II Chapter 5 “Excel Basics for Windows”
Chapter 6: Integrity (and Security)
Miscellaneous Excel Combining Excel and Access.
Connect to SQL Server and run select statements
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Advanced select statement Join Other DML commands
Multiplication table. x
Database application MySQL Database and PhpMyAdmin
Current outstanding balance
Handling Exceptions.
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
SQL 101.
Structured Query Language (SQL) William Klingelsmith
PL/SQL Programing : Triggers
PowerPoint Create charts and tables
HAVING,INDEX,COMMIT & ROLLBACK
Writing Basic SQL SELECT Statements
Access/SQL Server Eliminate Duplicates with SELECT DISTINCT
Using CASE Value expression
SQL Tutorial Basic SQL Commands
Multiplication Facts 3 x Table.
Presentation transcript:

SQL continued CMSC 461 Michael Wilson

Right back into it  Recap:  Learned how to log in to PostgreSQL  Learned about PostgreSQL data types  Learned how to create tables and insert data into tables

Select statement  This is how you get data out of tables  This is the great majority of most applications SQL calls  Basic syntax:  SELECT FROM, WHERE

Select statement  Selecting columns  This tells what column values you want coming back in your results  Can be any subset of the columns available in a table  If you want all columns, you can type * instead of listing out the columns  SELECT * FROM test_table WHERE…

Select statement  Selecting tables  You can select from any number of tables  Let’s focus on the use case of just one for now  We will address multi-table selects later

Select statement  Where clause  This is exactly like the conditions piece of the relational algebra select  You are stringing together specific conditions that you want the returned data to meet

Where clauses  Where clauses consist of a series of predicates  These predicates are the terms discussed during the relational algebra lecture  The format is the same   is =, !=, >, >=, <, <=  Can also use <> instead of !=

Predicate examples  address = ‘21 Jump Street’  age >= 21  bloodType = ‘O+’

Where clauses  You can string predicates together using AND or OR

Stringing together predicates  age > 21 AND bloodType = ‘O+’  daysSinceContact > 50 or myOpinionOfThisPerson = ‘Favorable’

Complete select example address daysSinceContact contactPhoneNumber numberTypecontactName 111 Great Street CellPhil 8 Get Out of Here Way WorkBob 7 RUN! Drive CellOctavio 21 Jump Street CellJohnny

Complete select example  SELECT * FROM AddressBook WHERE daysSinceLastContact > 20

Complete select example address daysSinceContact contactPhoneNumber numberTypecontactName 7 RUN! Drive CellOctavio 21 Jump Street CellJohnny

Complete select example  SELECT contactName FROM AddressBook WHERE phoneType = ‘Cell’

Complete select example address daysSinceContact contactPhoneNumber numberTypecontactName 111 Great Street CellPhil 7 RUN! Drive CellOctavio 21 Jump Street CellJohnny

Complete select example  SELECT contactName FROM AddressBook WHERE phoneType = ‘Cell’ and contactName = ‘Octavio’

Complete select example address daysSinceContact contactPhoneNumber numberTypecontactName 7 RUN! Drive CellOctavio

Predicate formulas  You can also use formulas in predicates  Example  age < (20 + 5)  Why this is useful will make more sense later, however

Update statement  This will update specific values in already existing rows in your table  Basic syntax:  UPDATE, SET =, = … WHERE

Update statement  Table selection  You can select multiple tables during one update  Let’s focus on the single table case for now

Update statement  Column value setting  Column = new value  The new value can be another column, a value, or a formula (similar to how predicates work in where clauses)  Can set multiple columns in one statement

Update statement  Where clause  This where clause functions exactly the same as it does with a select statement

Update example address daysSinceContact contactPhoneNumber numberTypecontactName 111 Great Street CellPhil 8 Get Out of Here Way WorkBob 7 RUN! Drive CellOctavio 21 Jump Street CellJohnny

Update example  UPDATE AddressBook SET phoneNumber = ‘ ’ WHERE contactName = ‘Phil’

Update example address daysSinceContact contactPhoneNumber numberTypecontactName 111 Great Street CellPhil 8 Get Out of Here Way WorkBob 7 RUN! Drive CellOctavio 21 Jump Street CellJohnny

Update example  UPDATE AddressBook SET daysSinceLastContact = 0, phoneType = ‘Home’ WHERE contactName = ‘Octavio’

Update example address daysSinceContact contactPhoneNumber numberTypecontactName 111 Great Street CellPhil 8 Get Out of Here Way WorkBob 7 RUN! Drive HomeOctavio 21 Jump Street CellJohnny