SlideServe
Menu
Préférences
© SlideServe · v2026

DBS201: Introduction to Structured Query Language (SQL)

sandro avatar
27 diapositives · 532 Views · Jul 27, 2014

DBS201: Introduction to Structured Query Language (SQL). Lecture 9. Agenda. The basic commands and functions of SQL How to use SQL to query a database to extract useful information (The SELECT statement). Introduction to SQL. SQL: Structured Query Language

DBS201: Introduction to Structured Query Language (SQL) - slide 1
01 / 27DBS201: Introduction to Structured Query Language (SQL)
1 / 17

Télécharger la présentation

DBS201: Introduction to Structured Query Language (SQL)
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. DBS201: Introduction to Structured Query Language (SQL) Lecture 9

  2. Agenda • The basic commands and functions of SQL • How to use SQL to query a database to extract useful information (The SELECT statement)

  3. Introduction to SQL • SQL: Structured Query Language • Designed specifically for communicating with databases • SQL functions fit into three broad categories: • Data definition language (DDL) • Data manipulation language (DML) • Transaction Control Language (TCL)

  4. Introduction to SQL (continued) • Data definition language • SQL includes commands to create • Database objects such as tables • Commands to define access rights to those database objects • Data manipulation language • Includes commands to insert, update, delete, and retrieve data within the database tables objects • Transaction control language • Includes commands to ensure the integrity of the database.

  5. Introduction to SQL (continued) • SQL is relatively easy to learn • Basic command set has a vocabulary of less than 100 words • Sample vocabulary: • CREATE COLLECTION • CREATE TABLE • CREATE VIEW

  6. Introduction to SQL (continued) • Sample vocabulary (continued): • DROP COLLECTION • DROP TABLE • DROP VIEW • ALTER • INSERT • SELECT • DELETE

  7. Introduction to SQL (continued) • American National Standards Institute (ANSI) prescribes a standard SQL • Several SQL dialects exist • Oracle, MySQL, Access etc

  8. Data Manipulation Commands • Retrieve data and manipulate it with • SELECT attributes also called fields FROM table(s) WHERE condition(s) ORDER BY attribute(s)

  9. Sample Table: PART

  10. Listing Table Rows • SELECT • Used to list contents of table • Syntax • SELECT Field1, Field 2,…FROM tablename WHERE Condition 1 AND/OR Condition 2 ORDER BY Field1, Field 2,…

  11. Listing Table Rows At a minimum, must specify what you want to select and where you want to select it from • SELECT PART_NUMBER FROM PART SELECT LAST_NAME, FIRST_NAME FROM EMPLOYEES;

  12. Listing Table Rows, specifying a specific field name

  13. Listing All Table Rows • Asterisk can be used as wildcard character to list all attributes • SELECT * FROM PART

  14. Listing Table Rows with * to represent all field names

  15. Selecting Rows with Comparison Operators • Select partial table contents by placing restrictions on rows to be included in output • Add conditional restrictions to the SELECT statement, using WHERE clause • SELECT * FROM PART WHERE ON_HAND > 30

  16. Listing Table Rows with * to represent all field names

  17. Comparison Operators

  18. Selecting Rows with Comparison Operators Note criteria is in Quotes – PART_NUMBER is a character field SELECT * FROM PART WHERE PART_NUMBER = ‘AX12’

  19. Sorting Output • Data is displayed in the order which it was added to the tables initially • To change the order the data is displayed in, use the ORDER BY clause in the SELECT statement • SELECT * FROM PART ORDER BY ON_HAND

  20. Sorting Output – Single Column SELECT * FROM PART ORDER BY ON_HAND

  21. Sorting Output – Multiple Columns Note how boat name is sorted within owner num SELECT * FROM PART ORDER BY PRICE, PART_NUMBER

  22. Sorting Output • Data is displayed in the order which it was added to the tables initially • To sort data in descending order, use the DESC keyword after each field specified in the ORDER BY clause that is to be displayed in descending order

  23. Changing Titles • The default title is the name of the attribute or field • Example: PART_NUMBER LNAME A better title might be PART NUMBER or Part Number SELECT PART_NUMBER AS ‘Part Number’

  24. Changing Title Example SELECT LAST_NAME, FIRST_NAME, BALANCE FROM PREMIERE.CUSTOMER;

  25. Changing appearance of titles SELECT LAST_NAME as ‘Last Name’, FIRST_NAME, BALANCE FROM PREMIERE.CUSTOMER;

  26. Changing the order of columns Change the order of the columns The data can be stored in any order and the columns in any order in the table. It is the SQL that controls the display. Changing the look again using concatenation SELECT FIRST_NAME || ', ' || LAST_NAME AS "Full Name“ FROM PREMIERE.CUSTOMER; Note the gap after SALLY. …. WHY?

  27. In Summary • SELECT statement • Used to list contents of table • Syntax • SELECT Field1, Field 2,…FROM tablename WHERE Condition 1 AND/OR Condition 2 ORDER BY Field1, Field 2,…