Top Banner
SQL John Nowobilski
23

SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

Jan 14, 2016

Download

Documents

Cora Dawson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

SQLJohn Nowobilski

Page 2: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

What is SQL?Structured Query Language

Manages Data in Database Management Systems based on the Relational Model

Developed in 1970s by IBM

Page 3: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

Relational DatabaseMatches data by common

characteristics within data set

Based on relational algebra and relational calculus

Also known as a schema

Page 4: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

RDBMSRelational Database Management

System

DBMS where data and relationships among data are stored in tables

Data can be accessed without changing forms of tables

Page 5: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

Advanced Clothing Solutions

Page 6: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

QueriesWay to access information from the

Database

All data and relationships are stored in tables

SQL: “SELECT - FROM - WHERE” statement format to access the relations/data stored in schema

Page 7: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

TablesName of the table is the object you

are trying to represent

Consist of a tuple of columns that contain information about that table

OOP: member variables ≈ columns

Page 8: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

Column DatatypesEach column has associated datatype

Set of “primitive” types as in OOP

INT, CHAR, VARCHAR, BOOL, FLOAT

DATE, TIME, YEAR, BLOB

Page 9: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

SELECT - FROM“SELECT” clause accesses columns from

a selected table

Access all columns, or specify which you want to access

“FROM” clause determines which tables to access columns from

Page 10: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

SELECT * FROM articles;

SELECT stock, rating, price FROM inventory;

Page 11: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

WHERE clauseAdds constraints to returned results from

queries

Allows for relationships to be accessed between multiple tables

“AND” clause adds more constraints to returned results

Page 12: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

SELECT * FROM articlesWHERE size =‘M’ AND gender =‘F’;

SELECT price, type FROM articles, inventoryWHERE articles.id = inventory.articleID;

Page 13: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

DISTINCT clauseAllows for distinct results from

columns to be returned

Avoids redundancy in results

Page 14: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

SELECT DISTINCT descriptionFROM articlesWHERE gender = ‘M’ AND type = ‘shirt’;

Page 15: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

CREATE TABLECreates table in the database

Specify column names in CREATE TABLE statement

NOT NULL ensures column isn’t null when entries are inserted

Page 16: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

CREATE TABLE articles(‘id’ INT NOT NULL,‘company_id’ INT NOT NULL,‘type’ VARCHAR(45),‘description’ VARCHAR(160),‘size’ VARCHAR(5),‘color’ VARCHAR(30),‘gender’ VARCHAR(1));

Page 17: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

INSERTAdds entry into a table in the

database

Can populate as many or as few columns as you want, as long as they’re not required for insertion

Page 18: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

INSERT INTOarticles(gender, type, color)VALUES(‘M’, ‘shirt’, ‘red’);

Page 19: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

UPDATEUpdates column values in a table

Can update certain entries, or all entries in the table at once

Page 20: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

UPDATE articles SET size=‘S’, color=‘blue’WHEREType=‘shirt’;

Page 21: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

DELETERemoves entries from a table

Similar to “SELECT-FROM-WHERE” format

Use “DROP” to delete tables

Page 22: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

DELETE FROM articlesWHERE size=‘S’ AND color=‘blue’;

DROP TABLE articles;

Page 23: SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.

Thank youSources:

http://en.wikipedia.org/wiki/SQL

http://en.wikipedia.org/wiki/Relational_database_management_system

http://www.w3schools.com/sql/sql_syntax.asp