Microsoft SQL ServerTSQL Fundamentals_第1页
Microsoft SQL ServerTSQL Fundamentals_第2页
Microsoft SQL ServerTSQL Fundamentals_第3页
Microsoft SQL ServerTSQL Fundamentals_第4页
Microsoft SQL ServerTSQL Fundamentals_第5页
已阅读5页,还剩342页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、microsoft sql server 2008t-sql fundamentalstable of contents1. cover62. copyright63. acknowledgments74. introduction85. chapter 1. background to t-sql querying and programming105.1 theoretical background105.2 sql server architecture175.3 creating tables and defining data integrity215.4 conclusion256

2、. chapter 2. single-table queries266.1 elements of the select statement266.2 predicates and operators486.3 case expressions506.4 nulls526.5 all-at-once operations566.6 working with character data576.7 working with date and time data676.8 querying metadata796.9 conclusion816.10 exercises826.11 soluti

3、ons857. chapter 3. joins887.1 cross joins887.2 inner joins927.3 further join examples947.4 outer joins977.5 conclusion1067.6 exercises1067.7 solutions1118. chapter 4. subqueries1138.1 self-contained subqueries1148.2 correlated subqueries1198.3 beyond the fundamentals of subqueries1228.4 conclusion12

4、88.5 exercises1288.6 solutions1329. chapter 5. table expressions1349.1 derived tables1359.2 common table expressions1399.3 views1449.4 inline table-valued functions1509.5 the apply operator1519.6 conclusion1549.7 exercises1549.8 solutions15910. chapter 6. set operations16110.1 the union set operatio

5、n16210.2 the intersect set operation16410.3 the except set operation16710.4 precedence16910.5 circumventing unsupported logical phases17010.6 conclusion17110.7 exercises17210.8 solutions17511. chapter 7. pivot, unpivot, and grouping sets17711.1 pivoting data17811.2 unpivoting data18311.3 grouping se

6、ts18611.4 conclusion19211.5 exercises19211.6 solutions19412. chapter 8. data modification19712.1 inserting data19712.2 deleting data20512.3 updating data20712.4 merging data21112.5 modifying data through table expressions21512.6 modifications with the top option21712.7 the output clause21812.8 concl

7、usion22412.9 exercises22412.10 solutions22813. chapter 9. transactions and concurrency23013.1 transactions23113.2 locks and blocking23313.3 isolation levels24113.4 deadlocks25313.5 conclusion25513.6 exercises25514. chapter 10. programmable objects26414.1 variables26514.2 batches26714.3 flow elements

8、27014.4 cursors27314.5 temporary tables27614.6 dynamic sql28114.7 routines28614.8 error handling29314.9 conclusion29615. appendix a. getting started29715.1 installing sql server29715.2 downloading source code and installing the sample database30715.3 working with sql server management studio30815.4

9、working with sql server books online31416. itzik ben-gan31717. additional resources for developers from microsoft press31717.1 visual basic31717.2 visual c#31717.3 web development31817.4 data access31817.5 sql server 200531817.6 other developer topics31918. more great developer resources32018.1 deve

10、loper step by step32018.2 developer reference32118.3 focused topics32219. index3233471. covermicrosoft sql server 2008 t-sql fundamentalsby itzik ben-ganpublisher: microsoft presspub date: october 22, 2008print isbn-10: 0-7356-2601-4print isbn-13: 978-0-7356-2601-0pages: 688overview this essential r

11、eference is designed for database developers and administrators who need to write queries and develop code using transact-sql (t-sql), the microsoft implementation of the standard sql language. guided by sql server guru itzik ben-gan, youll walk through the steps for writing queries, including retri

12、eving and modifying data, with an overview of programmable objects supported by sql server 2008. rather than focusing just on the syntactical elements of t-sql, however, this book explains the logic behind the language - helping you develop a true, core understanding of the elements and how to use t

13、hem. you will learn to think in terms of sets, and follow real-world best practices for t-sql programming. to complement the learning experience, the book provides exercises to practice and apply what youve learned. and youll examine recommended solutions to compare with your own work. the entire bo

14、oks code samples will be available for download from the companion web site.2. copyrightpublishedbymicrosoftpressadivisionofmicrosoftcorporationonemicrosoftwayredmond,washington98052-6399copyright 2009 by itzik ben-ganall rights reserved. no part of the contents of this book may be reproduced or tra

15、nsmitted in any form or by any means without the written permission of the publisher.library of congress control number: 2008938209printed and bound in the united states of america.123456789qwt321098distributed in canada by h.b. fenn and company ltd.a cip catalogue record for this book is available

16、from the british library.microsoft press books are available through booksellers and distributors worldwide. for further information about international editions, contact your local microsoft corporation office or contact microsoft press international directly at fax (425) 936-7329. visit our web si

17、te at send comments to mspinput.microsoft, microsoft press, msdn, sql server, and windows are either registered trademarks or trademarks of the microsoft group of companies. other product and company names mentioned herein may be the trademarks of their respective owners.the example companies, organ

18、izations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious. no association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred.this book expresses the auth

19、ors views and opinions. the information contained in this book is provided without any express, statutory, or implied warranties. neither the authors, microsoft corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indir

20、ectly by this book.acquisitionseditor:kenjonesdevelopmentaleditor:sallystickneyprojecteditor:mariagargiuloeditorialproduction:s4carlislepublishingservicestechnicalreviewer:rontalmage;technicalreviewservicesprovidedbycontentmaster,amemberofcmgroup,ltd.cover:tomdraperdesignbody part no. x15-12280dedic

21、ationto datoto live in hearts we leave behind, is not to die.thomas campbell3. acknowledgmentsmany people have contributed to the book, directly and indirectly, and id like to acknowledge their contributions.to ron talmage, the books technical editor: ive asked microsoft press to work with you for a

22、 reason. you seek a true understanding of things; you look for subtleties; you appreciate sql and logic; and on top of all this you have superb english. youve done an outstanding job!to dejan sarka: id like to thank you for your help with the first chapter of the book, and for your insights regardin

23、g set theory, predicate logic, and the relational model. i like the fact that you always question things, even those that most people take for granted. youre one of the people whose thoughts and ideas i heed most. your understanding of the relational model and your capacity for drinking beer are tru

24、ly admirable, albeit that the examples you choose for demonstrating your ideas are not always politically correct. ;-)several people from microsoft press and s4carlisle publishing services are due thanks. to ken jones, the project planner: its a real pleasure working with you. i appreciate your atte

25、ntiveness and the way you manage to handle us authors and our tempers. i also appreciate your friendship. thanks to sally stickney, the development editor, for lifting the project off the ground, and to maria gargiulo, the project editor, for managing the project on a day-to-day basis. it was great

26、to work with you! thanks is also due to christian holdener and tracy ball, the vendor project managers, and to becka mckay, the copy editor.id like to thank my company, solid quality mentors, for the best job i could ever hope for, which mainly involves teaching, and for making me feel like im part

27、of family and friends. fernando g. guerrero, brian moran, and douglas mcdowell, who manage the company: you have a lot to be proud of. the company has grown and matured, and has accomplished great things. to my friends and colleagues from the company, ron talmage, andrew j. kelly, eladio rincn, deja

28、n sarka, herbert albert, fritz lechnitz, gianluca hotz, erik veerman, daniel a. seara, davide mauri, andrea benedetti, miguel egea, adolfo wiernik, javier loria, rushabh b. mehta, and many others: its an honor and pleasure to be part of the gang; i always look forward to spending more time with you

29、over beer talking about sql and other things! id like to thank jeanne reeves for making many of my classes possible, and all the back office team for their support. id also like to thank kathy blomstrom for managing our writing projects and for your excellent edits.to lubor kollar, whos with the mic

30、rosoft sql server customer advisory team (sql cat): id like to thank you for being such a great example, and for your friendship. youre always there to help or to find the right address for help when i have a question about sql server, and this contributed a lot to my t-sql understanding. i always l

31、ook forward to spending time together!id like to thank several people from the product team. to michael wang, michael rys, and all others involved in the development of t-sql: thanks for making t-sql such a great language, notwithstanding the fact that the over clause is not yet fully implemented ;-

32、). to umachandar jayachandran (uc); i know very few people who understand the true depths of t-sql the way you do, and i cant tell you how glad i was when you joined the programmability team. i knew that t-sql was in good hands!to sensei yehuda pantanowitz: you were my greatest teacher, and a friend

33、; your passing away is unbearable.to the team at sql server magazine: megan bearly, sheila molnar, mary waterloo, karen forster, michele crockett, mike otey, lavon peters, and anne grubb: weve been working together for almost 10 years now, and i feel like its my home. thanks for giving me the freedo

34、m to write every month about a subject that is burning in my veins, and for all the work you do to enable the articles to be published.id like to thank my fellow mvps for your contribution to the sql community and to my knowledge. a few deserve special thanks: steve kass, when i grow up, i want to b

35、e just like you! to erland sommarskog, alejandro mesa, aaron bertrand, and tibor karaszi: your participation in the newsgroups is truly astounding! erland, your papers are a great source of information. to marcello poletti (marc): i believe that we share similar feelings towards sql and puzzles; you

36、r puzzles are wicked and they have deprived me of sleep more than once.my true passion is for teaching; id like to thank my students for enabling me to fulfill my passion. student questions and inquiries make me do a lot of research, and a lot of my knowledge today is due to those questions.id like

37、to thank my family for their support. to my parents, gabriel and emilia ben-gan, for supporting me in pursuing my passion, even if it means that we see each other less. and to my brother, michael ben-gan and my sister, ina aviram, for being there for me.finally, lilach, you give meaning to everythin

38、g i do; contrary to the common clich, i probably could finish the book without you. but then, why would i want to?4. introductionthis book walks you through your first steps in t-sql (also known as transact-sql), which is the microsoft sql server dialect of the standard ansi-sql language. youll lear

39、n the theory behind t-sql querying and programming, how to develop t-sql code to query and modify data, and get an overview of programmable objects.although this book is intended for beginners, it is not merely a step-by-step book. it goes beyond the syntactical elements of t-sql and explains the lo

40、gic behind the language and its elements.occasionally the book covers subjects that may be considered advanced for readers who are new to t-sql; therefore, those sections are optional reading. if you already feel comfortable with the material discussed in the book up to that point, you may want to t

41、ackle the more advanced subjects; otherwise, feel free to skip those sections and return to them after youve gained more experience. the text will indicate when a section may be considered more advanced and is provided as optional reading.many aspects of sql are unique to the language, and are very

42、different from other programming languages. this book helps you adopt the right state of mind and gain a true understanding of the language elements. you learn how to think in terms of sets and follow good sql programming practices.the book is not version-specific; it does, however, cover language e

43、lements that were introduced in recent versions of sql server, including sql server 2008. when i discuss language elements that were introduced recently, i specify the version in which they were added.to complement the learning experience, the book provides exercises that enable you to practice what

44、 youve learned. the book occasionally provides optional exercises that are more advanced. those exercises are intended for readers who feel very comfortable with the material and want to challenge themselves with more difficult problems. the optional exercises for advanced readers are labeled as suc

45、h.who this book is forthis book is intended for t-sql programmers, dbas, architects, analysts, and sql server power users who just started working with sql server and need to write queries and develop code using transact-sql.what this book is aboutthe book starts with both a theoretical background t

46、o t-sql querying and programming in chapter 1(see 5.), laying the foundations for the rest of the book, and also coverage of creating tables and defining data integrity. the book moves on to various aspects of querying and modifying data, in chapters 2(see 6.) through 8(see 12.), then to a discussio

47、n of concurrency and transactions in chapter 9(see 13.), and finally provides an overview of programmable objects in chapter 10(see 14.). the following section lists the chapter titles along with a short description:chapter 1(see 5.), background to t-sql querying and programming, provides a theoreti

48、cal background about sql, set theory, and predicate logic; examines the relational model and more; describes sql servers architecture; and explains how to create tables and define data integrity.chapter 2(see 6.), single-table queries, covers various aspects of querying a single table using the sele

49、ct statement.chapter 3(see 7.), joins, covers querying multiple tables using joins, including cross joins, inner joins, and outer joins.chapter 4(see 8.), subqueries, covers queries within queries, otherwise known as subqueries.chapter 5(see 9.), table expressions, covers derived tables, ctes, views

50、, inline table-valued functions, and the apply operator.chapter 6(see 10.), set operations, covers the set operations union, intersect, and except.chapter 7(see 11.), pivot, unpivot, and grouping sets, covers data-rotation techniques and working with grouping sets.chapter 8(see 12.), data modificati

51、on, covers inserting, updating, deleting, and merging data.chapter 9(see 13.), transactions and concurrency, covers concurrency of user connections that work with the same data simultaneously; it covers concepts including transactions, locks, blocking, isolation levels, and deadlocks.chapter 10(see

52、14.), programmable objects, provides an overview to the t-sql programming capabilities in sql server.the book also provides an appendix, getting started(see 15.), to help you set up your environment, download the books source code, install the sample database tsqlfundamentals2008, start writing code

53、 against sql server, and learn how to get help by working with sql server books online.companion contentthis book features a companion web site that makes available to you all the code used in the book, the errata, additional resources, and more. the companion web site is . please refer to appendix

54、a(see 15.), getting started, for details about the source code.hardware and software requirementsin appendix a(see 15.), getting started, i explain which editions of sql server 2008 you can use to work with the code samples included with this book. each edition of sql server may have different hardw

55、are and software requirements, and those requirements are well-documented in sql server books online under hardware and software requirements for installing sql server 2008. appendix a(see 15.) also explains how to work with sql server books online.find additional content onlinefor more great inform

56、ation from microsoft press, visit the new microsoft press online sitesyour one-stop online resource for access to updates, sample chapters, articles, scripts, and e-books related to our industry-leading microsoft press titles. check out the following sites: and support for this bookevery effort has

57、been made to ensure the accuracy of this book and the contents of the companion web site. as corrections or changes are collected, they will be added to a microsoft knowledge base article.microsoft press provides support for books at the following web site:questions and commentsif you have comments, questions, or ideas regarding the book, or questions that are

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论