The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.

Beginning SQL - Paul Wilton

Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by Leander Lim, 2022-12-01 22:11:08

Beginning SQL

Beginning SQL - Paul Wilton

conditions duplication, 30
efficiency improvements, 145–149
conditions, 12 entering in databases
configuration options
new data inserts, 41–44
MySQL installation, 395–396 updates, 45–46
Oracle installation, 446–447 WHERE clause, 47–49
confirmation message, MySQL installation, extracting from databases
aliases, 56
400 BETWEEN operator, 66–67
connection information concatenation, 82
IN operator, 73–75
MySQL installation, 397 LIKE operator, 70–72
Query Browser tool, 402, 404–405 NOT LIKE operator, 72
constraints NOT operator, 66
ADD CONSTRAINT, 137 NULL values, 113–115
CHECK, 125, 129–132 operator precedence, 62–65
FOREIGN, 135–139 ORDER BY clause, 75–79
NOT NULL, 124–125 results, filtering, 56–60
overview, 123 rows, returning values from, 55–56
PRIMARY KEY, 132–134 SELECT statement, 53–54
UNIQUE, 125–129 inconsistent data problems, 321–322
contact details screen, IBM installation, 413 logical division, 29–32
conventions, 4 numerical, delimiters around, 41
conversions redundancy, well designed databases, 9
data types, 179–180 sharing, database design structure, 10
number-to-character, 363 splitting into tables, 119
copying data in tables, 185 summaries, 189
correlated subqueries, 253–255 uncommitted data problems, 321
correlation names, 216 validation
correlation variable, 253 CHECK constraint, 125, 129–132
corruption, relational databases, 39 design improvement, 153–154
COUNT() function, 192–194 FOREIGN KEY constraint, 135–139
CPUs (central processing units), 351 NOT NULL constraint, 124–125
CREATE DATABASE statement, 17 performance improvement, 145–149
CREATE INDEX statement, 140 PRIMARY KEY constraint, 132–134
CREATE TABLE statement, 25–26 UNIQUE constraint, 125–129
CREATE USER statement, 330 Data Control Language (DCL), 11
CREATE VIEW statement, 290 Data Manipulation Language (DML), 11
cross joins, 213–214 data sets
combining, 226–230
D joins, 102–106

data
copying, 185
deleting from databases, 49–50

480


databases Index

data types databases. See also tables
brackets, 25 alternatives to, 10
categories, 18 creation
char, 20, 22 CREATE DATABASE statement, 17
character, 88 data type fields, 18–22
character string, 22–23 example database, 35–38
conversions, 179–180 name punctuation, 18
database comparisons, 19 Query Analyzer tool, 17
database creation example, 37 relational database organization, 14–16
date, 21, 264 requirement details, 35
datetime, 264 SQL syntax, 16–17
decimal data redundancy, 9
numerical data, 23–24 data sharing capabilities, 10
storage allocation, 21 defined, 8
defined, 18 deleting
descriptions, 20–21 data deletion, 49–50
fixed-length, 22 discussed, 18
floating-point numbers, 23 design principles
int data division specifics, 29–32
discussed, 180 data needs, obtaining and analyzing, 28–29
storage allocation, 21 data type selection considerations, 32–33
UNION operator, 227 efficiency, 30
naming considerations, 154 primary key fields, 33–35
nchar, 20 validation and efficiency, 153–154
numerical, 23–24, 179 entering information in
nvarchar, 20 new data inserts, 41–44
real updates, 45–46
numerical data, 23–24 WHERE clause, 47–49
storage allocation, 21 extracting information from
reasons for, 19 aliases, 56
selection considerations, 32–33 BETWEEN operator, 66–67
smallint, 21 concatenation, 82
storage space used, 20–21 IN operator, 73–75
text-based, 47 LIKE operator, 70–72
time, 21 NOT LIKE operator, 72
varchar, 22 NOT operator, 66
variable length, 22 NULL values, 113–115
operator precedence, 62–65
database administrators (DBAs), 313 ORDER BY clause, 75–79
database caches, 354–355 results, filtering, 56–60
database management systems (DBMS), 8 rows, returning values from, 55–56
database owner (DBO), 329 SELECT statement, 53–54

481


databases (continued) Microsoft SQL Server
authentication mode, 433
databases (continued) computer selection, 430
fields concatenation, 82–85
defined, 14 data type comparisons, 19
field views, 292 discussed, 3
front end programs, 10 downloads, 429
history of, 7 Enterprise Manager, tool, 435
Honeywell Information Systems, Inc., 7 installation types, 431
IBM instance creation, 430
Command Center tool, 416 instance name selection, 432
concatenation, 85–88 Query Analyzer, 435–439
contact details screen, 413 services accounts, 433
data type comparisons, 19 typical installation option, 432
discussed, 3 welcome screen, 429
history of, 7
installation summary details, 415 MySQL
license agreement, 410 account information, installation process,
login information, 412 394
product links, 409–410 character set configuration, 398
protocol details, 414 command line interface access, 401
setup program, 409 concatenation, 88–89
task scheduler options, 414 concurrent connection selection, 397
Ted Codd (IBM research), 7 configuration options, 395–396
tutorial information, 416 confirmation message, installation options,
typical installation option, 411 400
identification, 8 data type comparisons, 19
identifiers, 9, 16 database install file, 391–392
keywords, 17 discussed, 3
literals, 16 drive specification, 397
locking, 314 execution options, 400
Microsoft Access license agreement, 392
blank database link, 424 networking options, 398
code views, 428 password information, 399
concatenation, 82–85 Query Browser tool, 401–405
data type comparisons, 19 typical installation option, 393
default screen, 423 usage options, 396–397
design views, 427 Windows service options, 399
discussed, 3
new table creation, 425 networks, 10
query execution, 426 objects, 14
SQL code, 425–426 operating systems, 11

482


deletion anomaly Index

Oracle processors, 351
concatenation, 85–88 queries, 355–356
configuration options, 446–447 reasons for, 356
data type comparisons, 19 table scans, 361–362
discussed, 3 workstations, 350–351
download link, 444 well designed, 9
history of, 7 when to use, 9–11
installation types, 445 date
SQL*Plus tool, 448–450 date and time data types, 24–25
welcome screen, 444 date data type, 21, 264
datetime data type, 264
personal use, 10 day month_name year formats, 44
queries literals, 58
variations, 24–25
defined, 9 year-month-day formats, 44
results, database extraction, 58–60 DAY() function, 178
reasons for, 9–11 day month_name year date formats, 44
records, 8, 16 DBAs (database administrators), 313
relational DBMS (database management systems), 8
advantages of, 9 DBMS_RANDOM package, 162
corruption, 39 DBO (database owner), 329
defined, 8 DCL (Data Control Language), 11
groups, 8 deadlock locking level, 315–316
organization, 14–16 debugging, error messages, 26
security control, 14 decimals
structure of, 15 decimal data type
rows numerical data, 23–24
locking, 314 storage allocation, 21
returning values from, 55–56 decimal points, rounding numbers, 167
row views, 291 declarative languages, 12–13
security advantages, 10 default screen, Microsoft Access, 423
simple, 8 DELETE statement
theory, 2 subqueries, 259–260
tuning WHERE clause, 49–50
caches, 352–355 deleting
compartmentalized networks, 352 columns from tables, 27
files, 351 data from databases, 49–50
filter redundancy, 363 databases, 18
gigahertz networks, 352 tables, 27–28
hardware, 349–350 users, 331
indexes, 357–361 deletion anomaly, 119
number-to-character conversions, 363
pattern matching, 363 483


delimiters DISTINCT keyword
SELECT statement, 55–56, 194
delimiters, 41 SUM() function, 197
DESC keyword, 142
descending sorting order, 76 division operator (/), 158
design DML (Data Manipulation Language), 11
doubly linked lists, indexes, 359
efficiency, 30 downloading
good database design principles
Command Center tool, 416
data division specifics, 29–32 Microsoft SQL Server, 429
data needs, obtaining and analyzing, 28–29 Oracle, 444
data type selection considerations, 32–33 Query Analyzer tool, 435
primary key fields, 33–35 Query Browser tool, 401
validation and efficiency, 153–154 source code, 4–5
indexes drive specification, MySQL installation, 397
b-tree structure, 357–358 DROP COLUMN statement, 27
character, 168–169 DROP DATABASE statement, 18
CREATE INDEX statement, 140 DROP INDEX statement, 141, 143
doubly linked lists, 359 DROP TABLE statement, 27
dropping, 360 DROP USER statement, 331
multicolumn, 154 DROP VIEW statement, 298
results, speeding up, 139–143 dropping indexes, 360
when to use, 360–361 duplication, data
normalization guidelines duplicated values, avoiding, 142
discussed, 117 overview, 30
first normal form, 118–119 Dynamic Host Configuration Protocol (DHCP),
second normal form, 119–121
third normal form, 121–123 350
transitive dependency, 121
validation E
CHECK constraint, 125, 129–132
design improvement, 153–154 efficiency improvements
FOREIGN KEY constraint, 135–139 data, 145–149
NOT NULL constraint, 124–125 database design, 30
performance improvement, 145–149
PRIMARY KEY constraint, 132–134 Enterprise Manager tool, Microsoft SQL Server
UNIQUE constraint, 125–129 database, 435
design views, Microsoft Access installation,
entries, data
427 new data inserts, 41–44
DHCP (Dynamic Host Configuration Protocol), updates, 45–46
WHERE clause, 47–49
350
DIFFERENCE() function, 175–177 equals operator (=), 47
discussion groups, author and peer, 5–6 equijoins, 92, 208–210
errartas, 5

484


functions Index

error messages fields
debugging, 26 defined, 8, 14
subqueries, 238–239 field views, 292

escalation lock parameter, 316–317 files
Europe, date variations, 24 comma-delimited, 41
examples database tuning, 351
.txt, 451
database creation, 35–38
normalization filtered windowed views, 292–293
filtering results, with WHERE clause, 56–58
first normal form, 118–119 first normal form, 118–119
second normal form, 120 fixed-length data types, 22
third normal form, 121–122 floating-point numbers, 23
timetables, 26 FLOOR() function, 165
transactions, 303–304 foreign keys
Excel spreadsheets, database alternatives, 10
exclusive locking level, 315 defined, 34
execution options FOREIGN KEY constraint, 135–139
Microsoft Access installation, 426 foreign-based offices, date variations, 25
MySQL installation, 400 form formats, normalization
EXISTS operator, 249–252 normal forms
expressions, subqueries as, 238
extended privileges, 336–337 discussed, 117
extraction, from databases first normal, 118–119
aliases, 56 second normal, 119–121
BETWEEN operator, 66–67 third normal, 121–123
concatenation, 82 transitive dependency, 121
IN operator, 73–75 forums, author and peer discussions, 5–6
LIKE operator, 70–72 fractions, floating-point numbers, 23
NOT LIKE operator, 72 Free Online Dictionary of Computing, 8
NOT operator, 66 FROM clause, 271
NULL values, 113–115 front end programs, 10
operator precedence, 62–65 FULL OUTER JOIN keyword, 225–226
ORDER BY clause, 75–79 functions
results, filtering, 56–60 ABS(), 159–160, 181
rows, returning values from, 55–56 AVG(), 198–200
SELECT statement, 53–54 case conversion, 170–171
CAST(), 179–180
F CEILING(), 165
COALESCE(), 180, 183–185
fault-tolerance, 350 CONCAT(), 85–86, 88–89
FavCategory table CONCAT_WS(), 89
COUNT(), 192–194
example code, 39 DAY(), 178
initial data setup, 459–462

485


functions (continued) G

functions (continued) gigahertz networks, database tuning, 352
DIFFERENCE(), 175–177 granting privileges
FLOOR(), 165
LEN(), 172 GRANT ALL statement, 341
LENGTH(), 172–174 GRANT OPTION statement, 342–343
LOWER(), 170 PUBLIC keyword, 342
LTRIM(), 172 tables and views, 341–342
MAX(), 200–202 granularity, locks, 313–314
MID(), 169 greater than operator (>), 47
MIN(), 200–202 GROUP BY clause
MONTH(), 178 HAVING clause, 202–205
NULLIF(), 180 overview, 189–191
POWER(), 160–161, 181 grouped views, 340
RAND(), 162–163 grouping results, 189–191
REVERSE(), 171 groups
RND(), 162 group access, 332–334
ROUND(), 163–167 relational databases, 8
RTRIM(), 172
SOUNDEX(), 175–177 H
sp_addlogin, 331
sp_defaultdb, 331 hard disk caches, 352–353
sp_denylogin, 331 hardware, database tuning, 349–350
sp_droplogin, 331 hash symbol (#), 58, 60, 113
sp_grantdbaccess, 331 HAVING clause
sp_grantlogin, 331
sp_helplogins, 331 GROUP BY clause, 202–205
sp_helpuser, 331 subqueries, 252–253
sp_password, 331 historical values, data selection, 90–94
sp_revokedbaccess, 331 history, databases, 7
sp_revokelogin, 331 Honeywell Information Systems, Inc.
SQRT(), 162
SUBSTR(), 169 (database research), 7
SUBSTRING(), 168–170 horizontal views, 339–340
SUM(), 196–198 hours, date and time data types, 24
TRIM(), 172
UPPER(), 170 I
YEAR(), 178
IBM databases
486 Command Center tool
downloading, 416
Interactive tab, 418–420
Results tab, 422–423
Script tab, 416–417


installation Index

concatenation, 85–88 INNER JOIN keyword
data type comparisons, 19 brackets around, 100–101
discussed, 3 as default join, 92
history of, 7 linked tables, 95
installing ON keyword, 91, 96
results returned by, 94
contact details screen, 413 syntax, 91, 207
license agreement, 410
login information, 412 inner queries, 235–236
product links, 409–410 innermost queries, 236
protocol details, 414 input/output (I/O), 351
setup program, 409 INSERT INTO statement
summary details, 415
task scheduler options, 414 overview, 43–44
tutorial information, 416 SELECT statement, 185–187
typical installation, 411 subqueries, 255–257
Ted Codd (IBM research), 7 syntax, 41
identification insert problems, transactions, 322
databases, 8 installation
group access, 332–334 IBM
user security, 329–332
identifiers contact details screen, 413
defined, 9 license agreement, 410
naming considerations, 25 login information, 412
objects and, 16 product links, 409–410
primary keys and, 34 protocol details, 414
IN operator setup program, 409
discussed, 62 summary details, 415
OR operator and, 73 task scheduler options, 414
subqueries, 242–245 tutorial information, 416
WHERE clause, 74 typical installation option, 411
inconsistent data problems, 321–322 Microsoft Access
indexes blank database link, 424
b-tree structure, 357–358 code views, 428
character, 168–169 default screen, 423
CREATE INDEX statement, 140 design views, 427
doubly linked lists, 359 new table creation, 425
dropping, 360 query execution, 426
multicolumn, 154 SQL code, 425–426
results, speeding up, 139–143 Microsoft SQL Server
when to use, 360–361 authentication mode, 433
computer selection, 430
downloads, 429
installation types, 431

487


installation (continued) isolation levels, transactions
READ UNCOMMITTED statement, 319–320
installation (continued) REPEATABLE READ statement, 319
Microsoft SQL Server (continued) SERIALIZABLE statement, 318–319
instance creation, 430 SET TRANSACTION statement, 318
instance name selection, 432 versioning, 320
services accounts, 433
setup complete screen, 434 italicized text, 4
typical installation option, 432
welcome screen, 429 J
MySQL
account information, 394 joins
character set configuration, 398 cross, 213–214
command line interface access, 401 data sets, 102–106
concurrent connection selection, 397 diagram, 93
configuration options, 395–396 equijoins, 92, 208–210
confirmation message, 400 INNER JOIN keyword
database install file, 391–392 brackets around, 100–101
drive specification, 397 as default join, 92
execution options, 400 linked tables, 95
license agreement, 392 ON keyword, 91, 96
networking options, 398 results returned by, 94
password information, 399 syntax, 91, 207
typical installation option, 393 JOIN keyword, 90
usage options, 396–397 multiple, 210–213
Windows service options, 399 non-equijoins, 209
Oracle ON keyword, 209
configuration options, 446–447 OUTER JOIN keyword
download link, 444 discussed, 218
installation types, 445 FULL OUTER JOIN keyword, 225–226
welcome screen, 444 LEFT OUTER JOIN keyword, 219–221
RIGHT OUTER JOIN keyword, 221–225
instances, Microsoft SQL Server installation, reasons for, 90
430, 432 record sets, 102–106
self, 214–218
int data type syntax, 91
discussed, 180
storage allocation, 21 K
UNION operator, 227
keys
Interactive tab (Command Center tool), foreign keys
418–420 defined, 34
FOREIGN KEY constraint, 135–139
I/O (input/output), 351
IS NOT NULL operator, 114
IS NULL operator, 114
ISO (International Standards Organization), 2

488


locks, transactions Index

primary keys declarative, 12–13
database creation example, 37 DML (Data Manipulation Language), 11
defined, 33 procedural, 12–13
identifiers and, 34 SQL (Structured Query Language)
NULL values, 132
PRIMARY KEY constraint, 132–134 procedural language comparisons, 12–13
uses for, 34 queries, 11–12
SQL-86 updates, 13
keywords SQL-89 updates, 13
AS, 56 SQL-92 updates, 13
CASCADE, 298, 346–347 SQL-99 updates, 13
CHECK OPTION, 295–298 SQL-2003 updates, 13
defined, 17 SQL*Plus tool, Oracle database, 448–450
DESC, 142 leaves, b-trees, 357
DISTINCT, 55–56, 194 LEFT OUTER JOIN keyword, 219–221
INNER JOIN LEN() function, 172
brackets around, 100–101 LENGTH() function, 172–174
as default join, 92 less than operator (<), 47
linked tables, 95 levels, locks, 314–316
ON keyword, 91, 96 license agreements
JOIN, 90 IBM installation, 410
ON MySQL installation, 392
INNER JOIN keyword, 91, 96 LIKE operator
joins, 209 case-sensitivity, 70–72
results returned by, 94 discussed, 62
syntax, 91, 207 literals
OUTER JOIN dates, 58
discussed, 218 defined, 16
FULL OUTER JOIN, 225–226 loading
LEFT OUTER JOIN, 219–221 Command Center tool, 416
RIGHT OUTER JOIN, 221–225 Microsoft SQL Server, 429
PUBLIC, 342 Oracle, 444
RESTRICT Query Analyzer tool, 435
discussed, 298 Query Browser tool, 401
revoking privileges, 346–347 source code, 4–5
rules, 17 Location table, initial data setup, 458–459
transaction, 307 locks, transactions
granularity, 313–314
L levels, 314–316
optimistic, 318
languages parameters, setting, 316–318
comparisons between, 12–13 pessimistic, 318
DCL (Data Control Language), 11
489


logical operators new table creation, 425
query execution, 426
logical operators, 48–49 SQL code, 425–426
login information, IBM installation, 412 overview, 3
logs, transaction, 312–313 Microsoft SQL Server databases
lost update problems, 320–321 concatenation, 82–85
LOWER() function, 170 data type comparisons, 19
LTRIM() function, 172 discussed, 3
Enterprise Manager tool, 435
M installing
authentication mode, 433
main program screen, Query Browser tool, 403 computer selection, 430
master database records, Query Analyzer tool, downloads, 429
installation types, 431
435 instance name selection, 432
math operations services accounts, 433
setup complete screen, 434
addition (+) operator, 158 typical installation option, 432
division (/) operator, 158 welcome screen, 429
functions instance creation, 430
Query Analyzer tool
ABS(), 159–160, 181 authentication options, 435
CEILING(), 165 downloading, 435
FLOOR(), 165 master database records, 435
POWER(), 160–161, 181 multiple queries, 439
RAND(), 162–163 Object Browser window, 437–438
RND(), 162 temporary databases, 437
ROUND(), 163–164, 166–168 MID() function, 169
SQRT(), 162 MIN() function, 200–202
multiplication (*) operator, 158 minutes, date and time data types, 24
subtraction (-) operator, 158 MONTH() function, 178
MAX() function, 200–202 multiplication operator (*), 158
MemberDetails table, initial data setup, multiprocessing, processors, 351
MySQL Server databases
452–455 concatenation, 88–89
memory data type comparisons, 19
discussed, 3
data types, 19 installing
database caches, 354–355 account information, 394
methods. See functions character set configuration, 398
Microsoft Access databases command line interface access, 401
concatenation, 82–85
data type comparisons, 19
installing

blank database link, 424
code views, 428
default screen, 423
design views, 427

490


operating systems Index

concurrent connection selection, 397 second normal, 119–121
configuration options, 395–396 third normal, 121–123
confirmation message, 400 transitive dependency, 121
database install file, 391–392 NOT IN operator, 244
drive specification, 397 NOT LIKE operator, 72
execution options, 400 NOT NULL constraint, 124–125
license agreement, 392 NOT operator, 62, 65–66
networking options, 398 NULL values
password information, 399 data extraction values, 113–115
typical installation option, 393 IS NOT NULL operator, 114
usage options, 396–397 IS NULL operator, 114
Windows service options, 399 NULLIF() function, 180
Query Browser tool numerics, 180–181
connection information, 402, 404–405 ORDER BY clause, 113
downloading, 401 primary keys, 132
main program screen, 403 strings and, 182
reference guide, 408 UNION operator, 232
schema information, 404 unknown values, 113
SQL execution information, 404 numbers
absolute values, 159–160
N data type selection considerations, 32
floating-point, 23
naming considerations NULL values, 180–181
data types, 154 number-to-character conversions, 363
database creation example, 36 random, 162–163
identifiers, 25 rounding, 163–167
punctuation issues, 18 numerical data
tables, 154 data types, 23–24, 179
delimiters around, 41
nchar data type, 20 nvarchar data type, 20
nesting
O
queries, 212
subqueries, 256 Object Browser window, Query Analyzer tool,
networks 437–438
database tuning, 352
network databases, 10 objects
networking options, MySQL installation, 398 defined, 14
NICs (network interface cards), 352 security, 328, 335
non-English characters, 32
normalization ON keyword
normal forms INNER JOIN keyword, 91, 96
joins, 209
discussed, 117
first normal, 118–119 operating systems, 11

491


operators NULL value, 232
ORDER BY clause, 230–231
operators SELECT statement, 228
addition (+), 158 optimistic locking, 318
ALL OR operator
discussed, 62 discussed, 62
subqueries, 247–249 IN operator and, 73
UNION operator, 229 WHERE clause, 48, 63
AND Oracle databases
discussed, 62 concatenation, 85–88
WHERE clause, 48, 63 data type comparisons, 19
ANY, 245–247 discussed, 3
BETWEEN, 62, 66–67 history of, 7
comparison, 47–48 installing
division (/), 158 configuration options, 446–447
EXISTS, 249–252 download link, 444
IN installation types, 445
discussed, 62 welcome screen, 444
OR operator and, 73 SQL*Plus tool, 448–450
subqueries, 242–245 ORDER BY clause
WHERE clause, 74 date functions, 178
IS NOT NULL, 114 NULL value, 113
IS NULL, 114 SELECT statement, 54, 75
LIKE, 62, 70–72 sorting orders, 75–79
logical, 48–49 UNION operator, 230–231
math, 157–159 organization
multiplication (*), 158 columns, 31
NOT, 62, 66 database design techniques, 28–32
NOT IN, 244 relational databases, 14–16
NOT LIKE, 72 OUTER JOIN keyword
operator precedence, 62–65 discussed, 218
OR FULL OUTER JOIN keyword, 225–226
discussed, 62 LEFT OUTER JOIN keyword, 219–221
IN operator and, 73 RIGHT OUTER JOIN keyword, 221–225
WHERE clause, 48, 63 outer queries, 235
SOME ownership, privileges, 337
discussed, 62
subqueries, 245–247 P
subtraction (-), 158
UNION pages, locking, 314
ALL statement, 229 parameters, locks, 316–318
discussed, 226
int data type, 227

492


queries Index

passwords procedural languages, SQL comparisons,
group access, 333 12–13
IBM installation, 412
MySQL installation, 399 processor caches, 352
SQL*Plus tool, 448 product links, IBM installation, 409–410
programs, front end, 10
pattern matching, database tuning, 363 protocol details, IBM installation, 414
peer and author discussions, 5–6 protocols, DHCP (Dynamic Host Configuration
percent sign (%), 70
performance improvement Protocol), 350
P2P forums, author and peer discussions, 5–6
table scans, 362 PUBLIC keyword, 342
validation, 145–149
personal use databases, 10 Q
pessimistic locking, 318
pipe character (|), 85 queries
POWER() function, 160–161, 181 base, 290
precedence, operator, 62–65 clauses, 12
primary keys conditions, 12
database creation example, 37 database tuning, 355–356
defined, 33 defined, 9
identifiers and, 34 examples of, 11–12
NULL values, 132 executing, Microsoft Access installation, 426
PRIMARY KEY constraint, 132–134 inner, 235–236
uses for, 34 innermost, 236
privileges nesting, 212
discussed, 328 outer, 235
extended, 336–337 results, database extraction, 58–60
granting statements, 12
subqueries
GRANT ALL statement, 341 ALL operator, 247–249
GRANT OPTION statement, 342 ANY operator, 245–247
PUBLIC keyword, 342 correlated, 253–255
tables and views, 341–342 DELETE statement, 259–260
ownership, 337 discussed, 235
revoking error messages, 238–239
CASCADE keyword, 346–347 EXISTS operator, 249–252
with GRANT OPTION statement, 345–346 as expressions, 238
RESTRICT keyword, 346–347 HAVING clause, 252–253
REVOKE statement, 344–345 IN operator, 242–245
problems, transactions INSERT INTO statement, 255–257
inconsistent data, 321–322 nesting, 256
inserts, 322 scalar, 236
lost updates, 320–321 SELECT statement, 236–240
uncommitted data, 321

493


queries (continued) redundancy
normalization, 121
queries (continued) well designed databases, 9
subqueries (continued)
SOME operator, 245–247 reference guide, Query Browser tool, 408
UPDATE statement, 257–259 REFERENCES statement
WHERE clause, 236, 240–242
writing queries discussed, 139
difficult queries, 270–274 extended privileges, 336–337
good queries, 283–285 registration, P2P forums, 5
relational databases
Query Analyzer tool advantages of, 9
authentication options, 435 corruption, 39
database creation example, 17 defined, 8
downloading, 435 groups, 8
master database records, 435 organization, 14–16
multiple queries, 439 security control, 14
Object Browser window, 437–438 structure of, 15
temporary databases, 437 REPEATABLE READ statement, 319
requirement details, database creation, 35
Query Browser tool, MySQL RESTRICT keyword
connection information, 402, 404–405 discussed, 298
downloading, 401 revoking privileges, 346–347
main program screen, 403 restrictions, updating views, 295
reference guide, 408 results
schema information, 404 adding, 196–197
SQL execution information, 404 averages, 198–200
combining, 226–230
question mark (?), 70 counting, 192–194
database extraction, 56–60
R filtering, 57
grouping, 189–191
RAND() function, 162–163 indexes, 139–143
random numbers, 162–163 ordering, 75–79
range of values, retrieving, 66–67 Results tab (Command Center tool), 422–423
READ UNCOMMITTED statement, 319–320 REVERSE() function, 171
real data type revoking privileges
CASCADE keyword, 346–347
numerical data, 23–24 with GRANT OPTION statement, 345–346
storage allocation, 21 RESTRICT keyword, 346–347
records REVOKE statement, 344–345
active, 301 RIGHT OUTER JOIN keyword, 221–225
defined, 8, 16 RND() function, 162
sets

combining, 226–230
joins, 102–106
updating, 48

494


simple databases Index

ROLLBACK statement, 307–308 group access, 332–334
ROLLBACK TRANSACTION statement, user IDs, 329–332
validation
310–311 CHECK constraint, 125, 129–132
ROUND() function, 163–167 design improvement, 153–154
rows, databases FOREIGN KEY constraint, 135–139
NOT NULL constraint, 124–125
locking, 314 performance improvement, 145–149
returning values from, 55–56 PRIMARY KEY constraint, 132–134
row views, 291 UNIQUE constraint, 125–129
RTRIM() function, 172 views and
grouped views, 340
S horizontal views, 339–340
limitations, 341
SAs (system administrators), 329 vertical views, 337–338
SAVE TRANSACTION statement, 309 SELECT statement
savepoints, 309 AS keyword, 56
scalar subqueries, 236 difficult queries, 271
schema information, Query Browser tool, 404 DISTINCT keyword, 55–56, 194
Script tab (Command Center tool), 416–417 INSERT INTO statement, 185–187
second normal form, 119–121 ORDER BY clause, 54, 75
seconds, date and time data types, 24 subqueries, 236–240
security syntax, 53
UNION operator, 228
authentication, 433, 435 WHERE clause, 56–57
concepts, 328 self-joins, 214–218
database advantages, 10 SERIALIZABLE statement, 318–319
DCL (Data Control Language), 11 services accounts, Microsoft SQL Server
objects, 328, 335
privileges installation, 433
SET clause, 46
discussed, 328 SET TRANSACTION statement, 318
extended, 336–337 sets, records
granting, 341–343
ownership, 337 combining, 226–230
revoking, 344–347 joins, 102–106
usage, 337 setup complete screen, Microsoft SQL Server
relational databases, 14
user security installation, 434
ALTER USER statement, 331 setup program, IBM installation, 409
CREATE USER statement, 330 shared locking level, 315
deleting users, 331 sharing data, 10
discussed, 328 simple databases, 8
DROP USER statement, 331

495


size, locking parameters standards
ANSI (American National Standards Institute),
size, locking parameters, 316 2, 305
smallint data type, 21 ASCII (American Standard Code for Informa-
SOME operator tion Interchange), 22
ISO (International Standards Organization), 2
discussed, 62
subqueries, 245–247 START command, 451
sorting orders statements. See also clauses
ascending, 77
descending, 76 ALTER COLUMN, 124
ORDER BY clause, 75–79 ALTER TABLE, 26–27
random numbers, 163 ALTER TABLE MODIFY, 124
using commas, 78 ALTER USER, 331
SOUNDEX() function, 175–177 BEGIN TRANSACTION, 306, 308
source code, downloading, 4–5 COMMIT, 306–308
spaces COMMIT TRANSACTION, 308
between aliases, 87 CREATE DATABASE, 17
between code, 17 CREATE INDEX, 140
sp_addlogin function, 331 CREATE TABLE, 25–26
sp_defaultdb function, 331 CREATE USER, 330
sp_denylogin function, 331 CREATE VIEW, 290
sp_droplogin function, 331 defined, 12, 16
sp_grantdbaccess function, 331 DELETE
sp_grantlogin function, 331
sp_helplogins function, 331 subqueries, 259–260
sp_helpuser function, 331 WHERE clause, 49–50
splitting data into tables, 119 DROP COLUMN, 27
sp_password function, 331 DROP DATABASE, 18
spreadsheets, database alternatives, 10 DROP INDEX, 141, 143
sp_revokedbaccess function, 331 DROP TABLE, 27
sp_revokelogin function, 331 DROP USER, 331
SQL (Structured Query Language) DROP VIEW, 298
procedural language comparisons, 12–13 GRANT ALL, 341
queries, 11–12 GRANT OPTION, 342–343
SQL-86 updates, 13 INSERT INTO
SQL-89 updates, 13 overview, 43–44
SQL-92 updates, 13 SELECT statement, 185–187
SQL-99 updates, 13 subqueries, 255–257
SQL-2003 updates, 13 syntax, 41
SQL*Plus tool, Oracle database, 448–450 READ UNCOMMITTED, 319–320
SQRT() function, 162 REFERENCES
square root functions, 162 extended privileges, 336–337
stand-alone applications, 11 overview, 139

496


syntax Index

REPEATABLE READ, 319 NULL values and, 182
REVOKE, 344–345 REVERSE() function, 171
ROLLBACK, 307–308 RTRIM() function, 172
ROLLBACK TRANSACTION, 310–311 SOUNDEX() function, 175–177
SAVE TRANSACTION, 309 SUBSTR() function, 169
SELECT SUBSTRING() function, 168–170
TRIM() function, 172
AS keyword, 56 UPPER() function, 170
difficult queries, 271 Structured Query Language. See SQL
DISTINCT keyword, 55–56, 194 styles, text, 4
INSERT INTO statement, 185–187 subqueries
ORDER BY clause, 54, 75 ALL operator, 247–249
subqueries, 236–240 ANY operator, 245–247
syntax, 53 correlated, 253–255
UNION operator, 228 DELETE statement, 259–260
WHERE clause, 56–57 discussed, 235
SERIALIZABLE, 318–319 error messages, 238–239
SET TRANSACTION, 318 EXISTS operator, 249–252
UPDATE as expressions, 238
addresses, 45–46 HAVING clause, 252–253
SET clause, 46 IN operator, 242–245
subqueries, 257–259 INSERT INTO statement, 255–257
syntax, 45 nesting, 256
WHERE clause, 45–46 scalar, 236
USAGE, 337 SELECT statement, 236–240
VALUES, 41 SOME operator, 245–247
storage UPDATE statement, 257–259
data types WHERE clause, 236, 240–242
discussed, 20–21 SUBSTR() function, 169
selection considerations, 32 SUBSTRING() function, 168–170
databases, history of, 7 subtraction operator (-), 158
design practices, 28 SUM() function, 196–198
indexes, 358 summaries
stored procedures, 331 summary details, IBM installation, 415
strings summary of data, 189
case conversion functions, 170–171 summary views, 293–294
character string data types, 22–23 symbols, aliases, 56
date functions, 178 syntax. See also code
DIFFERENCE() function, 175–177 CAST() function, 180
LENGTH() function, 172–174 CEILING() function, 165
LOWER() function, 170 CREATE TABLE statement, 25
LTRIM() function, 172
497


syntax (continued) deleting, 27
dropping, 27
syntax (continued) good design example, 30–31
cross joins, 213 joining, 91
DAY() function, 178 locking, 314
defined, 16 multicolumn indexes, 154
DIFFERENCE() function, 176 organization, 31
DROP TABLE statement, 27 sorting order, 75–79
DROP VIEW statement, 298 creating, 25–26, 39
equijoins, 208 data
FLOOR() function, 165 copying, 185
FOREIGN KEY constraint, 137 summaries, 189
FULL OUTER JOIN keyword, 225 defined, 8
INNER JOIN keyword, 91, 207 deleting, 27–28
INSERT INTO statement, 41, 185 example of, 14
joins, 91 FavCategory, initial data setup, 459–462
LEFT OUTER JOIN keyword, 219 good design example, 29–30
MONTH() function, 178 joining
POWER() function, 160 cross joins, 213–214
RIGHT OUTER JOIN keyword, 221 multiple joins, 210–213
ROUND() function, 167 self-joins, 214–218
SELECT statement, 53 Location, initial data setup, 458–459
SOUNDEX() function, 175 locking, 314
SQRT() function, 162 MemberDetails, initial data setup, 452–455
SUBSTRING() function, 168 naming considerations, 154
SUM() function, 196 normalization
UPDATE statement, 45 first normal form, 118–119
YEAR() function, 178 second normal form, 119–121
third normal form, 121–123
system administrators (SAs), 329 privileges, granting, 341–342
records, sets, 102–106
T relationships between, 135
splitting data into, 119
table scans, 361–362 table join views, 290
tables. See also databases views and, 341
virtual, 288
altering, 26–27 tabs, Command Center tool
Attendance Interactive tab, 418–420
Results tab, 422–423
example code, 37 Script tab, 416–417
initial data setup, 466–469 task scheduler options, IBM installation, 414
Category, initial data setup, 452
columns
aliases, 56
ALTER COLUMN statement, 124
defined, 16

498


tuning databases Index

telephone numbers, data type selection transactions
considerations, 32 ACID (Atomic, Consistent, Isolated, Durable)
test, 302
temporary databases, Query Analyzer tool, active records, 301
437 ANSI standard, 305
autocommit, 307
text BEGIN TRANSACTION statement, 306, 308
italicized, 4 COMMIT TRANSACTION statement, 308
styles, 4 example data, 303–304
text-based information, data type selection isolation levels
considerations, 32 READ UNCOMMITTED statement, 319–320
text-based operators, 47 REPEATABLE READ statement, 319
SERIALIZABLE statement, 318–319
text files, database alternatives, 10 SET TRANSACTION statement, 318
third normal form, 121–123 versioning, 320
time keywords, 307
locks
date and time data types, 24–25 granularity, 313–314
time data type, 21 levels, 314–316
timetable example, 26 optimistic, 318
timeout lock parameter, 317–318 parameters, setting, 316–318
tools pessimistic, 318
Command Center overview, 301
problems
downloading, 416 inconsistent data, 321–322
Interactive tab, 418–420 inserts, 322
Results tab, 422–423 lost updates, 320–321
Script tab, 416–417 uncommitted data, 321
Query Analyzer ROLLBACK statement, 307–308
authentication options, 435 ROLLBACK TRANSACTION statement,
database creation example, 17 310–311
downloading, 435 SAVE TRANSACTION statement, 309
master database records, 435 savepoints, 309
multiple queries, 439 transaction logs, 312–313
Object Browser window, 437–438
temporary databases, 437 transitive dependency, 121
Query Browser TRIM() function, 172
connection information, 402, 404–405 tuning databases
downloading, 401
main program screen, 403 caches
reference guide, 408 database, 354–355
schema information, 404 hard disk, 352–353
SQL execution information, 404 processor, 352
SQL*Plus, 448–450

499


tuning databases (continued) United States, date variations, 24
unknown values, NULL values, 113
tuning databases (continued) UPDATE statement
compartmentalized networks, 352
files, 351 addresses, 45–46
filter redundancy, 363 SET clause, 46
gigahertz networks, 352 subqueries, 257–259
hardware, 349–350 syntax, 45
indexes WHERE clause, 45–46
b-tree structure, 357–358 updates
database storage requirements, 358 database records, logical operators and, 49
doubly linked lists, 359 lost update problems, 320–321
dropping, 360 SQL, 13
when to use, 360–361 views
number-to-character conversions, 363
pattern matching, 363 CHECK OPTION keyword, 295–298
processors, 351 restrictions, 295
queries, 355–356 upgrades, workstations, 350
reasons for, 356 UPPER() function, 170
table scans, 361–362 U.S. (United States), date variations, 24
workstations, 350–351 usage options, MySQL installation, 396–397
USAGE statement, 337
Turing Award (Charles W. Bachman), 7 user security
tutorial information, IBM installation, 416 ALTER USER statement, 331
.txt files, 451 CREATE USER statement, 330
typical installation option deleting users, 331
discussed, 328
IBM database, 411 DROP USER statement, 331
Microsoft SQL Server installation, 432 group access, 332–334
MySQL database, 393 user IDs, 329–332

U V

uncommitted data problems, 321 validation
underscore (_), 70 CHECK constraint, 125, 129–132
Unicode character set, 20, 22 design improvement, 153–154
UNION operator FOREIGN KEY constraint, 135–139
NOT NULL constraint, 124–125
ALL statement, 229 performance improvement, 145–149
discussed, 226 PRIMARY KEY constraint, 132–134
int data type, 227 UNIQUE constraint, 125–129
NULL value, 232
ORDER BY clause, 230–231 values
SELECT statement, 228 absolute, 159–160
UNIQUE constraint, 125–129 duplicate, avoiding, 142
United Kingdom, date variations, 25

500


year-month-day data formats Index

historical, data selection, 90–94 vertical, 337–338
NULL values windowed, 292–293
virtual tables, 288
data extraction values, 113–115
IS NOT NULL operator, 114 W
IS NULL operator, 114
NULLIF() function, 180 welcome screen
numerics, 180–181 Microsoft SQL Server installation, 429
ORDER BY clause, 113 Oracle installation, 444
primary keys, 132
strings and, 182 WHERE clause
UNION operator, 232 AND operator, 48, 63
unknown values, 113 comparison operators, 47
retrieving DELETE statement, 49–50
ranges, 66–67 DIFFERENCE() function, 177
from rows, 55–56 filtering results with, 56–58
VALUES statement, 41 IN operator, 74
varchar data type, 22 logical operators, 48
variable length data types, 22 operator precedence, 64
versioning, isolation levels, 320 OR operator, 48, 63
vertical views, 337–338 SELECT statement, 56–57
views subqueries, 236, 240–242
base, 290–291 UPDATE statement, 45–46
benefits, 287–288
CREATE VIEW statement, 290 wildcard characters
creation, 288–289 * (asterisk), 70
defined, 287 multiple use, 71
dropping, 298 % (percent sign), 70
field, 292 ? (question mark), 70
grouped, 340 _ (underscore), 70
horizontal, 339–340
limitations, 287, 341 Window service options, MySQL installation,
privileges, granting, 341–342 399
row, 291
summary, 293–294 windowed views, 292–293
table join, 290 workstations, database tuning, 350–351
tables and, 341 Wrox, P2P forums, 5–6
updating
CHECK OPTION keyword, 295–298 Y
overview, 294
restrictions, 295 YEAR() function, 178
year-month-day data formats, 44

501


Click to View FlipBook Version