Index

limited FETCH capability, 236–238 • Symbols and logical connectives, 230–232 Numerics • modifying clauses, 211–213 clause, 235–236 % (percent sign) wildcard, 218–220 overview, 211 * (asterisk), 140, 245, 334 windows, 238–242 _ (underscore) wildcard, 218–220 ACID databases, 326 || (concatenation operator), 65–66, 178 ActiveX controls, Microsoft, 355 = (equal operator), 274 ad hoc queries, keyboard, 22 1NF (fi rst normal form), 132 aggregate functions, 181–184, 274. See also 2NF (second normal form), 132–134 set functions 3NF (third normal form), 53 aliases, 252, 427 4GLs (fourth-generation languages), 81 ALL predicate, 221–224 ALL quantifi er, nested queries, 275–276 • A • ALTER statement, 62, 63 ALTER TABLE statement, 53, 102, 123, abnormal form, 135–136 124, 419 ABS function, 194 altering table structure, 90–92, 102 ABS interval value functions, 196 AND logical connectives, 69, 230–231, 437 ABSOLUTE orientation, 391 ANY predicate, 221–224 Access, Microsoft ANY quantifi er, nested queries, 275–276 altering table structure, 90–92 API (application programming interface), 352 data-defi nition queries, 98–100 applets, Java, 356–357 Datasheet view, building database tables application, ODBC interface, 351 in, 83–84 application development environments, 433 deleting tables, 94–95 application programming interface Design view, building database tables in, (API), 352 84–86 applications, 318, 423–424 Design view, setting fi eld properties in, applications, SQL in 86–90 * wildcard, 334 indexes, creating, 92–94 embedded SQL, 336–339 security, 100–101 COPYRIGHTEDMicrosoft MATERIAL Access, 343–345 SQL in, 95–97, 342, 343–345 module language, 339–342 access privileges. See privileges overview, 333–334 accessing data. See also WHERE clauses procedural languages and SQL, 335–336 FROM clause, 213 RAD tools, 342–343 GROUP BY clause, 232–234 strengths and weaknesses of SQL, HAVING clause, 234 334–335

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 443443 88/1/13/1/13 22:29:29 PPMM 444 SQL For Dummies, 8th Edition

application-time period tables BETWEEN predicate, 215–217 overview, 159–162 BIGINT data type, 27 primary keys, designating in, 162–163 BINARY data type, 33 querying, 164–165 BINARY LARGE OBJECT (BLOB) data referential constraints, applying to, type, 33 163–164 BINARY strings, 32–33 approximate numeric data types, 29–30 BINARY VARYING data type, 33 architecture, system, 433 bitemporal tables, 169–170 ARRAY data type, 39–40, 378 BLOB (BINARY LARGE OBJECT) data ARRAY_MAX_CARDINALITY function, 40, type, 33 193–194 BLOB locators, 33 arrays, 193 BOOLEAN data type, 33 ASENSITIVE keyword, 388 Boolean value expression, 67 assertions, 126, 128–129 buckets, partitioning windows into, 239 assignment, in SQL/PSM, 400 bugs, fi xing, 434 asterisk (*), 140, 245, 334 building database structure. See also rapid AT LOCAL keywords, 66 application development tools ATOMIC keyword, 395, 399 altering table structure, 102 atomic transactions, 326 creating tables, 97–101 atomic values, 172 deleting indexes, 103 atomicity, compound statements, 394–395 deleting tables, 102 attributes indexes, creating, 101 domains, 17 overview, 81 functional dependency, 132–133 portability considerations, 103 modifi ed, creating views with, 144–145 using SQL with Microsoft Access, 95–97 overview, 7, 13 bytes, 192–193 transitive dependency, 134 UDTs, 41 • C • auditable records of database entries. See system-versioned tables C language, 337–338 AUTHORIZATION clause, 341 CALL statements, 406 authorization identifi er, 341 CARDINALITY function, 40, 193 automatic data entry, 148 cardinality of arrays, 40 AutoNumber data type, Microsoft Access, 85 Cartesian product, 213, 250, 253 AVG function, 70–71, 183, 232 CASCADE keyword, 310 cascading deletions, 121–122, 284 • B • CASE expressions COALESCE, 204–205 backing up data, 314, 325, 438 general discussion, 197–198 bad input data, 124 NULLIF, 202–204 base tables, 141 with search conditions, 198–200 basic joins, 249–250 with values, 200–202 BEFORE triggers, 428 CASE statement, 198 BEGIN keyword, 394 CASE…END CASE statements, 401–402 beta testing, 434 CAST expressions, 205–207, 336, 339

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 444444 88/1/13/1/13 22:29:29 PPMM Index 445

CATALOG_NAME fi eld, 419 columns catalogs, 52, 61–62 adding data to, 148 CEIL function, 195 adding to existing tables, 123 CEILING function, 195 DBMS processing of, 12–13 chain of dependency, 310 deleting from existing tables, 124 CHAR value, 172 identifying, in multitable relational CHARACTER data type, 31 databases, 106–107 CHARACTER LARGE OBJECT (CLOB) data transferring between tables, 149–150 type, 31–32, 361 comma-delimited values, 146 character sets COMMAND_FUNCTION fi eld, diagnostics access privileges, assigning, 74 header area, 415 collation, 386 COMMAND_FUNCTION_CODE fi eld, CONVERT value function, 189 diagnostics header area, 415 mapping, 362–363 comments, XML, 369 multitable relational databases, 111–112 COMMIT statement, 72, 318, 324 TRANSLATE value function, 189 comparison operators character strings, 30–32 correlated subqueries introduced with, CHARACTER VARYING data type, 31 279–281 CHARACTER_LENGTH function, 192 using with subqueries, 272–274 characters, language, 32 comparison predicates, 68, 214, 215 CHECK constraint, 127 complete logical view, 17 CLASS_ORIGIN fi eld, diagnostics detail complexity of databases, 7–8 area, 417 composite keys, 113, 133 client extensions, 354–355 compound statements clients, 48–49 assignment, 400 client/server systems atomicity, 394–395 ODBC in, 352 conditions, 396–400 SQL in, 47–49 cursors, declaring within, 396 CLOB (CHARACTER LARGE OBJECT) data exception handlers, 420–421 type, 31–32, 361 overview, 393–394 CLOB locator, 32 variables, 395–396 cloud, 8, 354 concatenation, 65–66, 368 clusters, 52, 62 concatenation operator (||), 65–66, 178 COALESCE expressions conceptual view, 17 general discussion, 204–205 concurrent access, 315–317 union joins, using with, 260, 263–265 handlers, 398–399 COLLATE BY clause, 386 condition joins, 254 collation, 386 CONDITION_NUMBER fi eld, 417, 420 collation sequences, 63, 74, 111–112 conditional value expressions, 180 collection data types, 39–40, 44 conditions, in compound statements, collection value expressions, 67 396–400 column constraints, 126–127 CONNECTION_NAME fi eld, 419 column references, 176–177 connectives, 207 COLUMN_NAME fi eld, 419 consistency, 326, 423 column-name joins, 254–255 constants, 172

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 445445 88/1/13/1/13 22:29:29 PPMM 446 SQL For Dummies, 8th Edition

constraints fetching data from single rows, 390–392 adding to existing tables, 419 opening, 388–390 general discussion, 17–18, 46–47 overview, 383–384 overview, 16 primary key, in application-time period • D • tables, 162 specifying, 63 damage to databases, avoiding, 71–72 within transactions, 327–331 Data Control Language (DCL) types of, 126–129 access privileges, assigning to users, violation information, 418–419 73–75 constructor function, for structured delegating responsibility for security, UDTs, 43 77–78 containment hierarchy, 52 overview, 51, 71, 298 CONTENT predicate, 372 referential integrity, 75–77 contention, 315 transactions, 71–72 CONTINUE effect, 399 data corruption, vulnerability to, 317–318 CONVERT value function, 189 Data Defi nition Language (DDL) copying from foreign data fi les, 149 catalogs, 61–62 correlated subqueries, 277–281, 282–283 collecting tables into schemas, 61 correlation names, 252, 427 creating tables, 109 CORRESPONDING keyword, 245–246, 247 multitable views, 56–60 COUNT function, 69, 182–183 overview, 51, 52, 298 CREATE ASSERTION statement, 63 planning databases, 52–53 CREATE CHARACTER SET statement, 63 single-table views, 55–56 CREATE COLLATION statement, 63 statements, 62–64 CREATE DOMAIN statement, 63, 305, 306 tables, creating, 53–55 CREATE SCHEMA statement, 63 data dictionary, 7 CREATE statements, 53, 62, 63, 166 data integrity CREATE TABLE statement, 53, 54, 63, 98 columns, adding to existing tables, 123 CREATE TRANSLATION statement, 63 columns, deleting from existing CREATE TRIGGER statement, 424 tables, 124 CREATE TYPE statement, 308 constraints, 126–129, 147 CREATE VIEW statements, 59–60, 63 domain integrity, 119–120 CROSS JOIN, 253 entity integrity, 118–119 cross product, 253 Internet, performing database current sessions, 176 manipulations over, 49–50 CURRENT_DATE function, 196 overview, 118 CURRENT_TIME function, 196 potential threats, 124–126 CURRENT_TIMESTAMP function, 196 referential integrity, 120–123 CURRENT_USER special variable, 176 data loss, 6 CURSOR_NAME fi eld, 419 Data Manipulation Language (DML) cursors logical connectives, 69 closing, 392 in Microsoft Access, 343 compound statements, declaring overview, 51, 64, 298 within, 396 predicates, 68 declaring, 341, 384–388 set functions, 69–71

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 446446 88/1/13/1/13 22:29:29 PPMM Index 447

subqueries, 71 relational model, 11–13 value expressions, 64–68 schemas, 16, 17 data redundancy, 125 views, 14–16 data source, ODBC interface, 351 database object owners, 298–299 data storage, 6 database objects, 299, 324 data types database structure, verifying, 435 approximate numerics, 29–30 database-management functions, 298 BINARY strings, 32–33 data-defi nition queries, Microsoft Access, BOOLEAN, 33 98–100 character strings, 30–32 Datasheet view, Microsoft Access, building collection, 39–40 tables in, 83–84 converting with CAST expressions, DATE data type, 34 205–207, 339 DATE value, 172 datetimes, 33–35 datetime data type, 33–35 exact numerics, 27–28 datetime value expressions, 66–67, 179–180 intervals, 35 datetime value functions, 196 mapping, 364, 375–379 date-time values, fi xing, 389 overview, 26 day-time intervals, 35, 66, 180 procedural languages versus SQL, 336 DBA (database administrator), 298–299 REF , 41 DBMS. See database management system ROW , 38–39 DCL. See Data Control Language table of, 45 DDL. See Data Defi nition Language UDTs, 41–44 DECIMAL data type, 28 user privileges, 298 declaration segments for host variables, 339 XML , 35–38, 360–362 declarations in modules, 340 XMLCAST function, 371 DECLARE CURSOR statement, 384, 386, database administrator (DBA), 298–299 387–388 database management system (DBMS) default SQL transactions, 319–320 exceeding capacity of, 126 default values, 208 general discussion, 8–9 DEFERRABLE constraint, 327 index maintenance, 117 DELETE statements object-relational model, 18–19 bitemporal tables, 170 preferred, using on projects, 433 nested queries, 282–284 database manipulation obsolete data, deleting, 156 adding data, 146–151 pipelined DML, 284 creating views, 141–145 restricting, 73 deleting obsolete data, 156 system-versioned tables, 166, 167 overview, 139 retrieving data, 139–141 trigger events, 424, 426 transferring data, 154–156 user access, 298 updating existing data, 151–154 using with cursors, 391–392 updating views, 145 deleting data database models in application-time period tables, 161 constraints, 16, 17–18 indexes, 103 domains, 16, 17 obsolete data, 156, 304 object model, 18 rows, in cursor operations, 387, 391–392 object-relational model, 18–19 tables, 94–95, 102

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 447447 88/1/13/1/13 22:29:29 PPMM 448 SQL For Dummies, 8th Edition

deletion anomaly, 130 DROP statement, 53, 62, 64 deletions, cascading, 121–122 DROP TABLE command, 102 delimited identifi ers, 363 duplicate hardware, 314 delta tables, 284 durability, 326 departmental databases, 8 dynamic link library (DLL), 351 design of databases, 20, 105–106 DYNAMIC_FUNCTION_CODE fi eld, 415 design reviews, 434 Design view, Microsoft Access • E • database tables, building in, 84–86 fi eld properties, setting in, 86–90 embedded SQL, 175, 336–339 detail area, diagnostics, 414, 416–418 END keyword, 394 diagnostics areas enterprise databases, 8 constraint violation information, 418–419 entity integrity, 118–119 constraints, adding to existing tables, 419 ENVIRONMENT_NAME fi eld, 419 details area, 416–418 equal operator (=), 274 header area, 414–416 EQUALS predicates, 164 information returned by SQLSTATE, equi-joins, 251–253 interpreting, 419–420 equipment failure, 314–315 overview, 414 equiwidth partitioning, 195 DIAGNOSTICS SIZE clause, 414 error handling dirty read, 320 adding to applications, 438 DISTINCT keyword, 272 conditions causing errors, 200 DISTINCT predicate, 225 diagnostics areas, 414–420 DK/NF (domain-key normal form), 134–135 handling exceptions, 420–421 DLL (dynamic link library), 351 overview, 411 DML. See Data Manipulation Language SQLSTATE status parameter, 411–413 DOCUMENT component of VALID WHENEVER clause, 413–414 predicate, 373 escape characters, 186, 193 DOCUMENT predicate, 371–372 exact numeric data types, 27–28 documenting progress, 434 EXCEPT operator, 248 domain-key normal form (DK/NF), 134–135 exception avoidance, 200 domains exception handlers, 420–421 access privileges, assigning to users, 74 EXEC SQL directive, 339 creating, 63 EXECUTE keyword, 298 general discussion, 17, 305–306 EXECUTE privilege, 408–409 integrity, 119–120 execution contexts, trigger, 426 mapping to XML, 375–376 existence tests, nested queries, 277–278 multitable relational databases, 111–112 EXISTS predicate, 224–225, 277–278 overview, 16 EXIT effect, 399 dormant sessions, 176 EXP function, 194 DOUBLE PRECISION data type, 29–30 expressions, defi ned, 171 driver DLL, ODBC interface, 351 eXtensible Markup Language. See XML driver manager, ODBC interface, 351 EXTRACT function, 192 drivers, ODBC, 350, 352 DROP domains, 306

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 448448 88/1/13/1/13 22:29:29 PPMM Index 449

functions. See also specifi c functions by • F • name failure of equipment, 314–315 defi ned, 171 feasibility of projects, 432 overview, 181 feedback on projects, listening to, 432 recursion, 285 FETCH statement, 236–238, 390–391 set, 181–184 Field Properties pane, Microsoft Access, stored, 407–408 85, 86 for XML data, 367–371 fi elds, defi ned, 172 fi les, copying from foreign data, 149 • G • fi rst normal form (1NF), 132 FIRST orientation, 391 GENERATED ALWAYS keyword, 166 FIRST_VALUE function, 241 GRANT DELETE statement, 74 fl at fi les, 9–11 GRANT INSERT statement, 74 FLOAT data type, 30 GRANT OPTION FOR clause, 310–311 FLOAT value, 172 GRANT REFERENCES statement, 74 fl oating-point number, 29 GRANT SELECT statement, 74 FLOOR function, 195 GRANT statement, 73, 300–301, 311–312 fl ow of control statement GRANT UPDATE statement, 74 CASE…END CASE statements, 401–402 granting privileges to users. See privileges FOR…DO…END FOR statements, 405 GROUP BY clause IF…THEN…ELSE…END IF statements, 401 general discussion, 232–234 ITERATE statement, 405–406 HAVING clause, subqueries with, 281 LEAVE statement, 403 overview, 212 LOOP…ENDLOOP statements, 402–403 restrictions, 437 overview, 400 summarizing data with, 436–437 REPEAT…UNTIL…END REPEAT statements, 404 • H • WHILE…DO…END WHILE statements, 404 FOR EACH clause, 425 handlers, condition, 398–399 FOR…DO…END FOR statements, 405 handling exceptions, 420–421 foreign data fi les, copying from, 149 hardware failures, 314–315 foreign keys, 73–74, 114, 121 HAVING clause, 212, 234, 281 forests of XML values, producing, 368 header area, diagnostics, 414–416 format-conversion utility, 149 hierarchies, 307 form-based data entry, 146–148 historical rows, 165, 166–167 FORTRAN, 207 holdability, cursor, 385 fourth-generation languages (4GLs), 81 host languages, using CAST expressions FROM clause, 212 with, 206–207 FULL keyword, 229–230 host variables, 175, 205–207, 339, 411 full outer joins, 259 HTML code for database access, 354–355 function calls, 285, 350, 407–408 functional dependency, 132–133

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 449449 88/1/13/1/13 22:29:29 PPMM 450 SQL For Dummies, 8th Edition

Internet, SQL over, 49–50 • I • Internet-based database systems, 352–353 INTERSECT icons, used in book, 2 operator, 246–248 identifi ers, mapping, 363 interval data type, 35 identity-constraint-option interval overlap, determining, 226 component of VALID predicate, 373 interval value expressions, 66–67, 180 IDEs (integrated development interval value functions, 196 environments), 81 intranets, 49–50, 355 IF…THEN…ELSE…END IF statements, 401 ISAM (indexed sequential access IGNORE NULLS keywords, 240 method), 351 IMMEDIATELY PRECEDES predicates, 165 ISO/IEC SQL standard, 19 IMMEDIATELY SUCCEEDS predicates, 165 isolation, 326 impedance mismatch, eliminating, 41 isolation levels, 320–322, 323 ITERATE implementations, 23 statement, 405–406 IN predicate, 217–218, 270–271, 277–278 Indexed property, Microsoft Access, 88 • J • indexed sequential access method (ISAM), 351 Java applets, 356–357 indexes JDBC (Java DataBase Connectivity), benefi ts of, 116–117 355–357 creating, 92–94, 101 operators deleting, 103 basic joins, 249–250 general discussion, 114–116 Cartesian product, 213 maintaining, 117 ON clauses, 266 information schema, 62 column-name joins, 254–255 inner joins, 255–256 condition joins, 254 input arguments, default, 407 CROSS JOIN, 253 INSENSITIVE keyword, 387–388 double-checking queries including, 436 INSERT statements equi-joins, 251–253 copying data between tables, 150–151 inner joins, 255–256 nested queries, 282–284 natural joins, 253–254 pipelined DML, 284 outer joins, 256–259 privileges, 298, 302 overview, 249 restricting, 73 union joins, 259–265 row value expressions, using with, 208 in views, 56 rows, adding data by, 147–148 WHERE clauses, 266 trigger events, 424, 426 insertion anomaly, 130 • K • instability, platform, 314 INTEGER data type, 27 keys, 112–114 integrated databases, 7 integrated development environments • L • (IDEs), 81 interactive SQL, 333 LAG function, 239–240 interface, ODBC, 350 language characters, 32

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 450450 88/1/13/1/13 22:29:29 PPMM Index 451

LANGUAGE clause, 341 metadata, 7, 359 LAST orientation, 391 methods, UDTs, 41 LAST_VALUE function, 241 Microsoft Access. See Access, Microsoft last-in-fi rst-out (LIFO) stack, 414 Microsoft ActiveX controls, 355 LEAD function, 240 MIN function, 70, 183 leaf subtypes of structured UDTs, 43 MOD function, 194 leaf types, 307 modifi cation anomalies, 129–130, 283–284 LEAVE statement, 403 modifi ed attributes, creating views with, left outer joins, 256–258 144–145 LIFO (last-in-fi rst-out) stack, 414 modifying clauses. See also WHERE clauses LIKE predicate, 218–220 FROM clause, 213 literal values, 172–174 general discussion, 211–213 LN function, 194 GROUP BY clause, 232–234 locking database objects, 324 HAVING clause, 234 logging functions, 423 ORDER BY clause, 235–236 logical connectives, 230–232 modifying table data, granting user access logical schemas, 61 to, 303 login, 299 module language, 339–342 LOOP…ENDLOOP statements, 402–403 modules, 339 LOWER value function, 189 modules, stored, 409–410 lowercase characters, converting modulus, 194 character strings to, 189 MORE fi eld, diagnostics header area, 415 MULTISET data type, 40 • M • multisets, 193, 379 multitable relational databases. See also major entities, 106 data integrity; normalization malicious corruption, 125 character sets, 111–112 managers, listening to opinions of, 432 collations, 111–112 mantissa, 29–30 defi ning objects, 106 mapping designing, 105–106 character sets, 362–363 domains, 111–112 data types, 364 indexes, 114–117 identifi ers, 363 keys, 112–114 non-predefi ned data types to XML, overview, 105 375–379 tables, defi ning, 107–111 tables, 364–365 tables and columns, identifying, 106–107 MATCH predicate, 226–230 translations, 111–112 materials processing, 293 multitable views, creating, 56–60 MAX function, 70, 183 mutator function, for structured UDTs, 43 maximal supertypes of structured UDTs, 43 mechanical failure, 124 • N • MERGE statements, 154–156, 284 MESSAGE_LENGTH fi eld, 420 named arguments, 406–407 MESSAGE_OCTET_LENGTH fi eld, 420 named constraints, 127 MESSAGE_TEXT fi eld, 419–420 NAMES ARE clause, 341

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 451451 88/1/13/1/13 22:29:29 PPMM 452 SQL For Dummies, 8th Edition

NATIONAL CHARACTER data type, 32 NTILE window function, partitioning into NATIONAL CHARACTER LARGE OBJECT buckets with, 239 data type, 32 NULL predicate, 220–221 NATIONAL CHARACTER VARYING data values type, 32 changing values to, with CASE native drivers, 352 expressions, 202–204 natural joins, 253–254 fi nding rows with, 220–221 nested queries general discussion, 46 ALL quantifi er, 275–276 MATCH predicate, 229–230 ANY quantifi er, 275–276 reasons to use, 182 correlated subqueries, 278–281 in XML, handling, 365 DELETE statements, 282–284 NULLIF expressions, 202–204 existence tests, 277–278 NUMBER fi eld, diagnostics header area, 415 INSERT statements, 282–284 NUMERIC data type, 27–28 overview, 71, 267–268 numeric literals, 65 pipelined DML, 284 numeric value expressions, 65, 179 returning sets of rows with, 269–272 numeric value functions, 190–196 returning single values with, 272–275 SOME quantifi er, 275–276 • O • UPDATE statements, 282–284 nesting window functions, 241–242 object model, 5, 18 NEW TABLE keywords, 284 object-oriented programming languages, 18 NEXT orientation, 391 object-oriented rapid application non-predefi ned data types, mapping to development (RAD) tools, 334, 342–343 XML, 375–379 object-relational databases, 5, 18–19 nonrepeatable read, 321 objects, defi ning, 106 normal forms, 38 observer function, for structured UDTs, 43 normalization obsolete data, deleting, 156 abnormal form, 135–136 OCCURRENCES_REGEX function, 191 DK/NF, 134–135 OCTET_LENGTH function, 192–193 fi rst normal form, 132 ODBC (Open DataBase Connectivity) modifi cation anomalies, 129–131 client extensions, 354–355 normal forms, 131–132 in client/server environment, 352 overview, 54, 129, 267 components of, 351 reducing complexity of relationships, 270 and Internet, 352–353 second normal form, 132–134 intranets, 355 third normal form, 134 ODBC interface, 350 NoSQL databases, 11 overview, 349–350 NOT DEFERRABLE constraint, 327 server extensions, 353 NOT EXISTS predicate, 277, 278 ODBC interface, 350 NOT IN keywords, 271–272 OFFSET keyword, 237 NOT IN predicate, 217–218 OLAP (online application processing), 195 NOT LIKE predicate, 218–220 ON clauses, 266 NOT logical connectives, 69, 232, 437 one-to-many relationships, 58, 110 NOT NULL constraints, 163, 327 online application processing (OLAP), 195 NTH_VALUE function, 240–241

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 452452 88/1/13/1/13 22:29:29 PPMM Index 453

Open DataBase Connectivity. See ODBC querying application-time period OPEN statement, 388–390 tables, 164 opening cursors, 388–390 for XML, 371–373 operator error, 124 preprocessor, 337, 338 OR logical connectives, 69, 230–231, 437 previous sessions, 176 ORDER BY clause PRIMARY KEY constraint, 127 general discussion, 235–236 primary keys overview, 212–213 in application-time period tables, using with cursors, 385–386 designating, 162–163 orientation of cursors, 391 changes to, 122 OUTER JOIN operation, 205 descriptive fi eld names for, 86 outer joins, 256–259 general discussion, 112–114 OVERLAPS predicate, 226 in indexes, 93 OVERLAY value function, 188 overview, 53 in system-versioned tables, designating, 167 • P • PRIOR orientation, 391 privilege hierarchy, 300 parameters, 175 privileges parent-child relationship, 120–121 across levels, granting, 307–309 parentheses, using with AND, OR, and assigning to users, 73–75, 77–78 NOT, 437 database object owners, 298–299 parses of strings, 370 DBA, 298–299 PARTIAL keyword, 229–230 of delegating access, 309 partial matches, comparing, 218–220 deleting obsolete rows, 304 partitioning windows into buckets, 239 inserting data, 302 Pascal, 207 maintaining when mapping tables to passwords, 299 XML, 364 percent sign (%) wildcard, 218–220 modifying table data, 303 period defi nitions, 158–159 referencing related tables, 304–305 Persistent Stored Modules. See SQL/PSM retrieval of data, 437 personal databases, 7 revoking, 310–311 phantom read, 321–322 SQL/PSM, 408–409 physical schemas, 61 TRIGGER, 306–307 pipelined DML, 284 to use domains, 306 planning databases, 52–53 using GRANT and REVOKE together, platform instability, 314 311–312 portability considerations, 103 viewing data, 302–303 POSITION function, 190–191 procedural languages POSITION_REGEX function, 191–192 combining SQL and, 335–336 POWER function, 195 overview, 21, 22, 333–334 PRECEDES predicates, 164 strengths and weaknesses of, 335 precision of numbers, 27 procedures, 339 predicates. See also specifi c predicates procedures, stored, 406–407 by name professional design reviews, 434 defi ned, 32 programs, incorporating SQL code into, 23 general discussion, 68 proper subtypes of structured UDTs, 43

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 453453 88/1/13/1/13 22:29:29 PPMM 454 SQL For Dummies, 8th Edition

proprietary APIs, 352 overview, 82 proprietary tools, 141 tracking information, 82–83 protecting data. See also SQL transactions using SQL with, 95–97, 342–343 concurrent access, 315–317 READ COMMITTED isolation level, 321, 322 constraints, 327–331 READ UNCOMMITTED isolation level, equipment failure, 314–315 320–321, 322 overview, 313 READ-WRITE mode, 320 platform instability, 314 REAL data type, 29 public access level, 300 REAL value, 172 records, 7, 13 • Q • recursion, 285–288 recursive queries QBE (Query By Example) grid, 95 general discussion, 288 qualifying rows, 199 overview, 285 quantifi ed comparison operator, 272 recursion, 285–288 queries. See also nested queries; recursive saving time with, 289–293 queries uses for, 293–294 application-time period tables, 164–165 redundancy, 125, 314 bitemporal tables, 170 REF data types, 41 including joins, double-checking, 436 REF IS clause, 309 from keyboard, 22 reference value expressions, 68 overview, 22 REFERENCES privilege, 74, 77, 298 sort order for output, 235 REFERENCING old_or_new_value_ with subselects, double-checking, 436 alias_list phrase, 427–428 system-versioned tables, 168–169 referencing related tables, granting access on test databases, 436 for, 304–305 in XML documents, 361 referential integrity, 75–77, 120–123 Query By Example (QBE) grid, 95 referential integrity constraints, 102, query expressions, 385 163–164, 168 referential integrity rules, and MATCH predicate, 228–230 • R • register sizes, 29 RAD tools. See rapid application relational databases development tools complexity of, 7–8 range check, 124 components of, 12 rapid application development (RAD) tools constraints, 16, 17–18 altering table structure, 90–92 data storage, 6 Datasheet view, building database tables database, defi ned, 7 in, 83–84 DBMS, 8–9 deleting tables, 94–95 design of, 20 Design view, building database tables in, domains, 16, 17 84–86 fl at fi les, 9–11 Design view, setting fi eld properties in, versus object model, 18 86–90 object-relational model, 18–19 indexes, creating, 92–94 overview, 5 relational model, 11–12

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 454454 88/1/13/1/13 22:29:29 PPMM Index 455

relations, 12–13 revoking privileges, 310–311 schemas, 16, 17 right outer joins, 258–259 sizes of, 7–8 roles, 301–302 views, 14–16 ROLLBACK function, 317 relational model, 5, 11–13 ROLLBACK statement, 72, 318, 324 relational operators. See also join routines, stored, 407 operators ROW data type, 38–39, 377 EXCEPT, 248 row triggers, 425 INTERSECT, 246–248 row value expressions, 67, 207–209 overview, 243 row values, 172 UNION, 243–246 ROW_COUNT fi eld, diagnostics header relational values, translating into XML area, 415 elements, 367 rows. See also cursors relations, 12–13 blocks of, adding to tables, 148–151 RELATIVE orientation, 391 data, adding to, 146–148 Remember icon, 2 DBMS processing of, 12–13 REPEAT…UNTIL…END REPEAT deleting, 156 statements, 404 groups of, evaluating in windows, 242 REPEATABLE READ isolation level, 321–322 inserting in database tables, 91 repeating groups, 39 sets of, returning with nested queries, reserved words, 26, 439–442 269–272 RESIGNAL statement, 399, 400, 421 transferring between tables, 149–150 RESTRICT keyword, 310–311 retrieving data • S • backing up data, 438 error handling in applications, 438 sandbox, 356 general discussion, 139–141 SAVEPOINT statement, 325, 326–327 GROUP BY clause, restrictions on, 437 savepoints, 325, 326–327 overview, 435 scalable database management systems, 8 parentheses, using with AND, OR, and scalar value, 172 NOT, 437 scale of numbers, 28 privileges, controlling, 437 SCHEMA clause, 341 queries including joins, double- SCHEMA_NAME fi eld, 419 checking, 436 schemas, 16, 17, 52, 61–63 queries on test databases, 436 schemas, XML, 359, 366 queries with subselects, double- scripts, 355 checking, 436 SCROLL keyword, 388 summarize data with GROUP BY, 436–437 scrollability, cursor, 384, 388, 391 verifying database structure, 435 search conditions, CASE expressions with, returnability, cursor, 385 198–200 REVOKE DELETE statement, 74 second normal form (2NF), 132–134 REVOKE INSERT statement, 74 security. See also privileges REVOKE REFERENCES statement, 74 DCL statements, 298 REVOKE SELECT statement, 74 delegating responsibility for, 77–78 REVOKE statement, 73, 310–312 domains, 305–306 REVOKE UPDATE statement, 74 Microsoft Access, 100–101

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 455455 88/1/13/1/13 22:29:29 PPMM 456 SQL For Dummies, 8th Edition

overview, 297 source types, 42 performing database manipulations over special variables, 176 Internet, 49–50 SQL referential integrity, 75–77 in client/server systems, 47–49 roles, 301–302 general discussion, 21–23 user access levels, 298–300 history of, 23–24 views, creating, 145 on Internet, 49–50 SELECT statements on intranets, 49–50 pipelined DML, 284 overview, 21 as query expressions, 385 reserved words, 26, 439–442 restricting, 73 statements, 24–25 retrieving data with, 140 SQL transactions transferring data between tables, 150 ACID databases, 326 user access, 298 backing up data, 325 selection conditions, creating views with, COMMIT statement, 324 143–144 constraints in, 327–331 sensitivity, cursor, 384, 387–388 default, 319–320 SEQUEL (Structured English QUEry isolation levels, 320–322 Language), 23 locking database objects, 324 SERIALIZABLE isolation level, 320, 322, 323 ROLLBACK statement, 324 serializing concurrent transactions, 317 savepoints, 325, 326–327 server extensions, 353 SET TRANSACTION statement, 323 servers, 47–48 subtransactions, 325, 326–327 SESSION_USER special variable, 176 transaction-starting statements, 322–323 sessions, 176 SQL View, Microsoft Access, 96–97, 344 SET CONSTRAINTS DEFERRED statement, SQL View Object tab, Microsoft Access, 329–330 96–97, 98 set functions SQL:2008 reserved words, 439–442 AVG, 183 SQL:2011, 24. See also temporal data COUNT, 182–183 SQL/PSM (Persistent Stored Modules). general discussion, 69–71 See also compound statements GROUP BY clause, combining with, 232 fl ow of control statement, 400–406 MAX, 183 overview, 393 MIN, 183 privileges, 408–409 overview, 181–183 stored functions, 407–408 SUM, 184 stored modules, 409–410 SET TRANSACTION statement, 319, 323, 414 stored procedures, 406–407 SIMILAR predicate, 220 SQLSTATE status parameter SIMPLE keyword, 229–230 general discussion, 396–398, 411–413 single-table views, 55–56 interpreting information returned by, SMALLINT data type, 27 419–420 social engineering, 76 SQRT function, 195 software, stability of, 314 statement triggers, 425 SOME predicate, 221–224 statements SOME quantifi er, nested queries, 275–276 DDL, 62–64 sort order for output, 235, 386 SQL, 24–25

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 456456 88/1/13/1/13 22:29:29 PPMM Index 457

status parameter. See SQLSTATE status SUBSTRING value function, 185–186 parameter SUBSTRING_REGEX value function, 186–187 stored functions, 407–408 substrings, 185, 188 stored modules, 409–410 subtransactions, 325, 326–327 stored procedures, 406–407 subtypes of structured UDTs, 43 stored routines, 407 SUCCEEDS predicates, 165 string concatenation, 65–66 SUM function, 70, 184 string value expressions summarizing data with GROUP BY, 436–437 CONVERT, 189 super user, 299 general discussion, 65–66, 178 syntax of SQL, 23 LOWER, 189 system administrator, 299 OVERLAY, 188 system architecture, 433 overview, 184 SYSTEM_TIME AS OF syntax, 168 SUBSTRING, 185–186 SYSTEM_TIME keyword, 159 SUBSTRING SIMILAR, 186 SYSTEM_USER special variable, 176 SUBSTRING_REGEX, 186–187 system-versioned tables, 166–169 TRANSLATE, 189 TRANSLATE_REGEX, 187–188 • T • TRIM, 189 UPPER, 188 table constraints, 126, 127–128 structure of database, 9, 435 TABLE_NAME fi eld, 419 Structured English QUEry Language tables. See also application-time period (SEQUEL), 23 tables; views structured user-defi ned types, 43–44, access privileges, assigning, 74 307–308 altering, 63, 102 style sheets, 359 bitemporal, 169–170 SUBCLASS_ORIGIN fi eld, diagnostics detail blocks of rows, adding to, 148–151 area, 417 changing data in, 12 sublanguage, 22 collecting into schemas, 61 subqueries columns, adding to existing, 123 ALL quantifi er, 275–276 columns, deleting from existing, 124 ANY quantifi er, 275–276 constraints, adding to existing, 419 correlated subqueries, 278–281 creating, 53–55, 63, 97–101 DELETE statements, 282–284 defi ning, in multitable relational existence tests, 277–278 databases, 107–111 EXISTS predicate, using with, 224–225 deleting, 94–95, 102 INSERT statements, 282–284 deleting rows in, granting privileges overview, 71, 267–268 for, 304 pipelined DML, 284 fi ring multiple triggers, 428 returning sets of rows with, 269–272 identifying, in multitable relational returning single values with, 272–275 databases, 106–107 SOME quantifi er, 275–276 mapping to XML documents, 364–365 UNIQUE predicate, using with, 225 removing, 64 UPDATE statements, 282–284 system-versioned, 165–169 subselects, 150, 153, 436 transferring data between, 149–150 SUBSTRING SIMILAR value function, 186

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 457457 88/1/13/1/13 22:29:29 PPMM 458 SQL For Dummies, 8th Edition

tables (continued) triggers typed, 307–308 applications of, 423–424 updating existing data, 151–154 creating, 424–426 views, 14–16, 142–143 fi ring multiple, on single tables, 428 XML data, transforming into, 373–374 overview, 423 Technical Stuff icon, 2 referencing old and new values, 427–428 temporal data. See also application-time in system-versioned tables, 167 period tables trigger execution contexts, 426 bitemporal tables, 169–170 TRIM value function, 189 overview, 157 TRIM_ARRAY function, 40, 194 periods, 158–159 two-dimensional arrays, 12 system-versioned tables, 165–169 typed tables, 307–308 times, 158–159 termination condition, 287 • U • test databases, queries on, 436 third normal form (3NF), 53 UDTs (user-defi ned types), 41–44, 67, 376 third-generation languages, 81 UNDER keyword, 298 TIME WITH TIME ZONE data type, 35 underscore (_) wildcard, 218–220 TIME WITHOUT TIME ZONE data type, 34 UNDO effect, 399 time zones, 179–180 Unicode, 363 times, 158–159, 179–180, 226 UNION ALL operation, 245 TIMESTAMP value, 172 UNION CORRESPONDING operation, TIMESTAMP WITH TIME ZONE data 245–246 type, 35 union joins, 259–265 TIMESTAMP WITHOUT TIME ZONE data UNION operator, 150, 243–246 type, 34 union-compatible tables, 243–245 timestamps, 168–169 UNIQUE keyword, 229–230 Tip icon, 2 UNIQUE predicate, 225 transaction processing, 315 updatability clause of DECLARE CURSOR transaction time, 158 statement, 387 TRANSACTION_ACTIVE fi eld, 416 anomalies, 120–123 transactions, 71–72 UPDATE statements TRANSACTIONS_COMMITTED fi eld, 416 bitemporal tables, 170 TRANSACTIONS_ROLLED_BACK fi eld, 416 CASE expressions, using with, 199–200 transaction-starting statements, 322–323 general discussion, 151–154 transferring data, 149–150, 154–156 nested queries, 282–284 transitive dependency, 134 pipelined DML, 284 TRANSLATE value function, 189 restricting, 73 TRANSLATE_REGEX value function, system-versioned tables, 166, 167 187–188 trigger events, 424, 426 translation tables, 63, 74 user access, 298 translations, 111–112 using with cursors, 391–392 trigger execution contexts, 426 updating TRIGGER keyword, 298 application-time period tables, 160–161 TRIGGER privileges, granting, 306–307 database tables, 90–91 triggered SQL statements, 425 existing data, 151–154

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 458458 88/1/13/1/13 22:29:29 PPMM Index 459

rows in cursor operations, 391–392 updating based on conditions, 199–200 system-versioned tables, 165 value expressions, 177–180 table rows accessed with cursors, 387 variables, 174–175 values, based on conditions, 199–200 VARBINARY data type, 33 views, 145 variables, 172, 174–175, 395–396 UPPER value function, 188 verifying database structure, 435 uppercase characters, converting viewing data, granting user access to, character strings to, 188 302–303 USAGE keyword, 298 views user access levels, 298–300 creating, 141–145 user access privileges. See privileges general discussion, 14–16 user interface, 335 multitable, 56–60 user names, 301–302 overview, 55 user-defi ned types (UDTs), 41–44, 67, 376 single-table, 55–56 updating, 145 • V • virtual tables, 14–16, 141 VALID predicate, 372–373 • W • valid time, 158 validation checks, 355 Warning icon, 2 value expressions. See also CASE web-based database systems, 352–354 expressions WHEN clause, 425 CAST, 205–207 WHENEVER clause, 413–414 conditional, 180 WHERE clauses. See also nested queries datetime, 179–180 ALL predicate, 221–224 general discussion, 64–68 ANY predicate, 221–224 interval, 180 comparison predicates, 215 numeric, 179 DISTINCT predicate, 225 overview, 177–178 equi-joins, 251–253 row, 207–209 EXISTS predicate, 224–225 string, 178 general discussion, 213–215 value functions. See also string value join operators, 266 expressions LIKE predicate, 218–220 datetime, 196 MATCH predicate, 226–228 interval, 196 NOT IN predicate, 217–218 numeric, 190–196 NOT LIKE predicate, 218–220 overview, 184 NULL predicate, 220–221 values. See also functions; value functions OVERLAPS predicate, 226 CASE expressions with, 200–202 overview, 140, 212 COALESCE expressions, 204–205 BETWEEN predicate, 215–217 column references, 176–177 IN predicate, 217–218 literal, 172–174 recursive queries, 292 overview, 171 referential integrity rules and MATCH row, 172 predicate, 228–230 special variables, 176 SIMILAR predicate, 220 types of, 171–172 SOME predicate, 221–224

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 459459 88/1/13/1/13 22:29:29 PPMM 460 SQL For Dummies, 8th Edition

WHERE clauses (continued) XML data type, 35–38, 360–362 UNIQUE predicate, 225 XML Names, 363 with UPDATE statements, 153 XML schemas, 359, 366 WHILE…DO…END WHILE statements, 404 XMLAGG function, 369 WIDTH_BUCKET function, 195–196 XMLCAST function, 371 windows, 238–242 XMLCOMMENT function, 369 WITH GRANT OPTION clause, 77–78, 309 XMLCONCAT function, 368 WITH IDENTITY CONSTRAINTS GLOBAL XML(CONTENT(ANY)) type, 36–37 component of VALID predicate, 373 XML(CONTENT(UNTYPED)) type, 37 WITH IDENTITY CONSTRAINTS LOCAL XML(CONTENT(XMLSCHEMA)) subtype, 37 component of VALID predicate, 373 XMLDOCUMENT function, 367 WITH SYSTEM VERSIONING keyword, 166 XML(DOCUMENT(ANY)) subtype, 37 WITH TIES syntax, 237–238 XML(DOCUMENT(UNTYPED)) type, 37–38 WITHOUT IDENTITY CONSTRAINTS XMLELEMENT function, 367 component of VALID predicate, 373 XMLEXISTS predicate, 372 WORK keyword, 324 XMLFOREST function, 368 workgroup databases, 8 XMLPARSE function, 370 written agreements about projects, 432 XMLPI function, 370 XMLQUERY function, 370–371 • X • XML(SEQUENCE) type, 36 XMLTABLE pseudo-function, 373–374 XML (eXtensible Markup Language) XQuery character sets, mapping, 362–363 overview, 36, 367 data types, mapping, 364 regular expression patterns, replacing generating XML schemas, 366 with replacement strings, 187–188 identifi ers, mapping, 363 regular expression patterns, searching non-predefi ned data types, mapping to, strings for, 186–187 375–379 XMLQUERY function, 370–371 null values, handling, 365 overview, 359 • Y • predicates, 371–373 and SQL, 359–360, 379–380 year-month intervals, 35, 66, 180 SQL functions for XML data, 367–371 tables, mapping, 364–365 transforming into SQL tables, 373–374 XML data type, 360–362

336_9781118607961-bindex.indd6_9781118607961-bindex.indd 460460 88/1/13/1/13 22:29:29 PPMM