01. WRITING SQL BASIC STATEMENT
02. RESTRICTING AND SORTING DATA
03. SINGLE-ROW FUNCTIONS
04. DISPLAY DATA FROM MUTIPLE TABLES
05. AGGREGATING DATA USING GROUP FUNCTIONS
06. SUBQUERIES
07. PRODUCING READABLE OUTPUT WITH ISQLPLUS
08. MANIPULATING DATA
09. CREATING AND MANAGING TABLES
10. INCLUDING CONSTRAINTS
11. CREATING VIEWS
12. OTHER DATABASE OBJECTS
13. CONTROLLING USER ACCESS
01. WRITING SQL BASIC STATEMENT
0. Database general
- Oracle9i can manage unstructured data: speadsheets, word document,
powerpoit, XML, mp3, multimedia such as graphics, video
- Oracle9i supports tens of thousands concurrent users, 512 petabytes
(1000 terabytes = 1000x1000 GB) of data
- 4 types of database: network, hierachical, relational, object
- rdb conponents:
> [composed of] collection of objects or relations that store the data
> [managed by] a set of operators that can act on the relations to produce other relations
> [governed by] data integrity for accuracy and consistency
- some explanations:
> relations = 2 dimention table
> row = tuple
> column = attribute
> cardinality = degree
- PK, FK
> PK can be changed, but generally don't change it
> FK must reference (match) PK, UK column or null
- 5 catagory of SQL statements
CAT1: SELECT
select -- data retrieval
CAT2: DML
MIDU (merge, insert, delete, update)
CAT3: DDL
CDART (create, drop, alter, rename, truncate)
CAT4: TC (transaction control)
CSR (commit, savepoint, rollback)
CAT5: DCL (data control language)
GR (grant, revoke)
- delete is DML; while truncate is DDL
- between a and b --> in [a,b]
1. select statement can do:
- projection: 'select * from' is also a projection
- selection: where clause
- joining:
2. case in-sensitive, keyword can't be abbreviated or split across line
3. 'from' clause can't use '+,-,*,/' operator
4. null
- (true and null) = (false or null) = null
- true or null = true
false and null = false
- salary/0 ---> error
salary/null = null
in (1, 3, 5, null, ...) = unkown
5. column alias
AS is optional, "..." means
6. literal
- character, number, date --> 'Heureux', 139, '12-OCT-04'
- char, date literal must be enclosed with ' ';
7. distinct
- must immediately follows 'select'
8. desc
- isql*plus command: desc TVS
STS-20
- select * from a is also a projection
- iSQL*PLUS use "-" for longstatement
- SQL vs. iSQL*PLUS
SQL is a command language used for communicating to the server,
iSQL*PLUS is not although is contains its own command language
and can be used to create scripts
- SQL is ANSI standard language
mickey=> select count(deviceid) from device where 1 in (select customerid from customer where device.customerid = customer.customerid);
count
-------
2
(1 row)
mickey=> select count(deviceid) from device where customerid = 1;
count
-------
2
(1 row)
mickey=> select count(deviceid) from device where customerid <> 1;
count
-------
1144
(1 row)
mickey=> select count(deviceid) from device where 1 not in (select customerid from customer where device.customerid = customer.customerid);
count
-------
1144
(1 row)
显摆一段俺以前的 SQL 笔记
代码:01. WRITING SQL BASIC STATEMENT 02. RESTRICTING AND SORTING DATA 03. SINGLE-ROW FUNCTIONS 04. DISPLAY DATA FROM MUTIPLE TABLES 05. AGGREGATING DATA USING GROUP FUNCTIONS 06. SUBQUERIES 07. PRODUCING READABLE OUTPUT WITH ISQLPLUS 08. MANIPULATING DATA 09. CREATING AND MANAGING TABLES 10. INCLUDING CONSTRAINTS 11. CREATING VIEWS 12. OTHER DATABASE OBJECTS 13. CONTROLLING USER ACCESS 01. WRITING SQL BASIC STATEMENT 0. Database general - Oracle9i can manage unstructured data: speadsheets, word document, powerpoit, XML, mp3, multimedia such as graphics, video - Oracle9i supports tens of thousands concurrent users, 512 petabytes (1000 terabytes = 1000x1000 GB) of data - 4 types of database: network, hierachical, relational, object - rdb conponents: > [composed of] collection of objects or relations that store the data > [managed by] a set of operators that can act on the relations to produce other relations > [governed by] data integrity for accuracy and consistency - some explanations: > relations = 2 dimention table > row = tuple > column = attribute > cardinality = degree - PK, FK > PK can be changed, but generally don't change it > FK must reference (match) PK, UK column or null - 5 catagory of SQL statements CAT1: SELECT select -- data retrieval CAT2: DML MIDU (merge, insert, delete, update) CAT3: DDL CDART (create, drop, alter, rename, truncate) CAT4: TC (transaction control) CSR (commit, savepoint, rollback) CAT5: DCL (data control language) GR (grant, revoke) - delete is DML; while truncate is DDL - between a and b --> in [a,b] 1. select statement can do: - projection: 'select * from' is also a projection - selection: where clause - joining: 2. case in-sensitive, keyword can't be abbreviated or split across line 3. 'from' clause can't use '+,-,*,/' operator 4. null - (true and null) = (false or null) = null - true or null = true false and null = false - salary/0 ---> error salary/null = null in (1, 3, 5, null, ...) = unkown 5. column alias AS is optional, "..." means 6. literal - character, number, date --> 'Heureux', 139, '12-OCT-04' - char, date literal must be enclosed with ' '; 7. distinct - must immediately follows 'select' 8. desc - isql*plus command: desc TVS STS-20 - select * from a is also a projection - iSQL*PLUS use "-" for longstatement - SQL vs. iSQL*PLUS SQL is a command language used for communicating to the server, iSQL*PLUS is not although is contains its own command language and can be used to create scripts - SQL is ANSI standard language