11.11.2015 DAT602 Database Application Development Lecture 3 Review of SQL Language.

Slides:



Advertisements
Similar presentations
Virtual training week 4 structured query language (SQL)
Advertisements

Database Systems: Design, Implementation, and Management Tenth Edition
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
SQL Basics Based on the relational algebra we just learned. Nonprocedural language – what to be done not how Simple, powerful language Used for both data.
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)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
ASP.NET Programming with C# and SQL Server First Edition
1 IT420: Database Management and Organization SQL - Data Manipulation Language 27 January 2006 Adina Crăiniceanu
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems.
Introduction to databases and SQL. What is a database?  A database is an organized way of holding together pieces of information  A database refers.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Sundara Ram Matta Apr 01 st, Sundara Ram Matta Apr 01 st, 2015
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.
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.
Information Technologies and Microsoft SQL Server Day 2 by Alper Özpınar
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.
SQL Unit – 2 Base Knowledge Presented By Mr. R.Aravindhan.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
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,
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.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 5: SQL I Rob Gleasure robgleasure.com.
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.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
ORDER BY Clause The result of a query can be sorted in ascending or descending order using the optional ORDER BY clause. The simplest form of.
Fundamentals of DBMS Notes-1.
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Introduction to Structured Query Language(SQL)
Chapter 8 Working with Databases and MySQL
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
Introduction To Structured Query Language (SQL)
Access: SQL Participation Project
Introduction To Structured Query Language (SQL)
Presentation transcript:

DAT602 Database Application Development Lecture 3 Review of SQL Language

Structured Query Language Database computer language designed for managing data in relational database management systems (RMDBS). Its scope includes data query and update, schema creation and modification, and data access control. Database Application Development - Lecture 3

Different database systems have different SQL languages. These SQL language are extensions of standard SQL language, they provide some additional support to the ANSI SQL-92 standard. Microsoft SQL Server: Transact – SQL ORACLE : Procedural Language/SQL (PL/SQL) Database Application Development - Lecture 3

SQL language command Create Table Alter Table Drop Table Manipulate Table Data Data Query Database Application Development - Lecture 3

Create Table Three aspects you should consider carefully before you create a table. - Data types. These include CHARACTER,INTEGER, FLOAT, and so on. - Data constraints. These include such restrictions as whether NULLS are permitted. -Default values. Default values can be assigned for each column. Database Application Development - Lecture 3

Command for creating a table CREATE TABLE tableName ( column1Name dataType[(size)] [constraints] [default value], column2Name dataType[(size)] [constraints] [default value], column3Name dataType[(size)] [constraints] [default value],...); CREATE TABLE CONTACT_INFO ( CONTACT_IDINTEGERNOT NULL PRIMARY KEY, FIRST_NAMEVARCHAR(20) NOT NULL, LAST_NAMEVARCHAR(30) NOT NULL, STREETVARCHAR(50) NOT NULL ); Database Application Development - Lecture 3

Alter Table : Add column Sometimes, after creating table, we need to alter table, like add, alter or remove a column. Database Application Development - Lecture 3 UserInfo FirstName LastName Age UserInfo FirstName LastName Age Gender Add Syntax of Adding a column: AlTER TABLE TableName ADD newColumnName (size) Example: ALTER TABLE UserInfo ADD Gender char(1)

Alter Table : remove column Database Application Development - Lecture 3 UserInfo FirstName LastName Age UserInfo FirstName LastName Age Gender remove Syntax of removing a column ALTER TABLE TableName DROP COLUMN columnName; Example: ALTER TABLE UserInfo DROP COLUMN Gender;

Alter Table : alter column Database Application Development - Lecture 3 UserInfo FirstName LastName Gender UserInfo FirstName LastName Age alter Syntax of alter column: ALTER TABLE TableName CHANGE OldColumnName NewColumnName Type(Size); Example: ALTER TABLE UserInfo CHANGE Age Gender Char(1);

Drop Table Delete existed table. Syntax of dropping table: DROP TABLE TableName; Example: DROP TABLE UserInfo; Database Application Development - Lecture 3

Data Manipulation INSERT Insert content into a table UPDATE Modify content of a table DELETE Delete content of a table Database Application Development - Lecture 3

INSERT Database Application Development - Lecture 3 NameGender AmyFemale BobMale NameGender AmyFemale BobMale CindyFemale insert Syntax of INSERT: INSERT INTO TableName (Column1, Column2,...) VALUES ( Value1, Value2,...); Example: INSERT INTO UserInfo (Name, Gender) VALUES (‘Cindy’, ‘Female’); Table: UserInfo

UPDATE: single row operation Database Application Development - Lecture 3 NameGender AmyFemale BobMale CindyFemale update NameGender AmyFemale BobMale CindyMale Syntax of Update: UPDATE TableName SET Column1 = [NewValue] WHERE {Condition} Example: UPDATE UserInfo SET Gender = ‘Female’ WHERE Name = ‘Cindy’; Table: UserInfo

UPDATE: multiple rows operation Database Application Development - Lecture 3 NameGenderGrade AmyFemaleA BobMaleA CharlieMaleA DerryMaleA update NameGenderGrade AmyFemaleA BobMaleB CharlieMaleC DerryMaleD Update: UPDATE Grade SET Grade = ‘A’ WHERE Gender= ‘Male’; Table: Grade

DELETE operation Database Application Development - Lecture 3 NameGender AmyFemale BobMale delete NameGender AmyFemale BobMale CindyFemale Syntax of DELETE operation: DELETE FROM TableName WHERE {Condition} Example: DELETE FROM UserInfo WHERE Name = ‘Cindy’; Table : UserInfo

Data Query Retrieve data from a database in response to a query Following part covers terms: SELECT, WHERE, ORDER BY, DISTINCT, AND, OR Database Application Development - Lecture 3

The SELECT statement is the heart of a SQL query. Syntax of SELECT: SELECT Column1, Column2,.. FROM TableName Database Application Development - Lecture 3 NameGender AmyFemale BobMale CindyFemale Name Amy Bob Cindy SELECT Example: SELECT Name FROM UserInfo

WHERE Clause you can restrict the query to return the requested fields from only records that match some specific criteria. SELECT * FROM Table_Student WHERE Gender = ‘Male’ Database Application Development - Lecture 3

Comparison operators -Equality (=) -Inequality (<>) -Greater Than (>) and Greater Than or Equal To (>=) -Less Than (<) and Less Than or Equal To (<=) -IS NULL -IS NOT NULL Database Application Development - Lecture 3

AND, OR You can use AND, OR to combine multiple conditions to filter query result. Syntax of AND, OR SELECT ColumnName FROM TableName WHERE Condition1 {[AND|OR] ConditionN } + Database Application Development - Lecture 3

Example: SELECT store_name FROM Store_Information WHERE Sales > 1000 OR (Sales 275) Database Application Development - Lecture 3 store_nameSalesDate Los Angeles$1500Jan San Diego$250Jan San Francisco$300Jan Boston$700Jan

The DISTINCT keyword eliminates duplicate rows from the results of a SELECT statement. Syntax of DISTINCT: SELECT DISTINCT Column FROM Table Example: SELECT DISTINCT Name FROM UserInfo Database Application Development - Lecture 3 NameCellPhoneNumber Amy Amy Bob Cindy Name Amy Bob Cindy Table: UserInfo Select Distinct result

The ORDER BY clause sorts query results by one or more columns. Syntax of ORDER BY: SELECT Column1, Column2… FROM Table ORDER BY ColumnN A sort can be ascending (ASC) or descending (DESC). If neither is specified, ASC is assumed. Database Application Development - Lecture 3

Alias. We can give a simple, short table or column names to represent original long, complex names. Syntax of alias: SELECT “TableAlias”.”ColumnName“ “ColumnAlias” FROM “TableName” “TableAlias" Example of Alias: SELECT A1.UserFullName Name FROM UserInfo A1; Database Application Development - Lecture 3

Sort function is very useful for locating the maximal or minimal value. Example: SELECT * FROM UserInfo ORDER BY Age DESC Database Application Development - Lecture 3 NameAge Amy24 Bob37 Cindy21 Derry42 NameAge Derry42 Bob37 Amy24 Cindy21 Table: UserInfoResult set Select Order by

Multiple table joint query. In well designed database, data in different tables are not overlapped. Most of time, the data we need is distributed in several different tables. So we need combine these related tables to do a joint query. Database Application Development - Lecture 3

Multiple tables joint query Database Application Development - Lecture 3 IDName 1Anny 2Bob 3Charlie IDCourseGrade 1MathA 1EnglishB 2GeographyA 3HistoryC Table: STUDENT_INFO Table: GRADE_INFO Get Anny’s grade: SELECT * FROM STUDENT_INFO s, GRADE_INFO g WHERE s.ID = g.ID AND s.Name = “Bob” s.IDs.Nameg.IDg.Courseg.Grade 2Bob2GeographyA Query result

You can find more detail on following website: Database Application Development - Lecture 3