SQL in a Nutshell pdf

226 534 0
SQL in a Nutshell pdf

Đ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

sql_titlepg.qxd 10/13/00 5:27 PM Page SOL SOL IN A NUTSHELL A Desktop Quick Reference sql_titlepg.qxd 10/13/00 5:27 PM Page sql_titlepg.qxd 10/13/00 5:27 PM Page SOL SOL IN A NUTSHELL A Desktop Quick Reference Kevin Kline with Daniel Kline Beijing • Cambridge • Farnham • Kưln • Paris • Sebastopol • Taipei • Tokyo ,COPYRIGHT.12247 Page iv Friday, March 23, 2001 10:05 AM SQL in a Nutshell by Kevin Kline with Daniel Kline Copyright © 2001 O’Reilly & Associates, Inc All rights reserved Printed in the United States of America Published by O’Reilly & Associates, Inc., 101 Morris Street, Sebastopol, CA 95472 Editor: Gigi Estabrook Production Editor: Mary Sheehan Cover Designer: Ellie Volckhausen Printing History: January 2001: First Edition Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly & Associates, Inc The association between the image of a chameleon and the topic of SQL is a trademark of O’Reilly & Associates, Inc Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and O’Reilly & Associates, Inc was aware of a trademark claim, the designations have been printed in caps or initial caps While every precaution has been taken in the preparation of this book, the publisher assumes no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein Library of Congress Cataloging-in-Publication Data Kline, Kevin E., 1966SQL in a nutshell : a desktop quick reference/Kevin Kline with Daniel Kline p cm Includes index ISBN 1-56592-744-3 SQL server SQL (Computer program language) Client/server computing I Kline, Daniel QA76.73.S67 K55 2000 005.75'85 dc21 ISBN: 1-56592-744-3 [M] 00-065206 [4/01] ,AUTHOR.COLO.12098 Page Friday, March 23, 2001 10:05 AM About the Author Kevin Kline is the team leader for Information Architecture within Shared Information Services at Deloitte & Touche LLP Kevin and his team perform data and infrastructure architecture in support of major knowledge management and transaction processing systems for Deloitte’s Client Service Technology organization Kevin is also the author of Transact-SQL Programming (O’Reilly, 1999) (http:// www.oreilly.com/catalog/wintrnssql/ ) and numerous magazine articles on Microsoft SQL Server When he’s not pulling his hair out over work issues, Kevin likes to romance his wife, play with his three kids, tinker with his ’66 Chevy pickup, and garden Other than being Kevin’s brother, Daniel Kline is an Assistant Professor of English at the University of Alaska, Anchorage, where he specializes in medieval literature, literary and cultural theory, and computer-assisted pedagogy He completed his Ph.D at Indiana University, Bloomington, and in addition to numerous scholarly presentations, Dan recently has published academic essays in Literary and Linguistic Computing, Philological Quarterly, Chaucer Review, and Essays in Medieval Studies When he’s not spending time with his wife and two boys, Dan frets over his pet project, the Electronic Canterbury Tales (http://cwolf.uaa.alaska.edu/~afdtk/ext_main.htm) Dan can be reached at afdtk@ uaa.alaska.edu Colophon Our look is the result of reader comments, our own experimentation, and feedback from distribution channels Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects The animal on the cover of SQL in a Nutshell is a chameleon There are approximately 85 species of chameleons existing in the world today They are mostly indigenous to Africa, although there are a few species found in Asia and in Europe Most are tree dwellers The chameleon is relatively small; the average adult size is between inches and 12 inches It lives mostly on insects, and uses its long tongue to capture its prey Indeed, the tongue is a critical tool It can stretch up to 1.5 times the lizard’s body length, and there is an adhesive pad on the end, which the insects are trapped on There are several other characteristics common to all species of chameleons For example, its eyes are large and protruding, and the lizard can see 360 degrees around without moving its head or body Its toes are on either side of its feet, usually with three on one side and two on the other This is ideal for moving quickly and efficiently through tree branches Chameleons are best known for their ability to change their appearance to adapt to their physical environment Actually, several types of reptiles can change their skin color, but the chameleon is far and away the most accomplished This skill, which is moderated by the nervous system, obviously is invaluable for hunting prey and avoiding predators, and also helps to stablize body temperature The extent of this camouflage capability is related to the gender, age, and species of the lizard ,AUTHOR.COLO.12098 Page Friday, March 23, 2001 10:05 AM Mary Sheehan was the production editor and proofreader for SQL in a Nutshell, and Jeffrey Holcomb was the copyeditor Emily Quill and Colleen Gorman provided quality control Linley Dolby provided production assistance Brenda Miller wrote the index Ellie Volckhausen designed the cover of this book, based on a series design by Edie Freedman The cover image is a 19th-century engraving from the Dover Pictorial Archive Emma Colby produced the cover layout with QuarkXPress 4.1 using Adobe’s ITC Garamond font Melanie Wang designed the interior layout based on a series design by Nancy Priest The text and heading fonts are ITC Garamond Light and Garamond Book The illustrations that appear in the book were produced by Robert Romano using Macromedia FreeHand and Adobe Photoshop This colophon was written by Mary Sheehan Whenever possible, our books use a durable and flexible lay-flat binding If the page count exceeds this binding’s limit, perfect binding is used ,sql_ianTOC.fm.14129 Page iii Wednesday, November 29, 2000 4:45 PM Table of Contents Preface v Chapter 1—SQL, Vendor Implementations, and Some History The Relational Database Model The Databases Described in This Book The SQL Standard Dialects of SQL Principles of Relational Databases 2 Chapter 2—Foundational Concepts Row Processing Versus Set Processing The Relational Model 10 SQL99 and Vendor-Specific Datatypes 10 Processing NULLS 18 Categories of Syntax 19 Using SQL 23 Conclusion 26 Chapter 3—SQL Statements Command Reference 27 Recommended Reading Approach 27 Quick SQL Command Reference 27 DROP Statements 96 Conclusion 162 iii Computer Crime: A Crimefighter’s Handbok, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc All rights reserved ,sql_ianTOC.fm.14129 Page iv Wednesday, November 29, 2000 4:45 PM Chapter 4—SQL Functions 163 Deterministic and Nondeterministic Functions 163 Types of Functions 164 Vendor Extensions 175 Chapter 5—Unimplemented SQL99 Commands 194 Appendix—SQL99 and Vendor-Specific Keywords 197 Index 205 iv Table of Contents Computer Crime: A Crimefighter’s Handbok, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc All rights reserved ,ch00.13241 Page v Wednesday, November 29, 2000 4:41 PM Preface The explosive growth of the information technology industry and the constantly growing need to compile, store, access, and manipulate increasingly larger masses of data have required the development of ever more sophisticated database management tools Since its first incarnation in the 1970s, Structured Query Language (SQL) has been developed hand in hand with the information boom, and as a result, is the most widely used database manipulation language in business and industry A number of different software companies and program developers, including those in the open source movement, have concurrently developed their own SQL dialects in response to specific needs All the while, standards bodies have developed a growing list of common features SQL in a Nutshell identifies the differences between the various vendor implementations of SQL Readers will find a concise explanation of the Relational Database Management System (RDBMS) model, a clear-cut explanation of foundational RDBMS concepts, and thorough coverage of basic SQL syntax and commands Most importantly, programmers and developers who use SQL in a Nutshell will find a concise guide both to the most popular commercial database packages on the market (Microsoft SQL Server and Oracle8i), and to two of the best known open source (http://www.opensource.org) database products (MySQL and PostgreSQL) SQL in a Nutshell’s attention to open source SQL products is an affirmation of the growing importance of the open source movement within the computing community As a result, SQL in a Nutshell benefits several distinct groups of users: the knowledgeable programmer who requires a concise and handy reference tool, the developer who needs to migrate from one SQL dialect to another, and the user who comes to SQL from another programming language and wants to learn the basics of SQL programming v Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc All rights reserved ,ch00.13241 Page vi Wednesday, November 29, 2000 4:41 PM How This Book Is Organized How This Book Is Organized This book is divided into five chapters and one appendix: Chapter 1, SQL, Vendor Implementations, and Some History This chapter discusses the Relational Database Model, describes the current and previous SQL standards, and introduces the SQL vendor implementations covered in this book Chapter 2, Foundational Concepts This chapter describes the fundamental concepts necessary for understanding relational databases and SQL commands Chapter 3, SQL Statements Command Reference This chapter is an alphabetical command reference It details each SQL99 command, as well as the implementations of each command by Oracle, Microsoft SQL Server, MySQL, and PostgreSQL Chapter 4, SQL Functions This chapter is an alphabetical reference of the SQL99 functions, describing vendor implementations of these functions and vendor extensions Chapter 5, Unimplemented SQL99 Commands This chapter lists commands that are included in the SQL standards, but have not yet been implemented by any of the vendors Appendix, SQL99 and Vendor-Specific Keywords The appendix provides a table that displays keywords declared in SQL99 and by the various database vendors Conventions Used in This Book Constant Width Used to indicate programming syntax, code fragments, and examples Italic Used to introduce new terms, for emphasis, and to indicate commands or user-specified file and directory names Bold Used to display the names of database objects, such as tables, columns, and stored procedures UPPERCASE Used to indicate SQL keywords The owl icon indicates a tip, suggestion, or general note vi Preface Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc All rights reserved ,appa.13975 Page 200 Wednesday, November 29, 2000 4:44 PM SQL99 and Vendor-Specific Keywords Table A-3: MySQL Keywords ACTION ALL ASC ADD ALTER AUTO_INCREMENT AFTER AND AVG BETWEEN BLOB CASCADE CHARACTER COLUMNS CROSS BIGINT BOOL CASE CHECK COMMENT CURRENT_DATE BINARY BOTH CHANGE CHECKSUM CONSTRAINT CURRENT_TIME DATA DATETIME DAY_SECOND DEC DATABASE DAY DAYOFMONTH DECIMAL DATABASEs DAY_HOUR DAYOFWEEK DEFAULT DELAYED DISTINCT ELSE ESCAPE FIELDS FLOAT4 FOREIGN GLOBAL HAVING HOUR IF INFILE INT INT4 INTO KEY LEADING LIMIT LOCK LONGTEXT MAX_ROWS MIDDLEINT MODIFY NATURAL NUMERIC OPTIONALLY OUTFILE PRECISION DELETE DISTINCTROW ENCLOSED ESCAPED FILE FLOAT8 FROM GRANT HEAP HOUR_MINUTE IGNORE INNER INT1 INT8 IS KEYS LEFT LINES LOGS LOW_PRIORITY MEDIUMBLOB MIN_ROWS MONTH NO ON OR PACK_KEYS PRIMARY DESC DOUBLE END EXISTS FIRST FLUSH FULL GRANTS HIGH_PRIORITY HOUR_SECOND IN INSERT INT2 INTEGER ISAM KILL LENGTH LOAD LONG MATCH MEDIUMINT MINUTE MONTHNAME NOT OPTIMIZE ORDER PARTIAL PRIVILEGES 200 AGGREGATE AS AVG_ROW_ LENGTH BIT BY CHAR COLUMN CREATE CURRENT_ TIMESTAMP DATE DAY_MINUTE DAYOFYEAR DELAY_KEY_ WRITE DESCRIBE DROP ENUM EXPLAIN FLOAT FOR FUNCTION GROUP HOSTS IDENTIFIED INDEX INSERT_ID INT3 INTERVAL JOIN LAST_INSERT_ID LIKE LOCAL LONGBLOB MAX MEDIUMTEXT MINUTE_SECOND MYISAM NULL OPTION OUTER PASSWORD PROCEDURE SQL99 and Vendor-Specific Keywords Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc All rights reserved ,appa.13975 Page 201 Wednesday, November 29, 2000 4:44 PM SQL99 and Vendor-Specific Keywords Table A-3: MySQL Keywords (continued) PROCESS REFERENCES REPLACE RLIKE SELECT SMALLINT SQL_BIG_TABLES PROCESSLIST REGEXP RESTRICT ROW SET SONAME SQL_LOG_OFF READ RELOAD RETURNS ROWS SHOW SQL_BIG_RESULT SQL_LOG_UPDATE SQL_SELECT_LIMIT SQL_SMALL_ RESULT STRAIGHT_JOIN SQL_WARNINGS TEMPORARY TIME TINYTEXT UNIQUE USAGE VARBINARY WHEN TERMINATED TIMESTAMP TO UNLOCK USE VARCHAR WITH SQL_SMALL_ RESULT TEXT TINYBLOB TRAILING UNSIGNED USING VARIABLES WRITE ALL ARRAY AUTHID BINARY INTEGER BY CLOSE COMMENT CONSTANT CURSOR DECIMAL DISTINCT ELSIF EXECUTE FALSE FOR GOTO HEAP IMMEDIATE INDICATOR INTERFACE IS ALTER AS AVG BODY CHAR CLUSTER COMMIT CREATE DATE DEFAULT DO END EXISTS FETCH FORALL GRANT HOUR IN INITIAL INTERSECT ISOLATION STATUS TABLES THEN TINYINT TYPE UPDATE VALUES VARYING ZEROFILL STRING REAL RENAME REVOKE SECOND SHUTDOWN SQL_BIG_SELECTS SQL_LOW_ PRIORITY_ UPDATES STARTING Table A-4: Oracle Keywords ADD ANY AUDIT BETWEEN BULK CHECK COLUMN CONNECT CURRVAL DECLARE DESC ELSE EXCLUSIVE EXTENDS FLOAT FUNCTION HAVING IF INDEX INTEGER INTO SQL99 and Vendor-Specific Keywords Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc All rights reserved Keywords ACCESS AND ACS BEGIN BOOLEAN CHAR_BASE COLLECT COMPRESS CURRENT DAY DELETE DROP EXCEPTION EXIT FILE FROM GROUP IDENTIFIED INCREMENT INSERT INTERVAL 201 ,appa.13975 Page 202 Wednesday, November 29, 2000 4:44 PM SQL99 and Vendor-Specific Keywords Table A-4: Oracle Keywords (continued) JAVA LOCK MAXEXTENTS MLSLABEL MONTH NEXTVAL NOT NUMBER_BASE ON OPERATOR ORGANIZATION PARTITION POSITIVEN PRIVILEGES RANGE REF RETURN ROW ROWNUM SELECT SHARE SQL STDDEV SYNONYM TIME TRUE UNIQUE VALIDATE VARIANCE WHERE WRITE LEVEL LONG MIN MOD NATURAL NOAUDIT NOWAIT OCIROWID ONLINE OPTION OTHERS PCTFREE PRAGMA PROCEDURE RAW RELEASE REVERSE ROWS ROWTYPE SEPERATE SIZE SQLCODE SUBTYPE SYSDATE TIMESTAMP TYPE UPDATE VALUES VIEW WHILE YEAR LIKE LOOP MINUS MODE NATURALN NOCOMPRESS NULL OF OPAQUE OR OUT PLS_INTEGER PRIOR PUBLIC REAL RENAME REVOKE ROWID SAVEPOINT SESSION SMALLINT SQLERRM SUCCESSFUL TABLE TO UID USE VARCHAR WHEN WITH ZONE LIMITED MAX MINUTE MODIFY NEW NOCOPY NUMBER OFFLINE OPEN ORDER PACKAGE POSITIVE PRIVATE RAISE RECORD RESOURCE ROLLBACK ROWLABEL SECOND SET SPACE START SUM THEN TRIGGER UNION USER VARCHAR2 WHENEVER WORK ALL AND ASC AVG BIT CASCADE CATALOG CHARACTER_ LENGTH COALESCE ALLOCATE ANY ASSERTION BEGIN BIT_LENGTH CASCADED CHAR CHECK Table A-5: PostgreSQL Keywords ABORT ALTER ARE AT BETWEEN BOTH CASE CHAR_LENGTH ADD ANALYZE AS AUTHORIZATION BINARY BY CAST CHARACTER CLOSE CLUSTER 202 COLLATE SQL99 and Vendor-Specific Keywords Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc All rights reserved ,appa.13975 Page 203 Wednesday, November 29, 2000 4:44 PM SQL99 and Vendor-Specific Keywords Table A-5: PostgreSQL Keywords (continued) COLLATION CONNECTION COPY CROSS CURRENT_TIME COMMIT CONTINUE COUNT CURRENT_DATE CURRENT_USER CONNECT CONVERT CREATE CURRENT_SESSION CURSOR DEC DELETE DIAGNOSTICS DOMAIN ESCAPE EXECUTE EXTERNAL FIRST FOUND GLOBAL GROUP INDICATOR INTERSECT JOIN LIKE LOCK MODULE NATURAL NONE NULLIF ON OUTER POSITION PRIMARY REFERENCES ROLLBACK SELECT SETOF SQL SUBSTRING TEMPORARY TRANSACTION TRUE UNLISTEN USAGE VALUE VERBOSE WHERE DECIMAL DESC DISCONNECT DROP EXCEPT EXISTS EXTRACT FLOAT FROM GO HAVING INNER INTERVAL LAST LISTEN LOWER MOVE NCHAR NOT NUMERIC OPEN OUTPUT PRECISION PRIVILEGES RESET ROWS SESSION SHOW SQLCODE SUBSTRING THEN TRANSLATE UNION UNTIL USER VALUES VIEW WITH SQL99 and Vendor-Specific Keywords Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc All rights reserved Keywords DATE DECLARE DESCRIBE DISTINCT ELSE EXCEPTION EXPLAIN FALSE FOR FULL GOTO IDENTITY INPUT INTO LEADING LOAD MAX NAMES NEW NOTIFY OCTET_LENGTH OR OVERLAPS PREPARE PROCEDURE REVOKE SCHEMA SESSION_USER SIZE SQLERROR SYSTEM_USER TO TRANSLATION UNIQUE UPDATE USING VARCHAR WHEN WORK COLUMN CONSTRAINT CORRESPONDING CURRENT CURRENT_ TIMESTAMP DEALLOCATE DEFAULT DESCRIPTOR DO END EXEC EXTEND FETCH FOREIGN GET GRANT IN INSERT IS LEFT LOCAL MIN NATIONAL NO NULL OFFSET ORDER PARTIAL PRESERVE PUBLIC RIGHT SECTION SET SOME SQLSTATE TABLE TRAILING TRIM UNKNOWN UPPER VACUUM VARYING WHENEVER WRITE 203 ,appa.13975 Page 204 Wednesday, November 29, 2000 4:44 PM ,sql_ianIX.fm.14249 Page 205 Wednesday, November 29, 2000 4:45 PM Index Symbols + addition arithmetic operator, 121 = assignment operator, 121 * asterisk, 25 @ at symbol, 61 & bitwise AND operator, 122 ^ bitwise exclusive OR operator, 122 | bitwise OR operator, 122 : colon, 84 / division arithmetic operator, 121 ’ ’ double apostrophe, 22 || double-pipe mark, 46, 170 ## double-pound sign, 61, 68 “ ” double quotation marks, 22 = equal to comparison operator, 122 =* equal-asterisk, 135 > greater than operator, 122 >= greater than or equal to operator, 122 < less than operator, 122 not equal to operator, 122 !> not greater than operator, 122 !< not less than operator, 122 + outer join operator, 25 + plus sign, 46, 170 +* plus-asterisk, 135 # pound sign, 61, 68 ‘ ’ single quotation marks, 21, 22 - subtraction arithmetic operator, 121 + unary operator, 123 - unary operator, 123 ~ unary operator, 123 _ underscore, 66 A abbreviations, using consistently, 20 ABSOLUTE operation (FETCH statement), 104 access privileges (see privileges) ADD keyword (PostgreSQL), 36 adding columns (PostgreSQL), 36 records/rows, 115 addition (+) arithmetic operator, 121 aggregate functions, 144, 164–166 ALL clause, DISCONNECT statement and, 95 ALL logical operator, 123 alphabetical reference of statements, 30–162 list in table, 28–30 ALTER PROCEDURE statement, 30 ALTER TABLE statement, 32 multiple clauses issued in (MySQL), 34 ALTER TRIGGER statement, 36 ALTER VIEW statement, 38 altering procedures, 30 tables, 32 triggers, 36 views, 38 American National Standards Institute (ANSI), AND CHAIN keyword, 45 AND logical operator, 123 205 Computer Crime: A Crimefighter’s Handbok, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc All rights reserved ,sql_ianIX.fm.14249 Page 206 Wednesday, November 29, 2000 4:45 PM anomalies, 155 ANSI (American National Standards Institute), ANSI joins, 25 ANSI standards, ANSI style of joins, 135 ANY logical operator, 123 ANY option (GRANT statement, Oracle), 109 arithmetic operators, 121 AS keyword, assignment operator and, 121 ascending indexes, creating (PostgreSQL), 59 assignment (=) operator, 121 asterisks asterisk (* ), SQL Server and, 25 equal-asterisk (=*), 135 plus-asterisk (+*), 135 at symbol (@) specifying stored procedure input parameters (SQL Server), 61 atomic values, 10 Authorization ID, 10 function for currently active, 166 AVG aggregate function, 144 AVG function, 164 B base tables, 24 (see also tables) BEGIN TRANSACTION statement, 156 vs START TRANSACTION statement and SET TRANSACTION statement, 156 BETWEEN logical operator, 123 binding styles, BIT_LENGTH function, 168 BITMAP indexes (Oracle), 57 bitwise AND (&) operator, 122 bitwise exclusive OR (^) operator, 122 bitwise OR (|) operator, 122 blank spaces, LIKE operator and, 119 BLOBs, MySQL datatypes for, 14 boolean comparison operators, 122 built-in scalar functions, 166 C CALL statement, 39 Cantor, Georg, CASE function, 40 case of strings, changing, 172 case sensitivity LIKE operator and, 118 naming conventions and, 19 206 CAST function, 42 vs CONVERT function with SQL Server, 171 vs CREATE FUNCTION statement, 50 categories of syntax for SQL statements, 19–23 changes committed to databases, DROP TABLE statement and (Oracle), 101 character literals, 21 character sets, 10 translating, 171 character strings converting, 171 extracting one from another, 173 leading spaces, removing from, 174 trailing characters, removing from, 174 CHARACTER_LENGTH function (MySQL, PostgreSQL), 168 CHARINDEX function (SQL Server), 169 CHAR_LENGTH function, 168 CLOSE CURSOR statement, 43 closing server-side cursors, 43 clustered indexes, 56 as defined in Oracle vs SQL Server, 58 clusters created with Oracle-specific command, 57 Codd, E.F., Twelve Principles of Relational Databases, 7, collations, 10 colon (:) prefacing OLD/NEW pseudo-tables, 84 column lists, 87 columns, 1, 10 ALTER TABLE statement and, 33 Oracle, 35 PostgreSQL, 36 calculated, indexes created on (SQL Server), 56 multiple building indexes upon (MySQL), 57 comma indicating, 67 multiple actions to (Oracle), 36 renaming (MySQL), 34 retrieving, 132–151 comma identifying multiple roles with, 152 indicating multiple column definitions with, 67 specifying multiple access privileges with, 105 SQL and, 21 commands (see statements) Index Computer Crime: A Crimefighter’s Handbok, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc All rights reserved ,sql_ianIX.fm.14249 Page 207 Wednesday, November 29, 2000 4:45 PM COMMIT TRANSACTION statement, 44 BEGIN statement and, 157 ROLLBACK statement and, 129 committing changes to databases, DROP TABLE statement and (Oracle), 101 company names, naming conventions and, 20 comparison operators, 122 composite indexes, 56 COMPUTE clause (SELECT statement, SQL Server), 148 CONCAT function (MySQL), 46, 170 CONCATENATE function, 170 concatenated indexes, 56 concatenated key, 60 concatenation operators, 46 conformance, levels of, CONNECT statement, 46 CONNECT TO DEFAULT statement, 47 connections disconnecting, 95 open, switching between, 151 CONVERT function, 171 in SQL Server, 168 Core SQL99 standard, COUNT aggregate function, 144 COUNT(*) aggregate function, 144 COUNT DISTINCT aggregate function, 144 COUNT function, 165 CREATE CLUSTER command (Oracle), 57 CREATE commands, destroying with DROP statements, 96 CREATE DATABASE statement, 48 caution when using in Oracle, 49 DROP DATABASE statement and, 96 CREATE FUNCTION statement, 50 in MySQL, 53 RETURN statement and, 124 as substitute for CREATE PROCEDURE statement (PostgreSQL), 55 CREATE INDEX statement, 55 CREATE PROCEDURE statement, 60 ALTER PROCEDURE statement and, 30 CREATE FUNCTION statement as substitute for (PostgreSQL), 55 (see also CREATE FUNCTION statement) CREATE ROLE statement, 63 CREATE SCHEMA statement, 64 CREATE TABLE statement, 66 CREATE TRIGGER statement, 81 CREATE USER statement (Oracle), 65 CREATE VIEW statement, 86 ALTER VIEW statement and, 38 creating databases, 48 functions, 50 indexes, 55 procedures, 60 roles, 63 schemas, 64 tables, 66 triggers, 81 views, 86 cross joins, 135 current session changing time zone for, 153 enabling/disabling roles for, 152 CURRENT_DATE function, 166 CURRENT_TIME function, 166 CURRENT_TIMESTAMP function, 166 CURRENT_USER function, 166 cursors closing open, 44 server-side, 43 opening, 119 ROLLBACK statement and, 129 D data manipulation of ending, 44 speeding with indexes, 55 modifying, controlling characteristics of, 154 updating, 159 data values, database design, 66 database objects operators and, 120 privileges for accessing/using, 105 databases, connecting to within DBMS, 46 creating, 48 dropping objects from, 96 location of (Oracle), 49 naming (Oracle), 49 (see also relational databases) datatypes, 10 MySQL, 14 redefining, 34 Oracle, 15–17 PostgreSQL, 17 SQL Server, 12–14 SQL99, 10–12 vendor-specific, 10–12 dateparts (MySQL), 168 Index Computer Crime: A Crimefighter’s Handbok, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc All rights reserved 207 ,sql_ianIX.fm.14249 Page 208 Wednesday, November 29, 2000 4:45 PM date/time Julian calendar, 14 MySQL dateparts, 168 scalar functions and, 166 dblink statement (Oracle), 40 DBMS connecting to, 46 disconnecting from, 95 DEALLOCATE statement (SQL Server), 44 declarative processing, DECLARE CURSOR statement, 89 CLOSE CURSOR statement and, 43 DEFAULT value, 67 deferred name resolution (SQL Server), 62, 84 defining functions, 55 DELETE privilege (GRANT statement), 105 DELETE statement, 92 CREATE TRIGGER statement and, 81 LIKE operator and, 118 operators and, 120 vs TRUNCATE statement, 158 deleting records, 92 (see also dropping) delimited identifiers, 20, 21 DENY statement (SQL Server), 126 derived tables, 24 derived values, retrieving, 132–151 deterministic/nondeterministic functions, 163 dialects of SQL, Direct SQL Invocation, dirty reads, 155 disabling roles, 152 DISCONNECT statement, 95 CONNECT statement and, 47 distinct values, computing average or sum of, 165 division (/) arithmetic operator, 121 domains (see datatypes) double apostrophe (’ ’), 22 double-pipe mark (||) for concatenation, 46, 170 double-pound sign (##) for declaring global temporary stored procedures, 61 for global temporary tables, 68 double quotation marks (“ ”), 22 DROP DATABASE statement, 96 DROP FUNCTION statement, 97 DROP INDEX statement, 98 DROP PROCEDURE statement, 99 DROP ROLE statement, 99 DROP statements, 96 208 DROP TABLE statement, 100 dropping views with (PostgreSQL), 103 DROP TRIGGER statement, 101 DROP VIEW statement, 102 dropping, 101 databases, 96 functions from databases, 97 indexes, 98 roles, 99 stored procedures, 99 table definitions, 100 views, 102 in PostgreSQL, 103 (see also deleting, records) E Embedded SQL Syntax, enabling/disabling roles, 152 ENCRYPTION option (SQL Server), 88 Enhanced SQL99, supplemental features packages and, Entry-level conformance, equal to (=) comparison operator, 122 equal-asterisk (=*), 135 EXECUTE privilege (GRANT statement), 106 EXECUTE statement used instead of CALL statement (SQL Server), 39 EXISTS logical operator, 123 expressions converting from one datatype to another, 42 operator precedence and, 123 EXTRACT function, 168 F FETCH statement, 103 files, 49 firing triggers, 81 FIRST operation (FETCH statement), 103 foreign languages, translating character sets for, 171 FROM clause, SELECT statement and, 134 full joins, 137 Full-level conformance, functions, 163–193 aggregate, 164–166 alphabetical listings of by vendor, 175–193 defining, 55 deterministic/nondeterministic, 163 dropping from database, 97 invoked by CALL statement (Oracle), 40 operators and, 120 Index Computer Crime: A Crimefighter’s Handbok, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc All rights reserved ,sql_ianIX.fm.14249 Page 209 Wednesday, November 29, 2000 4:45 PM overloading, 55 returning multiple via TABLE datatype (SQL Server), 52 scalar, 166–170 string, 170–175 terminating processing of, 124 types of, 164–175 user-defined, 163 G global temporary tables, 68 GRANT statement, 105 contained in CREATE SCHEMA statement, 65 revoking privileges and, 126 greater than (>) operator, 122 greater than or equal to (>=) operator, 122 GREATEST function (MySQL), 165 GROUP BY clause (SELECT statement), 144 SQL Server, 148 groups, revoking privileges of, 125 guidelines for assigning names, 19 H HAVING clause, 145 aggregate functions and, 166 hierarchical queries, 150 host operating system, function for currently active user, 166 host-DBMS user, 64 I identifiers, 19–21 identity rules, 20 IF-THEN-ELSE functionality provided by CASE function, 40 IN logical operator, 123 indexes ascending creating (PostgreSQL), 59 vs descending (Oracle), 57 BITMAP (Oracle), 57 building upon multiple columns (MySQL), 57 clustered, as defined in Oracle vs SQL Server, 58 creating, 55 dropping, 98 partitioned (Oracle), 58 space required for (SQL Server), 57 spanning several columns, 60 unique (PostgreSQL), 59 INIT.ORA file, 50 inner joins, 136 input parameters altering, 31 for stored procedures (SQL Server), 61 INSENSITIVE option (SQL Server), 90 INSERT privilege (GRANT statement), 105 INSERT statement, 115 CREATE TRIGGER statement and, 81 LIKE operator and, 118 operators and, 120 INSTR function (Oracle), 169 Intermediate-level conformance, International Standards Organization (ISO), interval literals (Oracle), 21 INTO clause (Oracle), 40 ISNULL( ) function (SQL Server), 144 ISO (International Standards Organization), isolation levels, 154 J JOIN clause, 25 SELECT statement and, 135 joins, 25, 135–138 NULL values and, 19 Julian calendar, 14 K keys, keywords, 23 in MySQL, 200 in Oracle, 201 in PostgreSQL, 202 in SQL Server, 199 in SQL99 standard, 197 L language extensions by vendor (lists), 175–193 LAST operation (FETCH statement), 103 LEAST function (MySQL), 165 left (outer) joins, 136 length of a column, 57 LENGTHB function (Oracle), 168 less than () operator, 122 not less than (!

Ngày đăng: 28/06/2014, 15:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan