Introduction to SQL Steve Perry Email: [email protected].

16
Introduction to SQL Steve Perry Email: [email protected]

Transcript of Introduction to SQL Steve Perry Email: [email protected].

Page 1: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

Introduction to SQL

Steve Perry

Email: [email protected]

Page 2: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

What is SQL?

• SQL is an abbreviation for Structured Query Language.• It is generally pronounced “Sequel”• SQL is a unified language for... defining, querying, modifying,

and controlling the data in a Relational Database.

2

Page 3: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

SQL Standards

• SQL is a standard, not a software product• Commercial institutions now lead the standard by extending

SQL to meet the needs of business.• The main commercial database management systems (DBMS) in

the industry today are: Oracle (MySQL), Sybase, Microsoft SQL Server

3

Page 4: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

Relational Database

• 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

4

Page 5: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

What is RDBMS? - cont.

• Supports the concept of NULL values• Provides Mechanisms for Integrity, Recovery, Authorization, and

Transactions

5

Page 6: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

What are Tables?

• They have Rows and Columns (like a spreadsheets with rows & columns)

6

Page 7: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

What is a Database

• A Set of Related Tables is called a Database• Tables are separate, but equal in that...

– They have no Hierarchical Ranking– They have inherent relationship to each other– You can create relationships

7

Page 8: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

What is an Entity?

• An entity is a person, place, or thing for which you wish to hold information

• A table is a collection of separate occurrences of an Entity– E.g. the “Employee” table contains information about individual

employees• Separate Characteristics are stored for each Occurrence of an Entity (i.e

a row)– E.g. An individual employee has a name, address, phone number, etc.

8

Page 9: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

Example Table

• In the above table "Last Name" and "City" are the columns• Each different person and their represent a row of data

9

Page 10: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

Primary Key

• Each Row is uniquely identified using the Primary Key.• The Primary Key is defined as any Column (or combination of

columns) that can be used to uniquely identify a particular row.

10

Page 11: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

Data Manipulation Statements

–The SELECT statement displays information you want to see from the database

–The INSERT statement allow you to add rows to the database–The UPDATE statement allows you to change existing column

information–The DELETE statement deletes rows of data

11

Page 12: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

Example Primary Key

• 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)

12

Page 13: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

Values• A Value can be determined by the intersection of the Column Name

for the row identified by the Primary Key.

• Example: If I wanted to know where “Perry” lives I need only tell SQL about the Primary Key value “Perry” and the City column.

13

Page 14: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

SQL is a High-Level Language

• SQL statements can logically be broken in to three high-level sets...–Data Manipulation DML

which can query and update the data–Data Definition DDL

which defines the objects in a database–Data Administration DCL

which controls access to the data

14

Page 15: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

Data Definition Statements

• The CREATE statement allows you create tables, views, and indexes• The DROP statement allows you to remove tables, views, and indexes

15

Page 16: Introduction to SQL Steve Perry Email: steveperrymail@yahoo.com.

End

16