Download presentation
Presentation is loading. Please wait.
Published byClarissa Simon Modified over 7 years ago
1
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 for... defining, querying, modifying, and controlling the data in a Relational Database.
2
2 SQL Standards u SQL standards were originally developed in academia by Dr. E.F. Codd u Commercial institutions now lead the standard by extending SQL to meet the needs of business. u The main commercial database management systems (DBMS) in the industry today are: Oracle, Sybase, Informix, Microsoft SQL Server
3
3 Interactive SQL u The class exercises in use interactive SQL (i.e. SQL in entered on a command line and the results are seen automatically in the data window) u Embedded SQL, which is SQL that is run inside of a computer program, is not covered in the book, but will be a special topic covered in the class
4
4 SQL as a Second Language u SQL is not a “Natural” Language u SQL is Non Procedural u SQL has a Definite Syntax u SQL is freeform, but individual clauses must be in the proper order u SQL can not do everything in a single statement
5
5 Relational Database u What is a Relational Database Management System (RDBMS)? – All data is stored in Tables (i.e. Relations) (grid-like format, similar to a spreadsheet) – The logical representation of data is separate from its physical storage – One high-level language is provided for structuring, querying, and changing information. This, of course, is SQL
6
6 What is RDBMS? - cont. u Supports Selection, Projection and Joins – Selection: What kind of information you see – Projection: The query criteria – Joins:How you connect related information from different tables u Supports the concept of NULL values u Allows VIEWS into the data u Provides Mechanisms for Integrity, Recovery, Authorization, and Transactions
7
7 What are Tables? u They have Rows and Columns (like Files or Spreadsheets) – Rows(like Records) – Columns (like Fields) u A Set of Related Tables is called a Database u Tables are separate, but equal in that... – They have no Hierarchical Ranking – They have no necessary Physical Relationship to each other
8
8 What is an Entity? u An entity is a person, place, or thing for which you wish to hold information u A table is a collection of separate occurrences of an Entity – E.g. the “Employees” table contains information about individual employees u Separate Characteristics are stored for each Occurrence of an Entity – E.g. An individual employee has a name, address, phone number, etc.
9
9 Rows & Columns u A Row is a single occurrence of an Entity u Each Column describes one Characteristic of the Entity
10
10 Example Table u Last NameCity PerrySan Diego SmithLos Angeles JonesLos Angeles u In the above table "Last Name" and "City" are the columns u Each different person and their represent a row of data
11
11 Question u What is a table?
12
12 Answer u A table is a collection of separate occurrences of an Entity
13
13 Question u What is a row?
14
14 Answer u A Row is a single occurrence of an Entity
15
15 Question u Characteristics of an entity are described with ___________?
16
16 Answer u Characteristics of an entity are described with COLUMNS ?
17
17 Primary Key u Each Row is uniquely identified using the Primary Key. u The Primary Key is defined as any Column (or combination of columns) that can be used to uniquely identify a particular row.
18
18 Example u Last NameCity PerrySan Diego SmithLos Angeles JonesLos Angeles u In the above example the Last Name column acts as the PRIMARY key. (Note: names are not usually a good choice, but this is a simple example)
19
19 Question u What is used to distinguish between rows in a table?
20
20 Answer u Rows are distinguished from either other by using a PRIMARY KEY
21
21 Values u A Value can be determined by the intersection of the Row and Column for the row identified by the Primary Key.
22
22 Types of Tables u User Tables hold the data of the system u System Tables hold information about the structure and objects of the database
23
23 Question u What is needed to find a specific value in a table?
24
24 Answer u The Primary Key and a Column
25
25 Physical vs. Logical u The User’s View of the data is independent of the physical storage of the data u Physical storage can change without affecting the logical representation of the data.
26
26 SQL is a High-Level Language u SQL statements can logically be broken in to three high-level sets... u Data ManipulationDML| which can query and update the data u Data DefinitionDDL which defines the objects in a database u Data AdministrationDCL which controls access to the data
27
27 Data Manipulation Statements u The SELECT statement displays information you want to see from the database u The INSERT statement allow you to add rows to the database u The UPDATE statement allows you to change existing column information u The DELETE statement deletes rows of data
28
28 Data DefinitionStatements u The CREATE statement allows you create tables, views, and indexes u The DROP statement allows you to remove tables, views, and indexes
29
29 Data Administration Statements u The GRANT statement allows you to define what userids have access to tables/columns u The REVOKE statement allows you to remove userid access to tables/columns
30
30 Select Statement Introduction u The next series of pages will show you some sample tables and data that we will use to illustrate the Select statement
31
31 Example Tables u Employees Table – Last_name – First_name – City u ZipCodes Table – City – Zip_code
32
32 Data in Example Tables u Employees - Last_nameFirst_nameCity PerrySteveSan Diego SmithWillLos Angeles JonesTommy LeeLos Angeles u ZipCodes - CityZip_code San Diego92001 Los Angeles90211
33
33 Selection u SELECT last_name, city FROM employees u Results: Last NameCity PerrySan Diego SmithLos Angeles JonesLos Angeles
34
34 Projection u SELECT last_name, city FROM employees WHERE city = 'San Diego' u Results: Last NameCity PerrySan Diego
35
35 Joins u SELECT last_name, city, zip_code FROM employees, zipcodes WHERE city = 'San Diego' AND employees.city = zipcodes.city u Results: Last NameCityZip Code PerrySan Diego92001
36
36 Introducing NULL Values u NULL means Unknown, Missing, or Not Applicable u NULL does NOT mean Zero or Blank
37
37 Question u What kind of SQL statement is used to Query information in a database?
38
38 Answer u The SELECT statements querys information from the database
39
39 SQL VIEWs u Views are 'Derived Tables' that allow a different view of the data stored in existing tables u They are not actual copies of the data u User may SELECT against them in the same way as a table u Also known as 'Virtual tables'
40
40 Integrity, Security, Transactions u Integrity insures the consistency and accuracy of the data u Security insures proper authorization to view and/or update the data u Transactions allow data to be saved to the database as a logical unit of work
41
41 Question u TRUE or FALSE? A NULL value means an empty string for character based data
42
42 Answer u FALSE a NULL value in numeric, date, or character based data means Unknown, Missing, or Not Applicable
43
43 Section 1 - Last Page u Study Chapters 2-3 (thru Create statements only) for Section 2 u There is no Test for Section 1
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.