Basic SQL and basic Python

Slides:



Advertisements
Similar presentations
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Advertisements

Murach’s Java SE 6, C21© 2007, Mike Murach & Associates, Inc.Slide 1.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
11 3 / 12 CHAPTER Databases MIS105 Lec14 Irfan Ahmed Ilyas.
MySQL and PHP By Trevor Adams.
CSC 2720 Building Web Applications Database and SQL.
Database Management Systems (DBMS)
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Database Lecture # 1 By Ubaid Ullah.
ASP.NET Programming with C# and SQL Server First Edition
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
1 Overview of Databases. 2 Content Databases Example: Access Structure Query language (SQL)
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Relational Databases Database Driven Applications Retrieving Data Changing Data Analysing Data What is a DBMS An application that holds the data manages.
Key Applications Module Lesson 21 — Access Essentials
Information Building and Retrieval Using MySQL Track 3 : Basic Course in Database.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
IT Faculty Software Engineering Seniors UML for a simple DataBase Management System Prepared by: أنس الأسود بشير الفروان زهير الزعبي ياسر المحمد.
SQL.. AN OVERVIEW lecture3 1. Overview of SQL 2  Query: allow questions to be asked of the data and display only the information required. It can include.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Chapter 3: Relational Databases
 CONACT UC:  Magnific training   
Understand Data Definition Language (DDL) Database Administration Fundamentals LESSON 1.4.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Introduction to Database Programming with Python Gary Stewart
Agenda for Today  DATABASE Definition What is DBMS? Types Of Database Most Popular Primary Database  SQL Definition What is SQL Server? Versions Of SQL.
Creating Indexes Database Systems Objectives Distinguish between the indexes that are created automatically and those that are created manually.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
Understanding Core Database Concepts Lesson 1. Objectives.
INTRODUCTION TO DATABASES (MICROSOFT ACCESS)
Introduction to Dynamic Web Programming
SQL Basic Python SQLite
Client/Server Databases and the Oracle 10g Relational Database
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
MongoDB Er. Shiva K. Shrestha ME Computer, NCIT
Understand Data Manipulation Language (DML)
Applied CyberInfrastructure Concepts Fall 2017
Information Systems Database Management
Understand Data Manipulation Language (DML)
SQL – Application Persistence Design Patterns
Databases and Information Management
ORACLE SQL Developer & SQLPLUS Statements
ISC440: Web Programming 2 Server-side Scripting PHP 3
SQL 101.
System And Application Software
Chapter 8 Working with Databases and MySQL
Chapter 6 System and Application Software
Structured Query Language
مقدمة في قواعد البيانات
Unit I-2.
Databases and Information Management
CS122 Using Relational Databases and SQL
SQL .. An overview lecture3.
Contents Preface I Introduction Lesson Objectives I-2
Relational Database Design
CS1222 Using Relational Databases and SQL
Chapter 6 System and Application Software
Chapter 6 System and Application Software
DATABASE Purpose of database
Database SQL.
Understanding Core Database Concepts
SQL – Application Persistence Design Patterns
Chapter 6 System and Application Software
CS122 Using Relational Databases and SQL
Unit J: Creating a Database
Unit – V Data Controls.
Presentation transcript:

Basic SQL and basic Python SPL – PS12 Basic SQL and basic Python

Overview SQL Data definition language Data manipulation language Basic Python

SQL We would like to have a system that stores data that will have the following features: Store and access data without having to deal with the low level implementation details of storing it. Access specific records without having to read entire files Define relations between different “files”. SQL is the standard way to interact with relational databases.

SQL (cont) SQL consists of two parts: Data Definition Language Data Manipulation Language

Some definitions Table – A table in the database, it holds only one kind of records. For example, TEACHING_ASSISTENTS table: OfficeHours Name ID Thu 08:00-10:00 Shaked 1 Wed 16:00-18:00 Matan 2 Mon 10:00-12:00 Yair 3 Tue 13:00-14:45 Linoy 4 Wed 10:00-12:00 Dolav 5 Wed 12:00-14:00 Hagit 6 Mon 10:30-12:00 Marina 7 Mon 12:15-14:00 Irit 8 Mon 18:00-20:00 Hussien 9

More definitions Record – A row from the table: Primary key – A field that is unique in a table. The field ‘ID’ is a primary key in the TA’s table. Foreign key – A “pointer” to another record in another table. This will allow us to define relations between tables. Thu 08:00-10:00 Shaked 1

Foreign keys Let’s see an example to a foreign key. Time Location GroupNum TA_ID Sun 14-16 90/145 11 1 Sun 18-20 28/103 12 Mon 18-20 34/005 22 4 Sun 12-14 90/236 23 5 Mon 16-18 72/212 62 OfficeHours Name Id Thu 08:00-10:00 Shaked 1 … Tue 13:00-14:45 Linoy 4 Wed 10:00-12:00 Dolav 5

Data Definition Language The Data Definition Language is used to create and destroy databases. These commands will primarily be used by the administrators during the setup and removal phases of a database object.

Data Definition Language (cont) The TA table from earlier could be created using the following syntax: And the Practical Sessions table could be created by this command:

Data Manipulation Language The Data Manipulation Language is used to retrieve, insert, and modify databases. These commands will be used by all database users during the routine operation of the database.

Insert Time Location GroupNum TA_ID Sun 14-16 90/145 11 1 Sun 18-20 28/103 12 Mon 18-20 34/005 22 4 Sun 12-14 90/236 23 5 Mon 16-18 72/212 62 Tue 16-18 90/328 43 8 Insert INTO PRACTICAL_SESSIONS (TA_ID,GroupNum,Location,Time) Values (8,43,’90/328’,’Tue 14-16’)

Update Time Location GroupNum TA_ID Sun 14-16 90/145 11 1 Sun 18-20 28/103 12 Mon 18-20 34/005 22 4 Sun 12-14 90/236 23 5 Mon 16-18 72/212 62 Tue 16-18 90/328 43 8 Tue 14-16 90/328 43 8 Update PRACTICAL_SESSIONS Set Time=“Tue 14-16” Where GroupNum=43

Delete Time Location GroupNum TA_ID Sun 14-16 90/145 11 1 Sun 18-20 28/103 12 Mon 18-20 34/005 22 4 Sun 12-14 90/236 23 5 Mon 16-18 72/212 62 Tue 16-18 90/328 43 8 Delete From PRACTICAL_SESSIONS Where GroupNum=43

Simple Select The Select command is the must commonly used command in SQL. It enables database users to retrieve the specific information they desire from an operational database.

Select example Select * From TEACHING_ASSISTANTS OfficeHours Name ID Thu 08:00-10:00 Shaked 1 Wed 16:00-18:00 Matan 2 Mon 10:00-12:00 Yair 3 Tue 13:00-14:45 Linoy 4 Wed 10:00-12:00 Dolav 5 Wed 12:00-14:00 Hagit 6 Mon 10:30-12:00 Marina 7 Mon 12:15-14:00 Irit 8 Mon 18:00-20:00 Hussien 9

Another Select Example Select Name From TEACHING_ASSISTANTS Name Shaked Matan Yair Linoy Dolav Hagit Marina Irit Hussien

Using Select with Where Select * From TEACHING_ASSISTANTS Where OfficeHours Like ‘Wed%’ OfficeHours Name ID Wed 16:00-18:00 Matan 2 Wed 10:00-12:00 Dolav 5 Wed 12:00-14:00 Hagit 6

Join Operation We could use the Select operation to retrieve the cartesian product of two tables. Most of the time we would like to connect related information. We could use the Join query for that.

Join Operation(cont) The ON operation lets us choose what is the connection between the two tables we would like to connect. The AS keyword can be used to give a table a temporary name. The basic Join operation will ignore any lines in TEACHING_ASSISTANTS that doesn’t fit any line in PRACTICAL_SESIONS. We can force the Join to ignore such lines and show them anyway using Left Join.

Join Example ps.Time ps.Location ps.GroupNum ta.Name Sun 14-16 90/145 11 Shaked Sun 18-20 28/103 12 Mon 18-20 34/005 22 Linoy Sun 12-14 90/236 23 Dolav Mon 16-18 72/212 62

Join Example (cont) ps.Time ps.Location ps.GroupNum ta.Name Sun 14-16 90/145 11 Shaked Sun 18-20 28/103 12 NULL Matan Yair Mon 18-20 34/005 22 Linoy Sun 12-14 90/236 23 Dolav Mon 16-18 72/212 62 Hagit Marina Irit Hussien

Basic Python Python is an open-source, general purpose programming language, that is dynamic, strongly-typed, object-oriented, functional, and memory-managed. Python is an interpreted language, meaning that it uses an interpreter to translate and run its code. The interpreter reads one line of code at a time, just like a script, hence the term “scripting-language”. Python is dynamic, meaning that types are only checked at runtime. But Python is also strongly-typed, meaning that just like Java, you can only execute operations that are supported by the target type.

Coding Python Being an interpreted language, there are more than one way to code Python. One is using Python’s REPL. Another ono is by using files. Python source files use the “.py” extension, and are called modules. You can run modules through the shell.