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

Apress the programmers guide to SQL oct 2003 ISBN 1590592182

763 76 0

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

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

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 763
Dung lượng 3,51 MB

Nội dung

The Programmer's Guide to SQL ISBN:1590592182 by Christian Darie and Karli Watson Apress © 2003 (400 pages) The book covers the latest version of the SQL standard, SQL-99, and includes two complete case studies, showing how to create and query the underlying database for a fully featured web site, and how to implement role-based security in your applications Table of Contents The Programmer's Guide to SQL Introduction Understanding SQL and Relational Chapter 1 Databases Chapter 2 - Retrieving Data with SQL Chapter 3 - Modifying Data Chapter 4 - Summarizing and Grouping Data Performing Calculations and using Chapter 5 Functions Chapter 6 - Combining SQL Queries Chapter 7 - Querying Multiple Tables Chapter 8 - Hiding Complex SQL with Views Chapter 9 - Using Stored Procedures Chapter 10 - Transactions Chapter 11 - Users and Security Chapter 12 - Working with Database Objects Chapter 13 - Triggers Chapter 14 - Case Study: Building a Product Catalog Case Study: Implementing Role-Based Chapter 15 Security Appendix A - Executing SQL Statements Setting up the InstantUniversity Appendix B Database Appendix C - Data Types Index List of Figures List of Tables List of Examples List of Sidebars Back Cover Do you speak SQL? We do, and in this book we provide you with an in-depth yet concise tutorial on using Structured Query Language (SQL), the standard that defines how to create and manipulate databases and the data they store SQL is a simple yet powerful language, and you’ll be amazed at how many things you can do with just a few lines of code We teach you all the basic concepts and provide practical examples relevant to your daily programming tasks Once you’ve mastered the fundamentals, this book will serve you well as a handy reference on SQL usage It covers all the major SQL statements you’re likely to need when programming databases and provides example code for five major database systems: SQL Server, Oracle, DB2, MySQL, and Access In each case, we demonstrate how the database system vendor implements, and often extends, the SQL standard We finish off with two complete, real-world case studies that pull together many of the concepts presented throughout the book We show how to create and query the underlying database for an ecommerce application, as well as how to implement role-based security in your applications Whether you’re just starting out with SQL, working with an unfamiliar database, or in need of a desktop reference, this book will provide you with the help and information you need to build effective database applications About the Authors Christian Darie is an independent IT consultant specializing in Microsoft technologies Having worked with computers since he was a child, he won his first prize at the age of 12 in the first programming contest he ever entered He was actively involved with the former Wrox Press as a technical reviewer and author, having contributed the OOP parts of Visual C# NET: ASP.NET E-Commerce with Visual Basic NET and Visual Studio.NET He has authored MCAD preparation material and various SkillDrill tests, such as C# programming, Microsoft COM+, and DB2 Development Karli Watson is a freelance author and IT specialist with a penchant for multicolored clothing He started out with the intention of becoming a world-famous nanotechnologist, so perhaps one day you might recognize his name as he receives a Nobel Prize For now, though, Karli’s computing interests include all things mobile and everything NET Karli is also a snowboarding enthusiast and wishes he had a cat The Programmer's Guide to SQL CRISTIAN DARIE, KARLI WATSON WITH CHRIS HART, KEVIN HOFFMAN, JULIAN SKINNER Copyright © 2003 by Cristian Darie, Karli Watson with Chris Hart, Kevin Hoffman, Julian Skinner All rights reserved No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher ISBN (pbk): 1-59059-218-2 Printed and bound in the United States of America 10987654321 Trademarked names may appear in this book Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark Technical Reviewers: Cristof Falk, Slavomir Furman, Brad Maiani, Judith M Myerson, Johan Normén, David Schultz Editorial Board: Dan Appleman, Craig Berry, Gary Cornell, Steven Rycroft, Julian Skinner, Martin Streicher, Jim Sumser, Karen Watterson, Gavin Wray, John Zukowski Lead Editor: Tony Davis Assistant Publisher: Grace Wong Project Manager: Darren Murphy Copy Editor: Kim Wimpsett Production Manager: Kari Brooks Production Editor: Kelly Winquist Proofreader: Thistle Hill Publishing Services Compositor: Kinetic Publishing Services, LLC Indexer: John Collin Artist: Kinetic Publishing Services, LLC Cover Designer: Kurt Krames Manufacturing Manager: Tom Debolski Distributed to the book trade in the United States by Springer-Verlag New York, Inc., 175 Fifth Avenue, New York, NY, 10010 and outside the United States by Springer-Verlag GmbH & Co KG, Tiergartenstr 17, 69112 Heidelberg, Germany In the United States: phone 1-800-SPRINGER, email , or visit http://www.springerny.com Outside the United States: fax +49 6221 345229, email , or visit http://www.springer.de For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710 Phone 510-549-5930, fax 510-549-5939, email , or visit http://www.apress.com The information in this book is distributed on an "as is" basis, without warranty Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work The source code for this book is available to readers at http://www.apress.com in the Downloads section About the Authors CRISTIAN DARIE is an independent IT consultant specializing in Microsoft technologies Having worked with computers since he was a child, he won his first prize at the age of 12 in the first programming contest he ever entered He was actively involved with the former Wrox Press as a technical reviewer and author, having contributed the OOP parts of Visual C# NET: A Guide for VB6 Developers and coauthored Beginning ASP.NET E-Commerce with Visual Basic NET and Visual Studio NET He has authored MCAD preparation material and various SkillDrill tests, such as C# Programming, Microsoft COM+, and DB2 Development, which can be taken at http://www.skilldrill.com Cristian is at Politehnica University of Bucharest, studying automatic control and industrial informatics He can be contacted through http://www.ChristianDarie.ro My big thanks go to Dave, Julian, and Chris for being such great people to work with KARLI WATSON is a freelance author and IT specialist with a penchant for multicolored clothing He started out with the intention of becoming a world-famous nanotechnologist, so perhaps one day you might recognize his name as he receives a Nobel Prize For now, though, Karli's computing interests include all things mobile and everything NET Karli is also a snowboarding enthusiast and wishes he had a cat JULIAN SKINNER studied Germanic etymology before joining the former Wrox Press He has consequently spent most of the last four-and-a-half years reading, editing, and writing books about programming, focusing on Microsoft technologies and, in particular, on C# and the NET Framework He contributed many sections and code samples, and often entire chapters, for the books he worked on at Wrox, mostly hiding behind the relative anonymity of an "additional material" credit, but he is credited as a coauthor of, among other titles, Professional ADO.NET CHRIS HART is a developer and author based in Birmingham (in the United Kingdom, not Alabama) Chris spent most of the last four years as a member of the technical editorial team at the former Wrox Press and has been programming on a variety of systems since the age of 10 She spends most of her time working with Microsoft technologies and has been heavily involved with NET since it was first released as an early alpha preview She's currently working for Business Post and is developing NET Compact Framework/SQL CE applications and 2D barcode scanning components in Delphi KEVIN HOFFMAN started programming at the age of 10 when his grandfather gave him a Commodore VIC-20 that he refurbished, and he's been addicted to programming ever since He has worked on everything from writing interfaces for scientific instruments to building e-commerce Web sites to providing second-tier technical support for Unix He got hold of NET when it was first handed out in early pre-beta form and has been coding with it ever since He's currently employed in Houston, Texas, where he creates enterprise applications with the NET Framework for a financial services company Introduction Structured query language (SQL) is the language of the database It's a standard that defines how to manipulate almost every aspect of database, from creating the database and tables themselves to creating, reading, inserting, updating, and deleting data in the database This standard is then implemented and extended differently by each database system vendor The current version of the SQL standard is SQL-99 Most major database platforms now adhere fairly closely to this standard with a couple of exceptions Microsoft Access, for example, has only recently (with Access XP) adopted the SQL-92 standard Previous editions of Access supported only SQL-89 In this book, we'll walk through all the major SQL statements you're likely to need when programming databases We'll highlight differences between the standard and implementations used in five major database systems: SQL Server Oracle DB2 MySQL Access List of Examples Chapter 2: Retrieving Data with SQL JOINING STRINGS (SQL SERVER) JOINING STRINGS (MYSQL) JOINING STRINGS (ORACLE) JOINING STRINGS (DB2) JOINING STRINGS (ACCESS) WHERE CLAUSE COMPARISONS FINDING RECORDS IN A SET PATTERN MATCHING COMPLEX PATTERN MATCHING (ACCESS AND SQL SERVER) REGULAR EXPRESSION MATCHING (MYSQL) Chapter 3: Modifying Data ADDING A SINGLE ROW TO A TABLE ADDING MULTIPLE ROWS TO A TABLE MODIFYING ROW DATA DELETING ROW DATA Chapter 4: Summarizing and Grouping Data COUNTING ROWS SUMMING COLUMNS GETTING COLUMN AVERAGES MAXIMUM AND MINIMUM COLUMN VALUES GROUPING DATA RETRIEVING THE TOP FIVE STUDENTS (SQL SERVER/ACCESS) RETRIEVING THE TOP FIVE STUDENTS (MYSQL) RETRIEVING THE TOP FIVE STUDENTS (DB2) RETRIEVING THE TOP FIVE STUDENTS (ORACLE) Chapter 5: Performing Calculations and using Functions USING EXPRESSIONS ROUNDING UP AND DOWN (SQL SERVER AND DB2) ROUNDING UP AND DOWN (ORACLE) ROUNDING UP AND DOWN (MYSQL) ROUNDING UP AND DOWN (ACCESS) MANIPULATING STRINGS (SQL SERVER) MANIPULATING STRINGS (ORACLE) MANIPULATING STRINGS (DB2) MANIPULATING STRINGS (MYSQL) MANIPULATING STRINGS (ACCESS) DIFFERENCES BETWEEN DATES (SQL SERVER) DIFFERENCES BETWEEN DATES (ORACLE) DIFFERENCES BETWEEN DATES (DB2) DIFFERENCES BETWEEN DATES (MYSQL) DIFFERENCES BETWEEN DATES (ACCESS) CREATING A FUNCTION (SQL SERVER) CREATING A FUNCTION (ORACLE) CREATING A FUNCTION (DB2) CREATING A FUNCTION (MYSQL) Chapter 6: Combining SQL Queries SIMPLE SUBQUERIES USING ALIASES WITH SIMPLE SUBQUERIES USING SET MEMBERSHIP WITH SUBQUERIES USING THE EXISTS OPERATOR USING THE ALL OPERATOR USING THE ANY OPERATOR COMBINING DATA WITH UNION Chapter 7: Querying Multiple Tables TWO TABLE EQUI-JOINS MULTI-TABLE EQUI-JOINS (NOT ACCESS) NESTED MULTI-TABLE EQUI-JOINS (ALL PLATFORMS) NON-EQUI JOINS INNER AND OUTER JOINS Chapter 8: Hiding Complex SQL with Views CREATING A VIEW (SQL SERVER) CREATING A VIEW (ORACLE) CREATING A VIEW (DB2) CHANGING A VIEW DELETING A VIEW Chapter 9: Using Stored Procedures CREATING A SIMPLE STORED PROCEDURE (SQL SERVER) CREATING A SIMPLE STORED PROCEDURE (ORACLE) CREATING A SIMPLE STORED QUERY (ACCESS) USING OUTPUT PARAMETERS (SQL SERVER) USING OUTPUT PARAMETERS (ORACLE) USING OUTPUT PARAMETERS (DB2) CONDITIONAL EXPRESSIONS (SQL SERVER) CONDITIONAL EXPRESSIONS (ORACLE) CONDITIONAL EXPRESSIONS (DB2) USING CURSORS (SQL SERVER) USING CURSORS (ORACLE) USING CURSORS (DB2) RETURNING ROWS (SQL SERVER AND ACCESS) RETURNING ROWS (DB2) RETURNING ROWS (ORACLE) ERROR HANDLING (SQL SERVER) ERROR HANDLING (ORACLE) ERROR HANDLING (DB2) Chapter 10: Transactions SQL SERVER TRANSACTIONS AND SAVEPOINTS SQL SERVER TRANSACTIONS WITH ERROR HANDLING ORACLE TRANSACTIONS AND SAVEPOINTS ORACLE TRANSACTIONS AND EXCEPTION HANDLING DB2 TRANSACTIONS MYSQL TRANSACTIONS Chapter 12: Working with Database Objects USING TEMPORARY TABLES (SQL SERVER) USING TEMPORARY TABLES (ORACLE) USING TEMPORARY TABLES (DB2) USING TEMPORARY TABLES (MYSQL) AUTONUMBERED COLUMNS (SQL SERVER) AUTONUMBERED COLUMNS (ORACLE) AUTONUMBERED COLUMNS (DB2) AUTONUMBERED COLUMNS (MYSQL) AUTONUMBERED COLUMNS (ACCESS) Appendix B: Setting up the InstantUniversity Database TESTING THE DATA 1 TESTING THE DATA 2 List of Sidebars Chapter 9: Using Stored Procedures A Final Note on Stored Procedures ... What it's saying is "Give me only the names of all the courses in the Courses table." In other words, give you all the rows stored in the database but only return the values stored in the CourseName column Any other information stored in the table, such as the number of credits... later, known as SQL- 89 This standard was updated in 1991 to a new version, SQL- 92, and subsequently to another version, SQL- 99 (also referred to as SQL: 1999 and SQL3 ) This book concentrates on this SQL- 99 standard... Locate this book in the online catalog or within the book's category and go to the book's Web page Check to see if there is a Corrections link If there is, click the link to see the posted errata

Ngày đăng: 26/03/2019, 17:09

TỪ KHÓA LIÊN QUAN