SQL Review Sections 1 - SQL and other basic statements.

Slides:



Advertisements
Similar presentations
Database Design Sections 12 & 15 - Introduction to Application Express (APEX) SQL editor, Introduction to SQL statements.
Advertisements

Virtual training week 4 structured query language (SQL)
Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
Introduction to Structured Query Language (SQL)
Introduction to Oracle9i: SQL1 Basic SQL SELECT Statements.
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Writing Basic SQL statement 2 July July July Create By Pantharee Sawasdimongkol.
Database Design Sections 16 & 17 – Columns, Characters, Rows, Concatenations, DISTINCT, DESCRIBE, Logical Operators, Order of Operations, Sorting 9/26/2011.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
Chapter 1 Writing Basic SQL Statements Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina,
Ceng 356-Lab1. Objectives After completing this lesson, you should be able to do the following: Get Familiar with the development environment List the.
Structured Query Language S Q L. What is SQL It is a database programming language developed by IBM in the early 1970’s. It is used for managing and retrieving.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Chapter 2 Basic SQL SELECT Statements
Chapter 2 Basic SQL SELECT Statements Oracle 10g: SQL.
1 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
After completing this lesson, you should be able to do the following: List the capabilities of MySQL SELECT statements Execute a basic SELECT statement.
SQL (DDL & DML Commands)
2 Writing Basic SELECT Statements. 1-2 Copyright  Oracle Corporation, All rights reserved. Capabilities of SQL SELECT Statements Selection Projection.
Copyright  Oracle Corporation, All rights reserved. Writing Basic SQL Statements.
EMPLOYEES (EMP) Key Type OptionalityColumn Name pk*Employee_id oFirst_name *Last_name * oPhone_number *Hire_date Fk1*Job_id oSalary oCommission_pct.
RELATSIOONILISED ANDMEBAASID(alg) SQLi VÕIMALUSED.
Objectives After completing this lesson, you should be able to do the following: Describe each data manipulation language (DML) statement Insert rows.
Database Programming Sections 11 & 12 – Creating, and Managing Views, Sequences, Indexes, and Synonymns.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Introduction to SQL PART Ⅰ 第一讲 Writing Basic SQL SELECT Statements.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
1 Writing Basic SQL Statements. 1-2 Objectives At the end of this lesson, you should be able to: List the capabilities of SQL SELECT statements Execute.
Database Design Sections 17 & 18 – Concatenations, DISTINCT, DESCRIBE, Logical Operators, Order of Operations, Sorting.
Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Satrio Agung Wicaksono, S.Kom., M.Kom.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
Database Programming Sections 14– database transactions and controlling User Access.
Database Design Sections 13 & 16 - Introduction to HTML DB SQL editor, Introduction to SQL statements.
Working with Columns, Characters, and Rows. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Apply the concatenation.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
1 Chapter 2 Basic SQL SELECT Statements. 2 Chapter Objectives Distinguish between an RDBMS and an ORDBMS Identify keywords, mandatory clauses, and optional.
1-1 Copyright  Oracle Corporation, All rights reserved. Logging In to SQL*Plus From Windows environment:From Windows environment: From command line:From.
Database Design Sections 17 & 18 – Columns, Characters, Rows, Concatenations, DISTINCT, DESCRIBE, Logical Operators, Order of Operations, Sorting.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
Writing Basic SQL Statements. Objectives After completing this lesson, you should be able to do the following: –List the capabilities of SQL SELECT statements.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
1 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Oracle 10g Retrieving Data Using the SQL SELECT Statement.
1 Copyright © 2009, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Copyright س Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
1 Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Insert, update, delete TCL. Data Manipulation Language – A DML statement is executed when you: Add new rows to a table Modify existing rows in a table.
Retrieving Data Using the SQL SELECT Statement
Writing Basic SQL SELECT Statements
Manipulating Data.
Writing Basic SQL SELECT Statements
SQL 101.
Retrieving Data Using the SQL SELECT Statement
The Basics of Data Manipulation
Sections 1 - SQL and other basic statements
Sections 1 - SQL and other basic statements
Chapter 2 Views.
“Manipulating Data” Lecture 6.
مقدمة في قواعد البيانات
“Manipulating Data” Lecture 6.
Manipulating Data.
Writing Basic SQL SELECT Statements
Chapter 2 Views.
1 Manipulating Data. 2 Objectives After completing this lesson, you should be able to do the following:  Describe each data manipulation language (DML)
Retrieving Data Using the SQL SELECT Statement
IST 318 Database Administration
DATABASE ADMINISTRATION
Presentation transcript:

SQL Review Sections 1 - SQL and other basic statements

Marge Hohly2 Using APEX SQL editor  You may either type the command into the SQL editor or use the cut and paste option  If you are going to cut/paste the command copy the command from the word document into NotePad. This will drop out hidden characters.  Next copy the command from the NotePad into the editor

Marge Hohly3 Enter SQL command

Marge Hohly4 Display the Table structure  Enter the following command: DESCRIBE MUSIC;  The structure of the table should be shown.

Select command structure  SELECT field1, field2, field3 FROM table_name WHERE condition;  Try the following command SELECT employee_id, first_name, last_name, department_id FROM employees;  SELECT employee_id, first_name, last_name, department_id FROM employees WHERE department_id = 90; Marge Hohly5

6 SQL DESCRIBE  DESCRIBE ;  DESCRIBE employees; Try the last statement.

Marge Hohly7 Insert Data  Note the data types for each column  Inserting data into the table.  Since the table is empty all fields need to be populated, so column names can be omitted  INSERT INTO music VALUES (10,'Marge Hohly','Folk');  This will insert one record into the table  Next display the contents of the table to view the data  SELECT * FROM music;

Marge Hohly8 Typical error messages  The following statement has a spelling error:  SELCT * FROM employees; The error message is: ORA-00900: invalid SQL statement  The following statement incorrectly names the table employee instead of employees:  SELECT * FROM employee; The error message is: ORA-00942: table or view does not exist  Run the correct statement.

Marge Hohly9 Subset of data WHERE clause  SELECT FROM WHERE ;  SELECT first_name, last_name, salary FROM employees WHERE salary > 5000;

Marge Hohly10 Application Express SQL editor  The SQL course will use the three following sets of database tables for examples and practice exercises.  Oracle tables: COUNTRIES, REGIONS, DEPARTMENTS, EMPLOYEES, JOBS, JOB_HISTORY AND JOB_GRADES  DJs on Demand database tables: D_CDS, D_PACKAGES, D_TYPES, D_THEMES, D_CLIENTS, D_VENUES, D_SONGS, D_TRACK_LISTINGS, D_PARTNERS, D_EVENTS, D_PLAY_LIST_ITEMS, D_JOB_ASSIGNMENTS  Global Fast Foods database tables: F_CUSTOMERS, F_REGULAR_MENUS, F_PROMOTIONAL_MENUS, F_SHIFTS, F_STAFFS, F_FOOD_ITEMS, F_ORDERS, F_ORDER_LINES, F_SHIFT_ASSIGNMENTS  Print out these tables for your reference when using the Application Express editor  These tables are available on the Student Resource web page for this class

Marge Hohly11 Review the tables  There are six properties of tables in a relational database:  Property 1: Entries in columns are single-valued.  Property 2: Entries in columns are of the same kind.  Property 3: Each row is unique.  Property 4: Sequence of columns is insignificant.  Property 5: Sequence of rows is insignificant.  Property 6: Each column has a unique name.

Marge Hohly12 Categories of SQL Statements  Data manipulation language (DML) statements Begin with INSERT, UPDATE, DELETE, or MERGE Used to modify the table by entering new rows, changing existing rows, or removing existing rows.  Data definition language (DDL) statements set up, change, and remove data structures from the database. The keywords CREATE, ALTER, DROP, RENAME, and TRUNCATE begin DDL statements.  Transaction control (TCL) statements are used to manage the changes made by DML statements. Changes to the data are executed using COMMIT, ROLLBACK, and SAVEPOINT. TCL changes can be grouped together into logical transactions.  Data control language (DCL) keywords GRANT and REVOKE are used to give or remove access rights to the database and the structures within it.

Marge Hohly13 KEYWORD, CLAUSE, STATEMENT  Throughout this course, the words keyword, clause, and statement are used as follows: A keyword refers to an individual SQL element. For example, SELECT and FROM are keywords. A clause is a part of a SQL statement. SELECT employee_id, last_name,.... is a clause. A statement is a combination of two or more clauses. SELECT * FROM employees; is a SQL statement.

Marge Hohly14 Selection vs. Projection  SELECT salary FROM employees WHERE last_name like ‘Smith’;  Selection (row) Projection (column) IDFirst_nameLast_namesalary 10JohnDoe JaneJones SylviaSmith HaiNguyen6000

Join Marge Hohly15

SELECT statement  SELECT statements can provide the same information depending on how they are written  Example: SELECT * FROM d_songs; SELECT id, title, duration, artist, type_code FROM d_songs; Marge Hohly16

SELECTION  SELECT * FROM employees WHERE department_id = 60;  SELECT * FROM employees WHERE salary > 10000; Marge Hohly17

Projections  A subset of columns  SELECT first_name, last_name, salary FROM employees;  SELECT id, title, artist FROM d_songs; Marge Hohly18

Marge Hohly19 Arithmetic Expressions  Create expressions with number and date data by using arithmetic operators. OperatorDescription +Add -Subtract *Multiply /Divide

Marge Hohly20 Operator Precedence  Operator Precedence Multiplication and division take priority over addition and subtraction. Operators of the same priority are evaluated from left to right. Parentheses are used to force prioritized evaluation and to clarify statements. Remember: Please excuse my dear aunt Sally () ^ * / + -

Marge Hohly21 What is null?  If a row lacks the data value for a particular column, that value is said to be null, or to contain a null. A null is a value that is unavailable, unassigned, unknown, or inapplicable.  A null is not the same as zero. Zero is a number.  A null is not a space. Space is a character.

Marge Hohly22 Column Alias  Renames a column heading  Is useful in naming columns of derived values  Immediately follow the column name  Uses optional AS keyword between the column name and alias  Required double quotation marks if it contains spaces or special characters or is case sensitive

Marge Hohly23 Using Aliases  SELECT last_name name, salary AS Salary, salary*12 “Annual Salary” FROM employees; NAMESALARYAnnual Salary Whalen Hartstein Fay