+ All Categories

SQL 101

Date post: 24-Feb-2016
Category:
Upload: zizi
View: 53 times
Download: 0 times
Share this document with a friend
Description:
SQL 101. Fast and furious 7 classes, one hour in length Homework? Let’s talk Oracle SQL exam Too hard?. Code examples will come from This book:. Database Checkout: Can you login? Install the STUDENT schema: \\newmoon\public\SQL_101 Online Reference: - PowerPoint PPT Presentation
Popular Tags:
21
SQL 101
Transcript
Page 1: SQL 101

SQL 101

Page 2: SQL 101

- Fast and furious

- 7 classes, one hour in length

- Homework? Let’s talk

- Oracle SQL exam

- Too hard?

Page 3: SQL 101

Code examples will come fromThis book:

Page 4: SQL 101

• Database Checkout:

• Can you login?

• Install the STUDENT schema:

• \\newmoon\public\SQL_101

• Online Reference:

• \\newmoon\public\SQL_101\Oracle10g_Comp_Ref\book.pdf

Page 5: SQL 101

Examples: Syntax:

Page 6: SQL 101
Page 7: SQL 101

Relational Database Management System (RDBMS):

An RDBMS typically contains data in tables, essentially a two-dimensional matrix consisting of columns and rows.

Tables: A table typically contains data about a single subject. Each table has a unique name that signifies the contents of the data.

Columns: Columns in a table organize the data further. Each column represents a single, low-level detail about a particular set of data. The name of the column is unique within a table and identifies the data you find in the column.

Rows: Each row usually represents one unique set of data within a table. Each intersection of a column and row in a table represents a value, and some do not which are said to be null. Null is an unknown value… it cannot be evaluated or compared because a null is unknown.

Page 8: SQL 101

Column

Row

Page 9: SQL 101

Primary Key: The purpose of the primary key (PK) is to uniquely identify data within a table. A table may have only ONE PK which consists of one or more columns. If the PK contains multiple columns, it is referred to as a composite primary key. Oracle does not require every table to have a PK, however, it is strongly recommended.

Foreign Keys: If you store students and the students zip code information in one table, each student’s name would have the address information (zip, city, state) repeated for each student in that zip code. If however, the data is split into two tables (STUDENT & ZIPCODE), then when an update is made to the location of the student, only one column needs to be updated vice 3. Eliminating redundancy is one of the key concepts in relational databases and this process is called normalization. The foreign key column (ZIP) happens to have the same column name in the STUDENT table. This makes it easier to recognize the fact that the tables share common column values… this the preferred method, but not mandatory.

Page 10: SQL 101

Primary Key

Page 11: SQL 101

Foreign Key

Page 12: SQL 101

What is SQL?

• An acronym for Structured Query Language

• Pronounced “sequel”

• It is the primary interface with the database and it’s commands allow you to query, insert, update, and delete data.

• DML: Data Manipulation Language (Insert, Update, Merge & Delete data)

• DDL: Data Definition Language (Create, Alter, Drop, Truncate & Rename)

• DCL: Data Control Language (Grant, Revoke)

• Transaction Control: Commit, Rollback, Savepoint

Page 13: SQL 101

Capabilities of a SQL SELECT statement:

A SELECT statement retrieves information from the database. You can do the following when using a SELECT statement:

Projection: You can use the projection capability in SQL to choose the columns in a table that you want returned by your query

Selection: You can use the selection capability in SQL to choose the rows in a table that you want returned by a query

Joining: You can use the join capability in SQL to bring together data that is stored in different tables by creating a link between them

Page 14: SQL 101

So…. Using SQL, how would I see all the data in the COURSE table?

Page 15: SQL 101

So…. Using SQL, how would I see all the data in the COURSE table?

SQL> select * from course;

Page 16: SQL 101

How to limit the rows returned by your query:

Query the COURSE table and return the rows with a cost of 1095 only

Page 17: SQL 101

How to limit the rows returned by your query:

Query the COURSE table and return the rows with a cost of 1095 only

Use the WHERE clause (otherwise known as the “predicate”)

Page 18: SQL 101

How to sort the rows returned by your query:

Query the COURSE table and sort the rows by COURSE_NO

Page 19: SQL 101

How to sort the rows returned by your query:

Query the COURSE table and sort the rows by COURSE_NO

Now, reverse the order of the sort

Page 20: SQL 101

How to sort the rows returned by your query:

Query the COURSE table and sort the rows by COURSE_NO

Now, reverse the order of the sort

Page 21: SQL 101

Using variables in your SQL statement:


Recommended