1. Trang chủ
  2. » Công Nghệ Thông Tin

Introduction to SQL english ebook

165 498 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 165
Dung lượng 462,22 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Introduction toI Structured Query Language I Usually “talk” to a database server I Used as front end to many databases mysql,postgresql, oracle, sybase I Three Subsystems: data descripti

Trang 2

SQL

Trang 3

Introduction to

I Structured Query Language

I Usually “talk” to a database server

I Used as front end to many databases (mysql,postgresql, oracle, sybase)

I Three Subsystems: data description, data access andprivileges

I Optimized for certain data arrangements

I The language is case-sensitive, but I use upper casefor keywords

Trang 4

Introduction to

I Structured Query Language

I Usually “talk” to a database server

I Used as front end to many databases (mysql,postgresql, oracle, sybase)

I Three Subsystems: data description, data access andprivileges

I Optimized for certain data arrangements

I The language is case-sensitive, but I use upper casefor keywords

Trang 5

Introduction to

I Structured Query Language

I Usually “talk” to a database server

I Used as front end to many databases (mysql,postgresql, oracle, sybase)

I Three Subsystems: data description, data access andprivileges

I Optimized for certain data arrangements

I The language is case-sensitive, but I use upper casefor keywords

Trang 6

Introduction to

I Structured Query Language

I Usually “talk” to a database server

I Used as front end to many databases (mysql,postgresql, oracle, sybase)

I Three Subsystems: data description, data access andprivileges

I Optimized for certain data arrangements

I The language is case-sensitive, but I use upper casefor keywords

Trang 7

Introduction to

I Structured Query Language

I Usually “talk” to a database server

I Used as front end to many databases (mysql,postgresql, oracle, sybase)

I Three Subsystems: data description, data access andprivileges

I Optimized for certain data arrangements

I The language is case-sensitive, but I use upper casefor keywords

Trang 8

Introduction to

I Structured Query Language

I Usually “talk” to a database server

I Used as front end to many databases (mysql,postgresql, oracle, sybase)

I Three Subsystems: data description, data access andprivileges

I Optimized for certain data arrangements

I The language is case-sensitive, but I use upper casefor keywords

Trang 9

SQL What is SQL?

I Structured Query Language

I Usually “talk” to a database server

I Used as front end to many databases (mysql,postgresql, oracle, sybase)

I Three Subsystems: data description, data access andprivileges

I Optimized for certain data arrangements

I The language is case-sensitive, but I use upper casefor keywords

Trang 10

Introduction to

I Multiple simultaneous changes to data (concurrency)

I Data changes on a regular basis

I Large data sets where you only need someobservations/variables

I Share huge data set among many people

I Rapid queries with no analysis

I Web interfaces to data, especially dynamic data

Trang 11

Introduction to

I Multiple simultaneous changes to data (concurrency)

I Data changes on a regular basis

I Large data sets where you only need someobservations/variables

I Share huge data set among many people

I Rapid queries with no analysis

I Web interfaces to data, especially dynamic data

Trang 12

Introduction to

I Multiple simultaneous changes to data (concurrency)

I Data changes on a regular basis

I Large data sets where you only need someobservations/variables

I Share huge data set among many people

I Rapid queries with no analysis

I Web interfaces to data, especially dynamic data

Trang 13

Introduction to

I Multiple simultaneous changes to data (concurrency)

I Data changes on a regular basis

I Large data sets where you only need someobservations/variables

I Share huge data set among many people

I Rapid queries with no analysis

I Web interfaces to data, especially dynamic data

Trang 14

Introduction to

I Multiple simultaneous changes to data (concurrency)

I Data changes on a regular basis

I Large data sets where you only need someobservations/variables

I Share huge data set among many people

I Rapid queries with no analysis

I Web interfaces to data, especially dynamic data

Trang 15

Introduction to

I Multiple simultaneous changes to data (concurrency)

I Data changes on a regular basis

I Large data sets where you only need someobservations/variables

I Share huge data set among many people

I Rapid queries with no analysis

I Web interfaces to data, especially dynamic data

Trang 16

SQL When do you need a Database?

I Multiple simultaneous changes to data (concurrency)

I Data changes on a regular basis

I Large data sets where you only need someobservations/variables

I Share huge data set among many people

I Rapid queries with no analysis

I Web interfaces to data, especially dynamic data

Trang 17

I Backends to web sites

I Traditional rules may not be as important

Trang 18

I Backends to web sites

I Traditional rules may not be as important

Trang 19

I Backends to web sites

I Traditional rules may not be as important

Trang 20

I Backends to web sites

I Traditional rules may not be as important

Trang 21

I Backends to web sites

I Traditional rules may not be as important

Trang 22

I Backends to web sites

I Traditional rules may not be as important

Trang 23

I Backends to web sites

I Traditional rules may not be as important

Trang 24

I Backends to web sites

I Traditional rules may not be as important

Trang 25

Introduction to

I console command (mysql -u user -p dbname)

I GUI interfaces are often available

I Interfaces to many programming languages: R,python, perl, PHP, etc

I SQLite - use SQL without a database server

I PROC SQL in SAS

Trang 26

Introduction to

I console command (mysql -u user -p dbname)

I GUI interfaces are often available

I Interfaces to many programming languages: R,python, perl, PHP, etc

I SQLite - use SQL without a database server

I PROC SQL in SAS

Trang 27

Introduction to

I console command (mysql -u user -p dbname)

I GUI interfaces are often available

I Interfaces to many programming languages: R,python, perl, PHP, etc

I SQLite - use SQL without a database server

I PROC SQL in SAS

Trang 28

Introduction to

I console command (mysql -u user -p dbname)

I GUI interfaces are often available

I Interfaces to many programming languages: R,python, perl, PHP, etc

I SQLite - use SQL without a database server

I PROC SQL in SAS

Trang 29

Introduction to

I console command (mysql -u user -p dbname)

I GUI interfaces are often available

I Interfaces to many programming languages: R,python, perl, PHP, etc

I SQLite - use SQL without a database server

I PROC SQL in SAS

Trang 30

SQL Ways to Use SQL

I console command (mysql -u user -p dbname)

I GUI interfaces are often available

I Interfaces to many programming languages: R,python, perl, PHP, etc

I SQLite - use SQL without a database server

I PROC SQL in SAS

Trang 31

Introduction to

I A database server can contain many databases

I Databases are collections of tables

I Tables are two-dimensional with rows (observations)and columns (variables)

I Limited mathematical and summary operationsavailable

I Very good at combining information from severaltables

Trang 32

Introduction to

I A database server can contain many databases

I Databases are collections of tables

I Tables are two-dimensional with rows (observations)and columns (variables)

I Limited mathematical and summary operationsavailable

I Very good at combining information from severaltables

Trang 33

Introduction to

I A database server can contain many databases

I Databases are collections of tables

I Tables are two-dimensional with rows (observations)and columns (variables)

I Limited mathematical and summary operationsavailable

I Very good at combining information from severaltables

Trang 34

Introduction to

I A database server can contain many databases

I Databases are collections of tables

I Tables are two-dimensional with rows (observations)and columns (variables)

I Limited mathematical and summary operationsavailable

I Very good at combining information from severaltables

Trang 35

Introduction to

I A database server can contain many databases

I Databases are collections of tables

I Tables are two-dimensional with rows (observations)and columns (variables)

I Limited mathematical and summary operationsavailable

I Very good at combining information from severaltables

Trang 36

SQL Some Relational Database Concepts

I A database server can contain many databases

I Databases are collections of tables

I Tables are two-dimensional with rows (observations)and columns (variables)

I Limited mathematical and summary operationsavailable

I Very good at combining information from severaltables

Trang 37

Introduction to

Since a single server can support many databases, eachcontaining many tables, with each table having a variety

of columns, it’s easy to get lost when you’re working withdatabases These commands will help figure out what’savailable:

I SHOW DATABASES;

I SHOW TABLES IN database;

I SHOW COLUMNS IN table;

I DESCRIBE table; - shows the columns and theirtypes

Trang 38

Introduction to

Since a single server can support many databases, eachcontaining many tables, with each table having a variety

of columns, it’s easy to get lost when you’re working withdatabases These commands will help figure out what’savailable:

I SHOW DATABASES;

I SHOW TABLES IN database;

I SHOW COLUMNS IN table;

I DESCRIBE table; - shows the columns and theirtypes

Trang 39

Introduction to

Since a single server can support many databases, eachcontaining many tables, with each table having a variety

of columns, it’s easy to get lost when you’re working withdatabases These commands will help figure out what’savailable:

I SHOW DATABASES;

I SHOW TABLES IN database;

I SHOW COLUMNS IN table;

I DESCRIBE table; - shows the columns and theirtypes

Trang 40

Introduction to

Since a single server can support many databases, eachcontaining many tables, with each table having a variety

of columns, it’s easy to get lost when you’re working withdatabases These commands will help figure out what’savailable:

I SHOW DATABASES;

I SHOW TABLES IN database;

I SHOW COLUMNS IN table;

I DESCRIBE table; - shows the columns and theirtypes

Trang 41

SQL Finding Your Way Around the Server

Since a single server can support many databases, eachcontaining many tables, with each table having a variety

of columns, it’s easy to get lost when you’re working withdatabases These commands will help figure out what’savailable:

I SHOW DATABASES;

I SHOW TABLES IN database;

I SHOW COLUMNS IN table;

I DESCRIBE table; - shows the columns and theirtypes

Trang 42

I INTEGER, SMALLINT, BIGINT

I NUMERIC(w,d), DECIMAL(w,d) - numbers with width

w and d decimal places

I REAL, DOUBLE PRECISION - machine and databasedependent

I FLOAT(p) - floating point number with p binarydigits of precision

Trang 43

I INTEGER, SMALLINT, BIGINT

I NUMERIC(w,d), DECIMAL(w,d) - numbers with width

w and d decimal places

I REAL, DOUBLE PRECISION - machine and databasedependent

I FLOAT(p) - floating point number with p binarydigits of precision

Trang 44

I INTEGER, SMALLINT, BIGINT

I NUMERIC(w,d), DECIMAL(w,d) - numbers with width

w and d decimal places

I REAL, DOUBLE PRECISION - machine and databasedependent

I FLOAT(p) - floating point number with p binarydigits of precision

Trang 45

I INTEGER, SMALLINT, BIGINT

I NUMERIC(w,d), DECIMAL(w,d) - numbers with width

w and d decimal places

I REAL, DOUBLE PRECISION - machine and databasedependent

I FLOAT(p) - floating point number with p binarydigits of precision

Trang 46

I INTEGER, SMALLINT, BIGINT

I NUMERIC(w,d), DECIMAL(w,d) - numbers with width

w and d decimal places

I REAL, DOUBLE PRECISION - machine and databasedependent

I FLOAT(p) - floating point number with p binarydigits of precision

Trang 47

SQL Variable Types

SQL supports a very large number of different formats forinternal storage of information

Numeric

I INTEGER, SMALLINT, BIGINT

I NUMERIC(w,d), DECIMAL(w,d) - numbers with width

w and d decimal places

I REAL, DOUBLE PRECISION - machine and databasedependent

I FLOAT(p) - floating point number with p binarydigits of precision

Trang 48

Introduction to

Character

I CHARACTER(L) - a fixed-length character of length L

I CHARACTER VARYING(L) or VARCHAR(L) - supportsmaximum length of L

Trang 49

Introduction to

Character

I CHARACTER(L) - a fixed-length character of length L

I CHARACTER VARYING(L) or VARCHAR(L) - supportsmaximum length of L

Trang 50

Introduction to

Character

I CHARACTER(L) - a fixed-length character of length L

I CHARACTER VARYING(L) or VARCHAR(L) - supportsmaximum length of L

Trang 51

Introduction to

Character

I CHARACTER(L) - a fixed-length character of length L

I CHARACTER VARYING(L) or VARCHAR(L) - supportsmaximum length of L

Trang 52

Introduction to

Character

I CHARACTER(L) - a fixed-length character of length L

I CHARACTER VARYING(L) or VARCHAR(L) - supportsmaximum length of L

Trang 53

Introduction to

Character

I CHARACTER(L) - a fixed-length character of length L

I CHARACTER VARYING(L) or VARCHAR(L) - supportsmaximum length of L

Trang 54

Introduction to

Character

I CHARACTER(L) - a fixed-length character of length L

I CHARACTER VARYING(L) or VARCHAR(L) - supportsmaximum length of L

Trang 55

Introduction to

Character

I CHARACTER(L) - a fixed-length character of length L

I CHARACTER VARYING(L) or VARCHAR(L) - supportsmaximum length of L

Trang 56

Introduction to

Character

I CHARACTER(L) - a fixed-length character of length L

I CHARACTER VARYING(L) or VARCHAR(L) - supportsmaximum length of L

Trang 57

SQL Variable Types (cont’d)

Character

I CHARACTER(L) - a fixed-length character of length L

I CHARACTER VARYING(L) or VARCHAR(L) - supportsmaximum length of L

Trang 58

Introduction to

Suppose we have data measured on the height and weight

of children over a range of ages The first step is deciding

on the appropriate variable types, and creating the tablewith the CREATE TABLE command

CREATE TABLE kids(id CHAR(6),

race SMALLINT,age DECIMAL(6,3),height DECIMAL(7,3),weight DECIMAL(7,3),sex SMALLINT);

Trang 59

SQL CREATE TABLE statement

Suppose we have data measured on the height and weight

of children over a range of ages The first step is deciding

on the appropriate variable types, and creating the tablewith the CREATE TABLE command

CREATE TABLE kids(id CHAR(6),

race SMALLINT,age DECIMAL(6,3),height DECIMAL(7,3),weight DECIMAL(7,3),sex SMALLINT);

Trang 60

Introduction to

We could now enter individual items with the INSERTcommand:

INSERT INTO kids VALUES(100011,2,10.346,

148.5,38.95,1);

This quickly gets tedious We can automate the processusing the LOAD DATA command:

LOAD DATA INFILE ’kids.tab’

INTO TABLE kidsFIELDS TERMINATED BY ’\t’;This will read an entire tab-separated file into thedatabase in one command

Trang 61

Introduction to

We could now enter individual items with the INSERTcommand:

INSERT INTO kids VALUES(100011,2,10.346,

148.5,38.95,1);

This quickly gets tedious We can automate the processusing the LOAD DATA command:

LOAD DATA INFILE ’kids.tab’

INTO TABLE kidsFIELDS TERMINATED BY ’\t’;

This will read an entire tab-separated file into thedatabase in one command

Trang 62

SQL Entering observations into a table

We could now enter individual items with the INSERTcommand:

INSERT INTO kids VALUES(100011,2,10.346,

148.5,38.95,1);

This quickly gets tedious We can automate the processusing the LOAD DATA command:

LOAD DATA INFILE ’kids.tab’

INTO TABLE kidsFIELDS TERMINATED BY ’\t’;

This will read an entire tab-separated file into thedatabase in one command

Trang 63

Introduction to

In SQL, the WHERE clause allows you to operate on subsets

of a table The following comparison operators areavaiable:

I Usual logical operators: < > <= >= = <>

I BETWEEN used to test for a range

I IN used to test group membership

I Keyword NOT used for negation

I LIKE operator allows wildcards

_ means single character, % means anything

I SELECT salary WHERE name LIKE ’Fred %’;

I RLIKE operator allows regular expressions

I Use AND(&&) and OR(||) to combine conditions

Ngày đăng: 22/10/2014, 16:47

TỪ KHÓA LIÊN QUAN