وبلاگ بلیان

راهنمای گورو برای ترنسکت-اس‌کیوال: [شامل مایکروسافت ترنسکت-اس‌کیوال]

The Guru's guide to Transact-SQL : [covers Microsoft Transact-SQL

معرفی کتاب «راهنمای گورو برای ترنسکت-اس‌کیوال: [شامل مایکروسافت ترنسکت-اس‌کیوال]» (با عنوان لاتین The Guru's guide to Transact-SQL : [covers Microsoft Transact-SQL) نوشتهٔ Henderson, Kenneth، منتشرشده توسط نشر Addison-Wesley Professional در سال 2000. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است.

Since its introduction over a decade ago, the Microsoft SQL Server query language, Transact-SQL, has become increasingly popular and more powerful. The current version sports such advanced features as OLE Automation support, cross-platform querying facilities, and full-text search management. This book is the consummate guide to Microsoft Transact-SQL. From data type nuances to complex statistical computations to the bevy of undocumented features in the language, The Guru's Guide to Transact-SQL imparts the knowledge you need to become a virtuoso of the language as quickly as possible. In this book, you will find the information, explanations, and advice you need to master Transact-SQL and develop the best possible Transact-SQL code. Some 600 code examples not only illustrate important concepts and best practices, but also provide working Transact-SQL code that can be incorporated into your own real-world DBMS applications. Your journey begins with an introduction explaining language fundamentals such as database and table creation, inserting and updating data, queries, joins, data presentation, and managing transactions. Moving on to more advanced topics, the journey continues with in-depth coverage of: Transact-SQL performance tuning using tools such as Query Analyzer and Performance Monitor Nuances of the various T-SQL data types Complex statistical calculations such as medians, modes, and sliding aggregates Run, sequence, and series identification and interrogation Advanced Data Definition Language (DDL) and Data Management Language (DML) techniques Stored procedure and trigger best practices and coding methods Transaction management Optimal cursor use and caveats to look out for Full-text search Hierarchies and arrays Administrative Transact-SQL OLE Automation More than 100 undocumented commands and language features, including numerous unpublished DBCC command verbs, trace flags, stored procedures, and functions Comprehensive, written in understandable terms, and full of practical information and examples, The Guru's Guide to Transact-SQL is an indispensable reference for anyone working with this database development language. The accompanying CD-ROM includes the complete set of code examples found in the book as well as a SQL programming environment that will speed the development of your own top-notch Transact-SQL code. 0201615762B04062001 Cover......Page 1 Contents......Page 6 Foreword......Page 17 Preface......Page 18 On Formality......Page 19 Acknowledgments......Page 20 Chapter 1: Introductory Transact-SQL......Page 22 Choosing a SQL Editor......Page 23 Creating Tables......Page 24 Inserting Data......Page 26 Updating Data......Page 27 Querying Data......Page 28 Column Lists......Page 29 Functions......Page 30 CASE......Page 31 Filtering Data......Page 32 Joins......Page 34 Grouping Data......Page 39 Ordering Data......Page 40 Column Aliases......Page 41 Managing Transactions......Page 42 Summary......Page 43 Dates......Page 44 Y2K and Other Date Problems......Page 45 Date Functions......Page 46 Dates and Simple Arithmetic......Page 47 Determining Time Gaps......Page 48 Building Calendars......Page 52 Strings......Page 55 Char vs. Varchar......Page 56 SET ANSI_PADDING......Page 57 String Functions......Page 58 Xp_sscanf......Page 68 Masks......Page 69 Executing Strings......Page 70 Numerics......Page 75 Floating Point Fun......Page 76 Division by Zero......Page 78 Formatting Numeric Data......Page 79 Caveats......Page 80 Retrieving BLOB Data......Page 81 Updating BLOB Data......Page 84 Bits......Page 87 UNIQUEIDENTIFIER......Page 88 Cursor Variables......Page 89 Timestamps......Page 94 Summary......Page 96 Chapter 3: Missing Values......Page 98 NULL and Functions......Page 99 NULL and ANSI SQL......Page 100 NULL and Stored Procedures......Page 102 NULL If You Must......Page 104 Chapter 4: DDL Insights......Page 106 Foreign Keys......Page 107 Default Constraints......Page 108 Dropping Objects......Page 110 PAD_INDEX......Page 111 Can’t Create Objects in Other Databases......Page 112 Global Temporary Status Tables......Page 113 Object Naming and Dependencies......Page 114 Object Dependencies......Page 115 Summary......Page 116 INSERT......Page 118 DEFAULT and NULL......Page 119 SET IDENTITY_INSERT......Page 120 INSERT...SELECT......Page 121 INSERT...EXEC......Page 122 INSERT and Errors......Page 124 Using INSERT to Remove Duplicate Rows......Page 125 BULK INSERT......Page 126 UPDATE......Page 128 The Halloween Problem......Page 129 UPDATE and CASE......Page 130 Using UPDATE to Check Constraints......Page 131 Limiting the Number of Rows Affected by an UPDATE......Page 132 Swapping Column Values with UPDATE......Page 133 UPDATE and Cursors......Page 134 DELETE......Page 135 DELETE and Cursors......Page 137 TRUNCATE TABLE......Page 138 Summary......Page 139 Simple SELECTs......Page 140 Computational and Derived Fields......Page 141 SELECT TOP......Page 142 Derived Tables......Page 143 Outer Joins and Join Order......Page 147 BETWEEN......Page 149 LIKE......Page 152 EXISTS......Page 154 IN......Page 159 Subqueries......Page 161 Correlated Subqueries......Page 162 Aggregate Functions......Page 168 GROUP BY and HAVING......Page 171 Pivot Tables......Page 173 CUBE and ROLLUP......Page 174 UNION......Page 178 ORDER BY......Page 180 Summary......Page 182 Restrictions......Page 184 DML Restrictions......Page 185 ANSI SQL Schema VIEWs......Page 186 Updatable VIEWs......Page 187 Derived Tables......Page 188 Dynamic VIEWs......Page 189 Partitioning Data Using Views......Page 191 Summary......Page 193 Chapter 8: Statistical Functions......Page 194 The Case for CASE......Page 195 Variance and Standard Deviation......Page 197 The Identity Column Technique......Page 198 The CASE Technique......Page 202 Vector Medians......Page 204 Duplicate Values......Page 205 Clipping......Page 206 Returning the Top n Rows......Page 207 SET ROWCOUNT......Page 209 Rankings......Page 211 Histograms......Page 214 Stratified Histograms......Page 215 Cumulative and Sliding Aggregates......Page 216 Sliding Aggregates......Page 217 Extremes......Page 218 Determining Extreme Attributes......Page 219 Summary......Page 220 Sequences......Page 222 Time Series Fluctuation......Page 223 Regions......Page 224 Regions......Page 228 Intervals......Page 231 Partitioned Intervals......Page 232 Summary......Page 233 Arrays as Big Strings......Page 234 Modifying Array Elements......Page 240 Arrays as Tables......Page 241 Sorting......Page 242 Transposing Dimensions......Page 244 Reshaping the Array......Page 246 Comparing Arrays......Page 247 Summary......Page 249 Chapter 11: Sets......Page 250 Unions......Page 251 Differences......Page 252 Intersections......Page 255 Subsets......Page 256 Returning Every nth Row......Page 259 Summary......Page 260 Simple Hierarchies......Page 262 Multilevel Hierarchies......Page 263 Indenting a Hierarchy......Page 266 Another Approach......Page 267 Listing Leaf Nodes......Page 269 Indented Lists......Page 270 Summary......Page 271 On Cursors and ISAMs......Page 272 Types of Cursors......Page 274 Forward-Only Cursors......Page 275 Dynamic Cursors......Page 276 Static Cursors......Page 277 Keyset Cursors......Page 278 Appropriate Cursor Use......Page 279 Dynamic Queries......Page 280 Row-Oriented Operations......Page 282 T-SQL Cursor Syntax......Page 284 DECLARE CURSOR......Page 285 OPEN......Page 289 FETCH......Page 290 Asynchronous Cursors......Page 293 ANSI/ISO Automatic Cursor Closing......Page 295 Updating Cursors......Page 297 Cursor Variables......Page 298 Optimizing Cursor Performance......Page 300 Summary......Page 302 The ACID Test......Page 304 How SQL Server Transactions Work......Page 305 Automatic Transactions......Page 306 User-Defined Transactions......Page 307 Read-Only and Single-User Databases......Page 308 Automatic Transaction Management......Page 309 READ UNCOMMITTED......Page 310 READ COMMITTED......Page 311 REPEATABLE READ......Page 312 SERIALIZABLE......Page 313 Nested Transactions......Page 314 SAVE TRAN and Save Points......Page 317 Avoid Accidental ROLLBACKs......Page 318 Debugging Transactions......Page 320 Optimizing Transactional Code......Page 321 Summary......Page 322 Chapter 15: Stored Procedures and Triggers......Page 324 Stored Procedure Advantages......Page 325 Compilation......Page 326 Server Execution......Page 327 Creating Stored Procedures......Page 328 Creation Tips......Page 329 System Procedures......Page 333 Extended Procedures......Page 335 Executing Stored Procedures......Page 337 Environmental Concerns......Page 338 Parameters......Page 341 Output Parameters......Page 342 Result Codes......Page 343 Important Automatic Variables......Page 344 Flow Control Language......Page 345 Errors......Page 346 Recursion......Page 349 Triggers......Page 351 Debugging Procedures......Page 355 Summary......Page 356 General Performance Guidelines......Page 358 Database Design Performance Tips......Page 359 Index Performance Tips......Page 361 SELECT Performance Tips......Page 363 Bulk Copy Performance Tips......Page 365 Cursor Performance Tips......Page 367 Stored Procedure Performance Tips......Page 368 SARGs......Page 372 Denormalization......Page 389 Basic Techniques......Page 390 The Query Optimizer......Page 405 Join Optimizations......Page 406 Index Optimizations......Page 408 Data Warehouse Optimizations......Page 410 Predicate Clause Optimizations......Page 412 The Index Tuning Wizard......Page 415 Profiler......Page 417 Perfmon......Page 418 Perfmon-Related DBCC Commands......Page 419 Summary......Page 420 GUI Administration......Page 422 Administrative Automatic Variables......Page 423 Where’s the Beef?......Page 425 Status Routines......Page 426 Catalog Procedures......Page 440 Maintenance Routines......Page 453 Scripting Routines......Page 477 Summary......Page 482 Chapter 18: Full-Text Search......Page 484 Full-Text Predicates......Page 489 The CONTAINS() Predicate......Page 490 Rowset Functions......Page 492 The CONTAINSTABLE() Rowset Function......Page 493 Summary......Page 495 Chapter 19: OLE Automation......Page 496 sp_exporttable......Page 497 sp_importtable......Page 501 sp_getSQLregistry......Page 505 Summary......Page 507 Defining Undocumented......Page 508 DBCC ADDINSTANCE(object,instance)......Page 509 DBCC BUFFER(dbid[,objid][,numberofbuffers][,printopt {0 | 1 | 2}])......Page 510 DBCC CALLFULLTEXT(funcid[,catid][,objid])......Page 511 DBCC DBINFO(dbname)......Page 512 DBCC DBTABLE(dbid)......Page 513 DBCC DROPEXTENDEDPROC(procname)......Page 514 DBCC IND(dbid, objid[,printopt {0 | 1 | 2}])......Page 515 DBCC LOG(dbid)......Page 516 DBCC PAGE (dbid|dbname, filenum, pagenum [,printopt][,cacheopt])......Page 517 DBCC RESOURCE......Page 518 DBCC SETINSTANCE(object,counter,instance,val)......Page 519 GET_SID(username)......Page 520 PWDCOMPARE(str,pwd,oldenc)......Page 521 TSEQUAL(ts1,ts2)......Page 522 Undocumented Trace Flags......Page 523 Undocumented Procedures......Page 524 Summary......Page 530 Status Functions......Page 532 Property Functions......Page 534 Identifier Functions......Page 535 Index Functions......Page 536 Data Functions......Page 539 Unusual String Functions......Page 540 Data Scrubbing......Page 542 Removing Duplicates......Page 545 Iteration Tables......Page 546 Summary......Page 547 Books......Page 548 Internet Resources......Page 549 A......Page 550 B......Page 551 C......Page 552 D......Page 554 F......Page 556 H......Page 558 I......Page 559 M......Page 560 N......Page 561 P......Page 562 Q......Page 563 S......Page 564 T......Page 569 V......Page 571 Z......Page 572 From the Inside Flap: This is a coder's book. It's intended to help developers build applications that make use of Transact-SQL. It's not about database administration or design. It's not about end-user or GUI application development. It's not even about server or database performance tuning. It's about developing the best Transact-SQL code possible, regardless of the application. When I began writing this book, I had these design goals in mind: Be very generous with code samples--don't just tell readers how to do something, show them. Include complete code samples within the chapter texts so that the book can be read through without requiring a computer or CD-ROM. Use modern coding techniques, with specific emphases on ANSI compliance and current version features and enhancements. Construct chapters so that they're self-contained--so that they rely as little as possible on objects created in other chapters. Provide real-world code samples that have intrinsic value apart from the book. Avoid rehashing what's already covered extensively in the SQL Server Books Online. Highlight aspects of Transact-SQL that differentiate it from other SQL dialects; don't just write another ANSI SQL book. Avoid excessive screenshots and other types of filler mechanisms often seen in computer books. Proceed from the simple to the complex within each chapter and throughout the book. Provide an easygoing, relaxed commentary with a de-emphasis on formality. Be the reader's indulgent, amiable tutor. Attempt to communicate in writing the way that people speak. You'll have to judge for yourself whether these goals have been met, but my hope is that, regardless of the degree of success, the effort will at least be evident. About the Sample Databases This book uses SQL Server's Northwind and pubs sample databases extensively. You'll nearly always be able to determine which database a particular example uses from the surrounding commentary or from the code itself. The pubs database is used more often than Northwind, so, when it's not otherwise specified or when in doubt, use pubs. Usually, modifications to these databases are made within transactions so that they can be reversed; however, for safety's sake, you should probably drop and recreate them after each chapter in which they're modified. The scripts to rebuild them (instnwnd.sql and instpubs.sql) can be found in the \Install subdirectory under the root SQL Server folder. Results Abridged If I have a pet peeve about computer books, it's the shameless use of space-filling devices to lengthen them--the dirty little secret of the computer publishing industry. Many technical books these days overflow with gratuitous helpings of screenshots, charts, diagrams, outlines, sidebars, icons, line art, etc. There are people who assign more value to a book that's heavy, and many authors and publishers have been all too happy to accommodate them. They seem to take the old saying that "a picture is worth a thousand words" literally--in some cases turning out books that are little more than picture books. I think there's a point at which comprehensiveness gives way to corpulence, a time when exhaustiveness becomes exhausting. In this book, I've tried to strike a balance between being thorough and being space-efficient. To that end, I've often truncated or clipped query result sets, especially those too wide to fit on a page and those of excessive length (I always point this out). On occasion I also list them using reduced font sizes. I don't include screenshots unless doing so benefits the discussion at hand materially (only one chapter contains any screenshots). This is in keeping with my design goal of being complete without being overwrought. Nearly 600 SQL scripts are used in this book, and they are all included in the chapters that reference them. Hopefully none of the abridgements will detract from the book's overall usefulness or value. On Formality Another of my pet peeves is formality for the sake of formality. An artist once observed that "it's harder to draw a good curved line than a straight one." What he meant was that it's in some ways more difficult to do something well for which there is no exact or stringent standard than to do something that's governed by explicit rules and stuffy precedents. All you have to do to draw a straight line is pick up a straightedge. The rules that govern formal writing, particularly that of the academic variety, make writing certain kinds of books easier because they convert much of the subjective nature of writing into something more objective. They're like training wheels on the would-be author's bicycle. Writing goes from being a creative process to a mechanical one. Cross all the T's, dot all the I's, and you're halfway there. Obviously, this relieves the author of many of the decisions that shape creative writing. It also turns otherwise good pieces of work into dreary, textbook-like dissertations that are about as interesting as the telephone book White Pages. So, I reject the notion that formal writing is better writing, that it is a higher standard and is the ideal for which all technical writers should strive. Instead, I come from the Mark Twain school of thought--I "eschew surplusage"--and I believe that, so long as common methods of speech do not become overly banal (a subjective distinction, I freely admit), the ultimate goal of the technical writer should be to write the way that readers speak. It is the way people--even technical people--are most accustomed to communicating and the way they are the most able to learn and share ideas. I did not invent this way of thinking; it's simply the way most of my favorite authors--Mark Twain, Dean Koontz, Joe Celko, Ernest Hemingway, Robert Heinlein, Andrew Miller, Oscar Wilde, P. J. O'Rourke, Patricia O'Connor--write. Though it is far more difficult to structure and write a narrative that flows naturally and reads easily, it's worth the effort if the ideas the writer seeks to convey are understood as they were intended. So, throughout this book, you'll see a number of the rules and pseudo rules of formal writing stretched, skirted, bent, and sometimes outright broken. This is intentional. Sometimes I split infinitives, begin sentences with conjunctions, and end them with prepositions. Sometimes record is used interchangeably with row; sometimes field takes the place of column; and I never, ever treat data as a plural word. I saw some software recently that displayed a message to the effect "the data are being loaded," and I literally laughed out loud. The distinction between the plural data and its obscure singular form datum is not maintained in spoken language and hasn't really ever been (except, perhaps, in ancient Rome). It has also been deprecated by numerous writing guides and many authors. You will have to look very hard for an author who treats data as a plural word (I can think of only one off the top of my head, the irascible Ted Codd). The tendency for technical communication to become self-important or ostentatious has always baffled me: why stoop to pretension? Why trade the fluid conveyance of ideas between people for nonsense that confuses some and reads like petty one-upmanship to others? Acknowledgments I'd like to thank my wife, who not only makes it possible for me to write books but also makes it worthwhile. The book you see before you is as much hers as it is mine. I'd like to thank Neil Coy, who made a real programmer of me many years ago. Under Neil's tutelage, I learned software craftsmanship from a master. Joe Celko, the dean of the SQL language, has been a good friend and a valuable source of information throughout this project. Kudos to John Sarapata and Thomas Holaday for helping me come up with a title for the book (I'll keep Sybase for Dummies in mind for future use, John). Thanks to the book's technical reviewers, particularly Wayne Snyder, Gianluca Hotz, Paul Olivieri, and Ron Talmage. Heartfelt thanks to John Gmuender, Joe Gallagher, Mike Massing, and Danny Thorpe for their equanimity and for keeping me sane through the recent storm. Congratulations and genuine appreciation to the superb team at Addison-Wesley--Michael Slaughter, Marisa Meltzer, J. Carter Shanklin, and others too numerous to list. Special thanks to Nancy Cara-Sager, a friend, technical reviewer, and copyeditor who's been with me through several books and a couple of publishers now. Her tireless attention to detail has saved me from embarrassing myself more times than I can count. In The Guru's Guide to Transact-SQL , one of the world's leading Microsoft SQL Server 7 developers has written the ideal combination of tutorial and reference, bringing together all the information and skills developers need to create outstanding database applications. KEY TOPICS: Beginners and intermediate developers will appreciate the comprehensive tutorial that walks step-by-step through building a real client/server database, from concept to deployment and beyond -- and points out key pitfalls to avoid throughout the process. Experienced users will appreciate the book's comprehensive coverage of the Transact-SQL language, from basic to advanced level; detailed ODBC database access information; expert coverage of concurrency control, and more. The book includes thorough, up-to-the-minute guidance on building multi-tier applications; SQL Server performance tuning; and other crucial issues for advanced developers. MARKET: For all database developers, system administrators, and Web application developers who interact with databases in Microsoft-centric environments.
دانلود کتاب راهنمای گورو برای ترنسکت-اس‌کیوال: [شامل مایکروسافت ترنسکت-اس‌کیوال]