1. Trang chủ
  2. » Công Nghệ Thông Tin

SQL basics english ebook

28 383 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 28
Dung lượng 252 KB

Nội dung

SQL Basics SQL Basics Introduction to Introduction to Standard Query Language Standard Query Language SQL SQL – – What Is It? What Is It?   Structured Query Language Structured Query Language   Common Language For Variety of Common Language For Variety of Databases Databases   ANSI Standard BUT ANSI Standard BUT … … . .   Two Types of SQL Two Types of SQL   DML DML – – Data Manipulation Language (SELECT) Data Manipulation Language (SELECT)   DDL DDL – – Data Definition Language (CREATE Data Definition Language (CREATE TABLE) TABLE) Where To Use Where To Use   SQL*Plus SQL*Plus   TOAD TOAD   SQL Navigator SQL Navigator   ODBC Supported Connections ODBC Supported Connections   Excel Excel   Access Access   Lotus 1 Lotus 1 - - 2 2 - - 3 3   Heart of PL/SQL Heart of PL/SQL Pros & Cons of SQL Pros & Cons of SQL   Pros: Pros:   Very flexible Very flexible   Universal (Oracle, Access, Paradox, etc) Universal (Oracle, Access, Paradox, etc)   Relatively Few Commands to Learn Relatively Few Commands to Learn   Cons: Cons:   Requires Detailed Knowledge of the Structure Requires Detailed Knowledge of the Structure of the Database of the Database   Can Provide Misleading Results Can Provide Misleading Results Basic SQL Components Basic SQL Components   SELECT SELECT schema.table. schema.table. column column   FROM table FROM table alias alias   WHERE [conditions] WHERE [conditions]   ORDER BY [columns] ORDER BY [columns]   ; ;   Defines the end of an SQL statement Defines the end of an SQL statement   Some programs require it, some do not (TOAD Does Some programs require it, some do not (TOAD Does Not) Not)   Needed only if multiple SQL statements run in a script Needed only if multiple SQL statements run in a script Optional Elements SELECT Statement SELECT Statement   SELECT Statement Defines WHAT is to be SELECT Statement Defines WHAT is to be returned (separated by commas) returned (separated by commas)   Database Columns (From Tables or Views) Database Columns (From Tables or Views)   Constant Text Values Constant Text Values   Formulas Formulas   Pre Pre - - defined Functions defined Functions   Group Functions (COUNT, SUM, MAX, MIN, AVG) Group Functions (COUNT, SUM, MAX, MIN, AVG)   “ “ * * ” ” Mean All Columns From All Tables In the Mean All Columns From All Tables In the FROM Statement FROM Statement   Example: SELECT state_code, state_name Example: SELECT state_code, state_name FROM Statement FROM Statement   Defines the Table(s) or View(s) Used by Defines the Table(s) or View(s) Used by the SELECT or WHERE Statements the SELECT or WHERE Statements   You MUST Have a FROM statement You MUST Have a FROM statement   Multiple Tables/Views are separated by Multiple Tables/Views are separated by Commas Commas Examples Examples   SELECT state_name, state_abbr SELECT state_name, state_abbr FROM states FROM states   SELECT * SELECT * FROM agencies FROM agencies   SELECT SELECT arithmetic_mean arithmetic_mean – – minimum_value minimum_value FROM annual_summaries FROM annual_summaries WHERE Clause WHERE Clause   Optional Optional   Defines what records are to be included in the query Defines what records are to be included in the query   Uses Conditional Operators Uses Conditional Operators   =, >, >=, <, <=, != (<>) =, >, >=, <, <=, != (<>)   BETWEEN x AND y BETWEEN x AND y   IN ( IN ( list list ) )   LIKE LIKE ‘ ‘ %string %string ’ ’ ( ( “ “ % % ” ” is a wild is a wild - - card) card)   IS NULL IS NULL   NOT {BETWEEN / IN / LIKE / NULL} NOT {BETWEEN / IN / LIKE / NULL}   Multiple Conditions Linked with AND & OR Statements Multiple Conditions Linked with AND & OR Statements   Strings Contained Within SINGLE QUOTES!! Strings Contained Within SINGLE QUOTES!! AND & OR AND & OR   Multiple WHERE conditions are Linked by AND / Multiple WHERE conditions are Linked by AND / OR Statements OR Statements   “ “ AND AND ” ” Means All Conditions are TRUE for the Means All Conditions are TRUE for the Record Record   “ “ OR OR ” ” Means at least 1 of the Conditions is TRUE Means at least 1 of the Conditions is TRUE   You May Group Statements with ( ) You May Group Statements with ( )   BE CAREFUL MIXING BE CAREFUL MIXING “ “ AND AND ” ” & & “ “ OR OR ” ” Conditions Conditions [...]... Column Headers in the Output Aliases Cannot be Keywords Previous SQL With Aliases SELECT mo.mo_id, mo.poc, pa.parameter_desc parameter FROM monitors mo, parameters pa WHERE mo.pa_parameter_code = pa.parameter_code Why Use an Alias? Saves Typing Good Internal Documentation Better Headers If the same column name exists on multiple tables, SQL needs a way to know which element you are referencing (MO_MO_ID . SQL Basics SQL Basics Introduction to Introduction to Standard Query Language Standard Query Language SQL SQL – – What Is It? What Is It?   Structured. Definition Language (CREATE TABLE) TABLE) Where To Use Where To Use   SQL* Plus SQL* Plus   TOAD TOAD   SQL Navigator SQL Navigator   ODBC Supported Connections ODBC Supported Connections.   Excel Excel   Access Access   Lotus 1 Lotus 1 - - 2 2 - - 3 3   Heart of PL /SQL Heart of PL /SQL Pros & Cons of SQL Pros & Cons of SQL   Pros: Pros:   Very flexible Very flexible   Universal

Ngày đăng: 22/10/2014, 16:48

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN