• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Sql success ch02
 

Sql success ch02

on

  • 249 views

SQL course

SQL course

Statistics

Views

Total Views
249
Views on SlideShare
249
Embed Views
0

Actions

Likes
0
Downloads
2
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Sql success ch02 Sql success ch02 Presentation Transcript

    • SQL Success Chapter 2 slides Stéphane Faroult 1
    • ALPHA 2
    • Don Chamberlin with Ray Boyce (+ 1974) 3
    • select ... 4
    • select ... from ... 5
    • select ... from ... where ... 6
    • QUEL Michael Stonebraker 7
    • range of e is employee retrieve (comp = e.salary / (e.age - 18)) where e.name = "Jones" QUEL Michael Stonebraker 8
    • Movies | Movieid | Title | Country | Year_Released -------------------------------------------------------------------P. IN | | | | > 1985 QBE Moshe Zloof 9
    • Oates Ellison Miner 10
    • components 11
    • CREATE Data Definition Language 12
    • ALTER Data Definition Language 13
    • DROP Data Definition Language 14
    • id 1 2 3 4 5 6 INSERT title title Casablanca Blade Runner On The Waterfront Lawrence Of Arabia Annie Hall Goodfellas country us us us uk us us year_released 1942 1982 1954 1962 1977 1990 Data Manipulation Language 15
    • id 1 2 3 4 5 6 7 8 9 10 11 12 INSERT title country title Casablanca us Blade Runner us On The Waterfront us Lawrence Of Arabia uk Annie Hall us Goodfellas us The Third Man uk Citizen Kane us Bicycle Thieves it The Battleship Potemkin ru Sholay in A Better Tomorrow hk year_released 1942 1982 1954 1962 1977 1990 1949 1941 1948 1925 1975 1986 Data Manipulation Language 16
    • UPDATE id 1 2 3 4 5 6 7 8 9 10 11 12 title country Casablanca us Blade Runner us On The Waterfront us Lawrence Of Arabia uk gb Annie Hall us Goodfellas us The Third Man uk gb Citizen Kane us Bicycle Thieves it The Battleship Potemkin ru Sholay in A Better Tomorrow hk year_released 1942 1982 1954 1962 1977 1990 1949 1941 1948 1925 1975 1986 Data Manipulation Language 17
    • DELETE id 1 2 3 4 5 6 7 8 9 10 11 12 title country Casablanca us Blade Runner us On The Waterfront us Lawrence Of Arabia gb Annie Hall us Goodfellas us The Third Man gb Citizen Kane us Bicycle Thieves it The Battleship Potemkin ru Sholay in A Better Tomorrow hk year_released 1942 1982 1954 1962 1977 1990 1949 1941 1948 1925 1975 1986 Data Manipulation Language 18
    • SELECT id 1 2 3 4 title Casablanca Blade Runner On The Waterfront Lawrence Of Arabia country us us us gb 6 7 8 9 10 11 12 Goodfellas The Third Man Citizen Kane Bicycle Thieves The Battleship Potemkin Sholay A Better Tomorrow us gb us it ru in hk year_released 1942 1982 1954 1962 1990 1949 1941 1948 1925 1975 1986 19
    • 20
    • EMEA Survey, Evans Data, 2011 21
    • EMEA Survey, Evans Data, 2011 22
    • EMEA Survey, Evans Data, 2011 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • Flickr: Jeff Kramer 29
    • Client DBMS 30
    • Client DBMS 31
    • DBMS 32
    • DBMS 33
    • DBMS 34
    • DBMS 35
    • Client 36
    • ECHO 22 21 7 SSH FTP 23 25 88 110 80 143 37
    • ECHO 22 21 7 SSH FTP 23 25 88 110 80 143 38
    • ECHO 22 21 7 SSH FTP 23 25 88 110 80 143 39
    • ECHO 22 21 7 SSH FTP 23 25 88 110 80 143 40
    • $ mysql --user=donald --host=atlas --port=3306 41
    • $ mysql --user=donald --host=atlas --port=3306 $ psql --username donald --host atlas --port 5432 42
    • $ mysql --user=donald --host=atlas --port=3306 $ psql --username donald --host atlas --port 5432 $ sqlplus donald@//atlas:1521/ORCL 43
    • $ mysql --user=donald --host=atlas --port=3306 $ psql --username donald --host atlas --port 5432 $ sqlplus donald@//atlas:1521/ORCL $ clpplus donald@//atlas:50000/DB2 44
    • $ mysql --user=donald --host=atlas --port=3306 $ psql --username donald --host atlas --port 5432 $ sqlplus donald@//atlas:1521/ORCL $ clpplus donald@//atlas:50000/DB2 Database Engine ATLASSQLEXPRESS SQL Server Authentication donald 45
    • create table table_name 46
    • create table table_name ( , , ) 47
    • cReaTE tABle table_name ( , , ) 48
    • tablename = TABLENAME = tABleNamE 49
    • 4ME 50
    • 4ME 51
    • 4ME MY_TABLE2 52
    • 4ME MY_TABLE2 MY TABLE 53
    • 4ME MY_TABLE2 MY TABLE 54
    • create table table_name (column_name , , ) 55
    • create table table_name (column_name datatype , , ) 56
    • Text 57
    • Text Number 58
    • Text Number Date 59
    • Text Number Date Binary 60
    • Text Number Date Binary 61
    • Text datatypes char(length) char 62
    • Text datatypes char(length) char(1) 63
    • Text datatypes char(length) varchar(max length) varchar2(max length) 64
    • Text datatypes char(length) varchar(max length) clob 65
    • Number datatypes int 66
    • Number datatypes int float 67
    • Number datatypes int float numeric number 68
    • Number datatypes int float numeric (precision) 69
    • Number datatypes int float numeric (precision) 999999 99 70
    • Number datatypes int float numeric (precision, scale) 999999 99 71
    • Number datatypes int float numeric (precision, scale) 999999. 99 72
    • Date datatypes datetime date 73
    • Date datatypes datetime timestamp 74
    • Binary datatypes varbinary(max length) 75
    • Binary datatypes varbinary(max length) blob 76
    • create table people ( peopleid first_name surname born died number, varchar2(30), varchar2(30), number(4), number(4 )) 77
    • create table people ( peopleid first_name surname born died int, varchar(30), varchar(30), numeric(4), numeric(4 )) 78
    • Flickr:Daniel Moyle 79
    • create table people (peopleid first_name surname born died int , varchar(30), varchar(30) , numeric(4), numeric(4 )) 80
    • create table people (peopleid first_name surname born died int not null, varchar(30), varchar(30) , numeric(4), numeric(4 )) 81
    • create table people (peopleid first_name surname born died int not null, varchar(30), varchar(30) not null, numeric(4), numeric(4 )) 82
    • create table people (peopleid first_name surname born died int not null, varchar(30), varchar(30) not null, numeric(4), numeric(4 )) 83
    • create table people (peopleid first_name surname born died int not null, varchar(30), varchar(30) not null, numeric(4), numeric(4 )) 84
    • 85
    • 86
    • comment on column people.surname is 'Surname or stage name'; -- comments in an SQL statement start with a double dash 87
    • comment on column people.surname is 'Surname or stage name'; -- comments in an SQL statement start with a double dash 88
    • comment on column people.surname is 'Surname or stage name'; -- comments in an SQL statement start with a double dash 89
    • create table people (peopleid first_name surname born died int not null, varchar(30), varchar(30) not null, numeric(4), numeric(4 )) 45 90
    • No woman should ever be quite accurate about her age. It looks so calculating. Oscar Wilde The Importance of Being Earnest. 91
    • create table people (peopleid first_name surname born died int not null, varchar(30), varchar(30) not null, numeric(4) , not null, numeric(4 )) 92
    • Picture Surname Firstname Birthdate Hepburn Audrey 4-May-1929 93
    • Picture Surname Firstname Birthdate Hepburn Audrey 4-May-1929 Hepburn Audrey 4-May-1929 94
    • Picture Surname Firstname Birthdate Hepburn Audrey 4-May-1929 Hepburn Audrey 4-May-1929 95
    • 96
    • 97
    • CONSTRAINTS 98
    • create table people (peopleid first_name surname born died int not null, varchar(30), varchar(30) not null, numeric(4) not null, numeric(4)) 99
    • int not null, primary key, first_name varchar(30), surname varchar(30) not null, born numeric(4) not null, died numeric(4)) create table people (peopleid 100
    • create table people (peopleid int not null primary key, first_name varchar(30), surname varchar(30) not null, born numeric(4) not null, died numeric(4)) 101
    • create table people (peopleid int not null primary key, first_name varchar(30), surname varchar(30) not null, born numeric(4) not null, died numeric(4) , unique (first_name, surname)) 102
    • For Oracle, PostgreSQL and DB2 ... 'audrey' 'AUDREY' 'Audrey' 103
    • For Oracle, PostgreSQL and DB2 ... 'audrey' 'AUDREY' 'Audrey' ... not for SQL Server, MySQL or SQLite ... 104
    • create table people (peopleid int not null primary key, first_name varchar(30), surname varchar(30) not null, born numeric(4) not null, died numeric(4), unique (first_name, surname)) 105
    • create table people (peopleid int not null primary key, first_name varchar(30), check (first_name = upper(first_name)), surname varchar(30) not null, check (surname = upper(surname)), born numeric(4) not null, died numeric(4), unique (first_name, surname)) 106
    • Chris Date Picture: Douglas Robertson 107
    • Chris Date Picture: Douglas Robertson 108
    • create table movies (movieid int not null primary key, title varchar(60) not null, country char(2) not null, year_released numeric(4) not null check(year_released >= 1895), unique (title, country, year_released)) 109
    • COUNTRIES country_code country_name continent us United States AMERICA cn China ASIA in India ASIA br Brazil AMERICA uk United Kingdom EUROPE ru Russia EUROPE mx Mexico AMERICA it Italy EUROPE de Germany EUROPE 110
    • COUNTRIES country_code country_name continent us United States AMERICA cn China ASIA in India ASIA br Brazil AMERICA uk United Kingdom EUROPE ru Russia EUROPE mx Mexico AMERICA it Italy EUROPE de Germany EUROPE 111
    • create table movies (movieid int not null primary key, title varchar(60) not null, country char(2) not null, year_released numeric(4) not null check(year_released >= 1895), unique (title, country, year_released) foreign key(country) references countries(country_code)) 112
    • credits 113
    • movies credits 114
    • people movies credits 115
    • people movies credits 116
    • 117
    • PROGRAM 118
    • PROGRAM 119
    • Prepare the background 120
    • INSERT SOME_TABLE column1 column2 121
    • INSERT SOME_TABLE column1 column2 122
    • INSERT SOME_TABLE column1 column2 123
    • insert into table_name (list of columns) values (list of values) 124
    • insert into countries(country_code, country_name, continent) values('us', 'United States', 'AMERICA') 125
    • Reminder Hello World 126
    • Reminder HELLO WORLD 127
    • select * from countries 128
    • select * from countries 129
    • 1960 130
    • insert into movies(movieid, title, country, year_released) values (123, 'L''Avventura', 'it', 1960) 131
    • insert into movies(movieid, title, country, year_released) values (123, 'L''Avventura', '' 'it', 1960) 132
    • Entering a date? Flickr: Jason Dgreat 133
    • to_date( '07/20/1969' , 'MM/DD/YYYY') 134
    • SYSDATE 135
    • SYSDATE CURDATE() 136
    • SYSDATE CURDATE() GETDATE() 137
    • FLickr:Steve Jurvetson 138
    • SQL : THE database language. 139
    • SQL : THE database language. Connection : server, port, database, username, password. 140
    • SQL : THE database language. Connection : server, port, database, username, password. Create table: data types + constraints. 141
    • SQL : THE database language. Connection : server, port, database, username, password. Create table: data types + constraints. Keywords and identifiers: not case-sensitive Data : can be CASE-SENSITIVE 142