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

beginning t-sql with microsoft sql server 2005 and 2008

675 772 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 675
Dung lượng 14,18 MB

Nội dung

Beginning T-SQL with Microsoft ® SQL Server ® 2005 and 2008 www.wrox.com $39.99 USA $43.99 CAN Wrox Beginning guides are crafted to make learning programming languages and technologies easier than you think, providing a structured, tutorial format that will guide you through all the techniques involved. Recommended Computer Book Categories Database Management General ISBN: 978-0-470-25703-6 Nearly all business applications read, store, and manipulate data stored in relational databases. If you use Microsoft SQL Server in any way, you need to learn and use T-SQL, Microsoft’s powerful implementation of the ANSI-standard SQL database query language. This book teaches all of the basics of T-SQL as it’s used with SQL Server 2005 and 2008 databases. The authors, leading T-SQL experts, begin with the essentials of SQL Server that are needed to get the most from T-SQL. They then quickly move on to introduce T-SQL itself, including the core elements of data retrieval, SQL functions, aggregation and grouping, and multi-table queries, and they fully explain transaction processing and data manipulation using T-SQL. The authors also show you how to create and manage T-SQL programming objects, including views, functions, and stored procedures. They detail how to optimize T-SQL query performance and design queries for real-world business applications. All of the methods and techniques in this book can be used with both Microsoft SQL Server 2005 and 2008 databases. In addition, the book includes a comprehensive set of reference appendices, including T-SQL command syntax, system variables and functions, system stored procedures, information schema views, and FileStream objects. What you will learn from this book ● How to add, modify, and remove records ● How to query multiple tables ● Ways to use views to modify data ● How to create tools for managing databases using T-SQLT-SQL programming techniques using views, user-defined functions, and stored Enhance Your Knowledge Advance Your Career procedures ● Methods for optimizing query performance ● How to use SQL Server Reporting Services to visualize T-SQL query results Who this book is for This book is for beginning SQL Server developers and administrators who need to learn how to use T-SQL. Basic familiarity with relational databases and a general understanding of basic SQL functions is necessary. T-SQL with Microsoft ® SQL Server ® 2005 and 2008 Turley, Wood Beginning spine=1.344" Updates, source code, and Wrox technical support at www.wrox.com Beginning T-SQL with Microsoft ® SQL Server ® 2005 and 2008 Paul Turley, Dan Wood Wrox Programmer to Programmer TM Wrox Programmer to Programmer TM www.it-ebooks.info ffirs.indd iiffirs.indd ii 10/31/08 6:32:53 PM10/31/08 6:32:53 PM www.it-ebooks.info Beginning T-SQL with Microsoft® SQL Server® 2005 and 2008 Introduction xix Chapter 1: Introducing T-SQL and Data Management Systems 1 Chapter 2: SQL Server Fundamentals 23 Chapter 3: SQL Server Tools 49 Chapter 4: Introducing the T-SQL Language 101 Chapter 5: Data Retrieval 129 Chapter 6: SQL Functions 165 Chapter 7: Aggregation and Grouping 219 Chapter 8: Multi-Table Queries 245 Chapter 9: Advanced Queries and Scripting 273 Chapter 10: Transactions 297 Chapter 11: Advanced Capabilities 329 Chapter 12: T-SQL Programming Objects 355 Chapter 13: Creating and Managing Database Objects 409 Chapter 14: Analyzing and Optimizing Query Performance 443 Chapter 15: T-SQL in Applications and Reporting 477 Appendix A: Command Syntax Reference 527 Appendix B: System Variables and Functions Reference 549 Appendix C: System Stored Procedure Reference 573 Appendix D: Information Schema Views Reference 595 Appendix E: FileStream Objects and Syntax 609 Appendix F: Answers to Exercises 613 Index 625 ffirs.indd iffirs.indd i 10/31/08 6:32:52 PM10/31/08 6:32:52 PM www.it-ebooks.info ffirs.indd iiffirs.indd ii 10/31/08 6:32:53 PM10/31/08 6:32:53 PM www.it-ebooks.info Beginning T-SQL with Microsoft® SQL Server® 2005 and 2008 Paul Turley and Dan Wood Wiley Publishing, Inc. ffirs.indd iiiffirs.indd iii 10/31/08 6:32:53 PM10/31/08 6:32:53 PM www.it-ebooks.info Beginning T-SQL with Microsoft® SQL Server® 2005 and 2008 Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-25703-6 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 Library of Congress Cataloging-in-Publication Data is available from the publisher. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Website is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Website may provide or recommendations it may make. Further, readers should be aware that Internet Websites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Microsoft and SQL Server are registered trademarks of Microsoft Corporation in the United States and/or other countries. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. ffirs.indd ivffirs.indd iv 10/31/08 6:32:53 PM10/31/08 6:32:53 PM www.it-ebooks.info My wife, Sherri, is the reason I do anything meaningful in my life. The rest of it I pretty much come up with on my own. Thank you for your love, support and the occasional knock upside the head. —Paul Turley For my wonderful wife, Sarah: Without your constant love and support, I could accomplish nothing. You are truly my best friend. —Dan Wood ffirs.indd vffirs.indd v 10/31/08 6:32:53 PM10/31/08 6:32:53 PM www.it-ebooks.info V413HAV About the Authors Paul Turley (Vancouver, WA) is a Manager of Specialized Services for Hitachi Consulting Education Services. Paul manages the Business Intelligence training team and teaches classes for companies throughout the world on Microsoft SQL Server technologies. He works with companies to architect and build BI and reporting solutions. He has been developing business database solutions since 1991 for companies like Microsoft, Disney, Nike, and Hewlett - Packard. He has been a Microsoft Certified Trainer since 1996 and holds several industry certifications, including MCTS and MCITP for BI, MCSD, MCDBA, MSF Practitioner, and IT Project+. Paul has authored and co - authored several books and courses on database, business intelligence, and application development technologies. He is the lead courseware developer for the Hitachi Consulting courses: SQL Server 2008 Business Intelligence Solutions and SQL Server 2008 Reporting Services Solutions. Books include the prior edition of this book, the 2008, 2005 and 2000 editions of Professional SQL Server Reporting Services , Beginning SQL Server 2005 Administration , Beginning Access 2002 VBA , Data Warehousing with SQL Server 2000 Analysis Services , and Professional Access 2000 Programming — all from Wrox. He is also a contributing author for SQL Server 2005 Integration Services Step by Step from Microsoft Press. Dan Wood (Silverdale, WA) is the senior database administrator for Avalara, a sales tax compliance company, where he both administers and develops database solutions for several enterprise applications that handle global address validation, tax rate calculation, and sales tax remittance for e - commerce and ERP clients. He has been working with SQL Server as a DBA, consultant, and trainer since 1999. Dan was a contributing author on Beginning Transact - SQL with SQL Server 2000 and 2005 and the lead author of Beginning SQL Server Administration , both from Wrox. ffirs.indd viffirs.indd vi 10/31/08 6:32:54 PM10/31/08 6:32:54 PM www.it-ebooks.info Executive Editor Robert Elliott Development Editor John Sleeva Technical Editor David Norton Production Editor Daniel Scribner Copy Editor Nancy Rapoport Editorial Manager Mary Beth Wakefield Production Manager Tim Tate Vice President and Executive Group Publisher Richard Swadley Vice President and Executive Publisher Joseph B. Wikert Project Coordinator, Cover Lynsey Stanford Proofreader Publication Services , Inc. Indexer Robert Swanson Credits ffirs.indd viiffirs.indd vii 10/31/08 6:32:54 PM10/31/08 6:32:54 PM www.it-ebooks.info Acknowledgments This book wouldn ’ t exist without the hard work and dedication of my coauthor, Dan Wood. Dan ’ s a good friend, a true professional, a great father and husband - and I hear he ’ s an okay football coach. Thanks to Bob Elliot and John Sleeva at Wrox who have been incredibly patient and professional with two completely over - committed authors for the past year. DJ Norton did a great job with the technical review. Thanks, DJ, for breaking my code and making more work for me. Thanks to Lance Baldwin and Drew Naukam on Hitachi Consulting ’ s Microsoft Strategic Alliance team for giving me the space to complete this and the Reporting Services book this year. To all of the amazing people I work with at Hitachi Consulting, thanks for making this such a terrific organization for our clients and a great place to call home. — Paul Turley I ’ d like to thank Paul Turley, who is not only a great friend, but an amazing person, and I appreciate the opportunity to work with him again. Many thanks to our Wrox development editor, John Sleeva, who did an outstanding editing job — not to mention the job he did working with us, which was probably very much like herding cats. Special thanks go to the awesome development team at Avalara for a rewarding and stimulating work environment and for giving me inspiration for many of the examples in this book. Most important, I would like to thank my wonderful wife, Sarah, for all her patience and support as I disappeared for hours at a time and spent many a late night trying to finish the latest chapter. I would also like to thank my kids, Lukas, Tessa, and Caleb, who think it ’ s cool that Dad is writing a book but would much prefer that I spend time with them. — Dan Wood ffirs.indd viiiffirs.indd viii 10/31/08 6:32:54 PM10/31/08 6:32:54 PM www.it-ebooks.info [...]... Introducing T -SQL and Data Management Systems T -SQL Language 1 1 Programming Language or Query Language? What’s New in SQL Server 2008 Database Management Systems SQL Server as a Relational Database Management System Tables Relationships RDBMS and Data Integrity 2 3 4 5 5 14 17 SQL Server and Other Products Microsoft SQL Server Oracle IBM DB2 Informix Sybase SQLAnywhere Microsoft Access (Jet) MySQL 20 20... DB2 Informix Sybase SQLAnywhere Microsoft Access (Jet) MySQL 20 20 20 21 21 21 21 22 Summary 22 Chapter 2: SQL Server Fundamentals Who Uses SQL Server? SQL Server Editions and Features SQL Server Compact Edition SQL Server Express Edition SQL Server Workgroup Edition SQL Server Standard Edition SQL Server Enterprise Edition Relational Database Engine Semantics 23 23 25 25 25 26 26 26 27 27 Changing Terminology... are already comfortable with the concepts of relational databases and Microsoft s implementation, you might want to skip ahead to Chapter 2, SQL Server Fundamentals,” or Chapter 3, SQL Server Tools.” Both of these chapters introduce the features and tools in SQL Server 2005 and 2008 and discuss how they are used to write T -SQL T - SQL Language I have mentioned to my colleagues and anyone else who might... also use Windows 2000 Server, Windows Server 2003, or Windows Server 2008 with the Enterprise or Standard edition The SQL Server client tools must be installed on your desktop computer and the SQL Server relational database server must be installed on either your desktop computer or on a remote server with network connectivity and permission to access Consult www .microsoft. com /sql for information about... background in radio sales and marketing, he came up with a cool tagline about SQL Server and the NET Framework that said SQL Server and NET — Kiss T -SQL Goodbye.” He was quickly dissuaded by his team when presented with the facts However, Todd wasn’t completely wrong What his catchy tagline could have said and been accurate was SQL Server and NET — Kiss Inefficient, CPU-Hogging T -SQL Code Goodbye.” Two... Query Language programming with SQL Server 2005 and 2008 Transact -SQL, or T -SQL, is Microsoft Corporation’s powerful implementation of the ANSI standard SQL database query language, which was designed to retrieve, manipulate, and add data to relational database management systems (RDBMS) You may already have a basic idea of what SQL is used for, but you may not have a good understanding of the concepts... introduction of LINQ in SQL Server 2008 and CLR integration in SQL Server 2005, is T -SQL on its death bed? No, not really Reports of T -SQL s demise are premature and highly exaggerated The ability to create database programming objects in managed code instead of SQL does not mean that T -SQL is in danger of becoming extinct Likewise, the ability to create set-oriented queries in C# and VB does not sound... for specific topics We start with an introduction to the T -SQL language and data management systems, and then continue with the SQL Server product fundamentals This first section teaches the essentials of the SQL Server product architecture and relational database design principles This section (Chapters 1–3) concludes with an introduction to the SQL Server administrator and developer tools The next... release and the changes to the product since the release of SQL Server 2000 were myriad and significant Several books and hundreds of websites were published that were devoted to the topic of “What’s New in SQL Server 2005. With the release of SQL Server 2008, however, there is much less buzz and not such a dramatic change to the platform However, the changes in the 2008 release are still very exciting and. .. file system commands, and system management commands What You Need to Use This Book The material in this book applies to all editions of Microsoft SQL Server 2005 and 2008 To use all the features discussed, we recommend that you install the Developer Edition, although you can also use the Enterprise, Standard, or Workgroup editions SQL Server 2005 Developer Edition or SQL Server 2008 Developer Edition . PM www.it-ebooks.info Beginning T -SQL with Microsoft SQL Server 2005 and 2008 Introduction xix Chapter 1: Introducing T -SQL and Data Management Systems 1 Chapter 2: SQL Server Fundamentals 23 Chapter 3: SQL Server. basics of T -SQL as it’s used with SQL Server 2005 and 2008 databases. The authors, leading T -SQL experts, begin with the essentials of SQL Server that are needed to get the most from T -SQL. They. with SQL Server as a DBA, consultant, and trainer since 1999. Dan was a contributing author on Beginning Transact - SQL with SQL Server 2000 and 2005 and the lead author of Beginning SQL Server

Ngày đăng: 05/05/2014, 13:09

TỪ KHÓA LIÊN QUAN

w