CSC3530 Software Technology Tutorial 4 SQL. SQL / RDBMS Structured Query Language 4 th Generation programming language Tell computer what to do instead.

Slides:



Advertisements
Similar presentations
SQL Rohit Khokher.
Advertisements

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.
Database Basics I101 Summer 2006 Copyright 2004, Matt Hottell.
Introduction to Structured Query Language (SQL)
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Structured Query Language - SQL Carol Wolf Computer Science.
1 A GUIDE TO ORACLE8 CHAPTER 2: Creating and ModifyingDatabaseTables 2.
Introduction to Structured Query Language (SQL)
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
19-Jun-15 SQL. SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell” is the only correct.
1 Chapter 2: Creating and Modifying Database Tables.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Modification of the Database – Deletion Delete all account records at the Perryridge branch.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
Creating Database Tables © Abdou Illia MIS Spring /21/2015.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
Introduction to Structured Query Language (SQL)
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
Oracle Data Definition Language (DDL)
Copyright © Curt Hill SQL The Data Definition Language.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
CSCI 6962: Server-side Design and Programming
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
Database A collection of related data. Database Applications Banking: all transactions Airlines: reservations, schedules Universities: registration, grades.
Introduction to SQL Steve Perry
2440: 141 Web Site Administration Database Management Using SQL Professor: Enoch E. Damson.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
CSC 2720 Building Web Applications Database and SQL.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
1 Creating and Modifying Database Objects. 2 An Oracle database consists of multiple user accounts Each user account owns database objects Tables Views.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
CpSc 462/662: Database Management Systems (DBMS) (TEXNH Approach) Relational Schema and SQL Queries James Wang.
1 Chapter 2: Creating and Modifying Database Objects.
Sql DDL queries CS 260 Database Systems.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
Week 8-9 SQL-1. SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Basic SQL*Plus edit and execute commands SQL*Plus buffer and built-in editor holds the last SQL statement Statements are created in free-flow style and.
CSCI N311: Oracle Database Programming 5-1 Chapter 15: Changing Data: insert, update, delete Insert Rollback Commit Update Delete Insert Statement –Allows.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
CS 3630 Database Design and Implementation
ORACLE SQL Developer & SQLPLUS Statements
SQL data definition using Oracle
SQL-1 Week 8-9.
SQL (Structured Query Language)
Presentation transcript:

CSC3530 Software Technology Tutorial 4 SQL

SQL / RDBMS Structured Query Language 4 th Generation programming language Tell computer what to do instead of how to do An precise way to manipulate data SQL statement update insert select RDBMS – Relation DataBase Management System Oracle mySQL A system that store data in an efficient way that allow us to retrieve and update by issuing SQL statement

Oracle Account Login to your unix account The oracle account password is same as your unix account Login to oracle server Type> source /usr/local/oracle8i/setup Append “source /usr/local/orale8i/setup” in.cshrc file Type> sqlplus Input account and password Password given in You can start executing SQL statement Supp. notes from course CSC3170 Fall

Database Schema staff(code, name, phone, , password, rank) Underline means key Generic form Table_name (field_name1, field_name2, …) codeNamephone Passwordrank L2345Le

Create Table create table staff ( code char(10) not null, name varchar2(50), phone char(8), varchar2(50), password varchar2(10), rank varchar2(20), primary key (code) ); Table name – staff char(10) – fixed length string (length = 10) varchar2(50) – variable length string (max. length = 50) not null – cannot be missing primary key – indicate code is unique to differentiate different records

Cont’d Other data type int or integer numeric(p,d) – totally p digits, with d digits on the right of decimal point float(n) – floating point number with at least n digits date – date in (4 digit) year, month, day time – time in hours, minutes and seconds Altering table that already created alter table staff drop phone alter table staff add phone varchar2(20)

Inserting/Deleting Records insert into staff (code, name, phone, , password, rank) values (‘test’, ‘test’, ‘ ’, ‘1234’, ‘Manager’); string are embraced by single quote Integer does not need to be embraced Syntax: insert into “table_name”(“fields”) values (“fields”); delete staff where name=‘Vernon’; The row with name equals Vernon is drop Syntax : delete “table_name” where “condition”;

Updating Records Suppose you issued an invoice, you have to subtract the items you sold from the stock update product set on_hand=on_hand-5 where code=‘B2345’; Suppose a staff change his password Update staff set password=‘newpassword’ where code=‘staffid’; Suppose an invoice need to be voided Update invoice set voided=‘true’ where invoice_number=‘abcde123’;

Selecting Records Product(code, category, name, on-hand, low-limit) select code,name from product where on_hand < low_limit; Syntax: select “field_name” from “table_name” where “condition”; codecategorynameOn-handLow-limit A1234PrinterCannon B2345DVJVC C3456LCDSharp D4567MouseLogitech E5678Hard diskIBM codeName A1234Cannon1234 D4567Logitech4567

Joint Table Query Sometimes you need to do complex query Find those suppliers that supply us the product which are out of stock now select S.name from supplier S, product P, supplying SU where S.code=SU.supplier_code and SU.product_code=P.code and P.on_hand < P.low_limit; If you don’t use join table, you may Find product-code that is out of stock Find the supplier-code that supply that product-code Find the name of supplier with that supplier-code

Nested Query / Partial Match Instead of join table, you can make nested query select S.name from supplier S where S.code in (select SU.supplier_code from supplying SU where SU.product_code in (select P.code from product P where P.on_hand<P.low_limit)); You want to find all product which name consist of “er” % here means any character select * from product where name like ‘%er%’;

Beyond The Basics Adding constraint for a table, if violated, error will occur create table product ( code char(10) not null, category varchar2(50), name varchar2(50), on_hand integer, low_limit integer, primary key (code), check (on_hand >= 0)); When you issue invoice to sell an item, you need to deduct it from the product table, error will occur if you make the on_hand < 0, so …

Cont’d Find the best selling product’s product_code select I.product_code from invoice_item I group by I.product_code having sum (I.qty*I.price) >=all (select sum(I1.qty*I1.price) from invoice_item I1 group by I1.product_code); To interpret First, find the sales figure of each product Second, find the product which sales figure is highest Rank the product by their sales figure select I.product_code, sum(I.qty*I.price) as sales from invoice_item I group by (I.product_code) order by sales desc;

OLAP OLTP – On line Transaction Processing Support daily transaction of a company Sales in the outlet Recording working hours of staff Mainly consist of update to a single table OLAP – On line Analytical Processing Decision support for an enterprise The trend of a product base on its sales figure How is the utilization of staff in a company Mainly consist of join table query (we call it view) The two query introduced previously is a simple kind of OLAP