Structured Query Language and its components. SQL SQL stands for Structured Query Language. There is a standard SQL called the American National Standards.

Slides:



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

Virtual training week 4 structured query language (SQL)
Introduction to Structured Query Language (SQL)
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.
Databases Lab 5 Further Select Statements. Functions in SQL There are many types of functions provided. The ones that are used most are: –Date and Time.
Databases Week 1, lab 2 Simple selects. About the environment We are using SQL Server for the moment. The server we are using is: –Cian.student.comp.dit.ie.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
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)
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 16 – SQL SEAN J. TAYLOR.
SQL Within PL / SQL Chapter 4. 2 SQL Within PL / SQL SQL Statements DML in PL / SQL Pseudocolums Transaction Control.
Introduction to DBMS and SQL Introduction to DBMS and SQL GUIDED BY : MR. YOGESH SAROJ (PGT-CS) MR. YOGESH SAROJ (PGT-CS) Presented By : JAYA XII –COM.
Database Lecture # 1 By Ubaid Ullah.
Introduction to Databases Chapter 6: Understanding the SQL Language.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Database Technical Session By: Prof. Adarsh Patel.
Introduction to SEQUEL. What is SEQUEL? Acronym for Structural English Query Language Acronym for Structural English Query Language Standard language.
Lecture6:Data Manipulation in SQL, Simple SQL queries Prepared by L. Nouf Almujally Ref. Chapter5 Lecture6 1.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
SQL FUNDAMENTALS SQL ( Structured Query Language )
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Quick review of SQL And conversion to Oracle SQL.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 7 Introduction to Structured.
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.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL Structured Query Language 1. Data Definition Language (DDL) is used to manage table and define data structure i.e. CREATE, ALTER, DROP Data Control.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
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)
SQL. Originally developed by IBM Standardized in 80’s by ANSI and ISO Language to access relational database and English-like non-procedural Predominant.
SQL Introduction to database and SQL. Chapter 1: Databases and Database Users 6 Introduction to Databases Databases touch all aspects of our lives. Examples:
Dr. Chen, Oracle Database System (Oracle) 1 Chapter 7 User Creation and Management Jason C. H. Chen, Ph.D. Professor of MIS School of Business Gonzaga.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
1 Database Fundamentals Introduction to SQL. 2 SQL Overview Structured Query Language The standard for relational database management systems (RDBMS)
 CONACT UC:  Magnific training   
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
SQL Basics Review Reviewing what we’ve learned so far…….
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.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
SQL Query Getting to the data ……..
Managing Privileges.
Connect to SQL Server and run select statements
The Basics of Data Manipulation
Introduction To Database Systems
SQL 101.
DATABASE MANAGEMENT SYSTEM
The Basics of Data Manipulation
مقدمة في قواعد البيانات
SQL Fundamentals in Three Hours
SQL .. An overview lecture3.
Contents Preface I Introduction Lesson Objectives I-2
Chapter # 7 Introduction to Structured Query Language (SQL) Part I.
Lecuter-1.
INTRODUCTION A Database system is basically a computer based record keeping system. The collection of data, usually referred to as the database, contains.
Presentation transcript:

Structured Query Language and its components

SQL SQL stands for Structured Query Language. There is a standard SQL called the American National Standards Institute’s 2003 Standard SQL (ANSI:2003 SQL) Most database vendors cover much of the standard, but do not adhere to it completely. –Note, when you start using Oracle SQL, you will see that many of the functions are different.

Database Vendors While there is a standard, there are many providers of database systems. Some of the providers you may find: –Oracle –Microsoft SQL Server –Microsoft Access (very limited) –MySQL (open source – popular for projects) –PostGres (open source)

Some definitions Before explaining SQL, let’s look at some definitions: –Metadata: This is data about data, i.e. table definitions, column definitions, etc. –Data: This is the value that is held in the database, that must follow the rules of the metadata. –Transaction: A transaction is a unit of work, passed to the database for processing. –Session: A process that connects to the database, relating an individual user to a specific database (or schema) allowing the user to interact with the database, ending when the user disconnects from the database.

SQL – What’s in it? SQL is made up of different categories of commands: –Data Definition Language –Data Manipulation Language –Transaction control statements –Session or data control statements

Data Definition Language (DDL) This consists of commands that enable the database administrator, in association with the application developer, to manipulate the infrastructure of the database. This infrastructure is known as the conceptual schema. It enables definition of the metadata. The commands used to do this are: –CREATE –DROP –ALTER –TRUNCATE

Data Manipulation Language (DML) This consists of commands that enable the application developer to manipulate the data in the tables. The commands used are: –SELECT –INSERT –UPDATE –DELETE –MERGE

Transaction Control Statements These statements allow the application developer to group DML statements, in order to conduct a transaction. A transaction is a unit of work, passed to the database for processing. A transaction will often require: –Selection from one or more tables or views –Insertion to one or more tables or views –Update to one or more tables or views –Deletion from one or more tables. Examples: –Place an order for several items –Register as a student –Pay a phone bill.

Transaction Control Statements Most of the statements used during a transaction are DML statements (some DDL statements may be used). There are also transaction safeguard statements. These are: –Commit –Rollback

Data Control Language (DCL) These consist of statements that allow the database (schema) owner to control either his / her own sessions, or sessions of other users trying to access his / her data. The statements are: –GRANT –REVOKE –And various SET commands (Session control)

So far we have met… SELECT INSERT CREATE DROP Let’s look back at them.

SELECT This statement is very versatile and is the single retrieval mechanism. Its basic components are –SELECT –Field-list –FROM –Table-list We have tried these in the labs, and will continue to do so.

SELECT field-list The field-list in a SELECT statement can be: –A wildcard character * to denote all eligible fields. –A column name that is unique to one of the tables in the table list. –A table-name.column-name to specify a column from a specific table from the table list. –A database.table-name.column-name to specify a column in a specific table in a specific database Please note: Oracle calls the domain in which the tables reside a schema. SQL Server calls this domain a database. –A derived field

Derived fields in the SELECT field- list Fields can be derived by: –Performing calculations on column-fields from the table-list. E.g. unitprice * quantity as linecost –Using functions on the column-fields from the table list. E.g. day(orderdate) –Using database provided functions. E.g. SQL Server: getdate() gets the current date from the system, not from any table. Oracle: Select sysdate from dual; (Dual is a working storage area for use in sessions connected to the database).

Table-list Initially, the queries we do will be on single tables, but as we get more fluent with SQL, we will start to do multi-table selects. The tables must belong to the same database / schema. Sometimes the database/schema name is required to qualify the table name. –See later.

Additions to Select If you think of a table (e.g. Dog) as a 2D grid, the column- list manipulates the columns: DogIdNameWeightAgeDietExerciseBreed_Id 1Goldie403Standard Glab 2Mutt462Standard Glab 3Spot444Standard Pood 4Sooty555Standard Blab 5Beauty503Specialised Grtv 6Jack674Specialised GDan 7Pal555Standard Blab I’ve shortened the column names here to fit it in the slide.

Select name, age from dog This query picks out specific columns from the table. DogIdNameWeightAgeDietExercise Breed_I d 1Goldie403Standard Glab 2Mutt462Standard Glab 3Spot444Standard Pood 4Sooty555Standard Blab 5Beauty503 Specialise d Grtv 6Jack674 Specialise d GDan 7Pal555Standard Blab

To pick out rows: This is called projection and is done using the WHERE clause. This clause goes after the basic select: SELECT column-list FROM table-list WHERE condition The condition usually relates to a value in one or more of the columns from the column list.

Conditions The conditions can include: >,, =, !=, NOT, between, IS NULL, IS LIKE. The IS NULL returns a true if the value in the column is null, and a false otherwise. You will NEVER get anything if you use the condition WHERE column = NULL –Null means undefined. You cannot equate to undefined!

LIKE LIKE allows us to match patterns in strings. Wildcard characters can be used to represent –A character from a string _ –A variable length substring from a string %.

Manipulating ROWS The WHERE clause allows to choose from specific ROWS in our query: SELECT dogname, dogage FROM dog WHERE dogage BETWEEN 2 and 4 Look back at the exercises we did last week.

Formatting output We looked at date formatting last week in the lab. What other formatting may we want? –String formatting Concatenation: –SQL Server + –Oracle || Renaming –AS clause SELECT corder.unitprice as Price or –SELECT corder.unitprice as ‘Unit Price’ Numeric formatting (use cast, convert (SQL Server) and to_char(Oracle).

Ordering your data To sort the output by a particular column, add the suffix ORDER BY column-name E.g. SELECT dogname, dogage FROM dog ORDER BY dogage DognameDogAge Mutt2 Goldie3 Beauty3 Jack4 Spot4 Sooty5 Pal5

Ordering your data You can reverse the order: SELECT dogname, dogage FROM dog ORDER BY dogage DESC DognameDogAge Sooty5 Pal5 Jack4 Spot4 Goldie3 Beauty3 Mutt2

Ordering your data You can also order it by two columns: SELECT dogname, dogage FROM dog ORDER BY dogage, dogname DESC DognameDogAge Mutt2 Goldie3 Beauty3 Spot4 Jack4 Sooty5 Pal5