SQL in 10 Minutes a Day, Sams Teach Yourself
Häftad, Engelska, 2020
Av Ben Forta
469 kr
Whether you're an application developer, database administrator, web application designer, mobile app developer, or Microsoft Office users, a good working knowledge of SQL is an important part of interacting with databases. And Sams Teach Yourself SQL in 10 Minutes offers the straightforward, practical answers you need to help you do your job.
Expert trainer and popular author Ben Forta teaches you just the parts of SQL you need to know–starting with simple data retrieval and quickly going on to more complex topics including the use of joins, subqueries, stored procedures, cursors, triggers, and table constraints.
You'll learn methodically, systematically, and simply–in short, quick lessons that will each take only 10 minutes or less to complete.
Produktinformation
- Utgivningsdatum2020-08-25
- Mått154 x 228 x 12 mm
- Vikt408 g
- FormatHäftad
- SpråkEngelska
- SerieSams Teach Yourself
- Antal sidor256
- Upplaga5
- FörlagPearson Education
- ISBN9780135182796
Tillhör följande kategorier
Ben Forta is Adobe’s Senior Director of Education Initiatives and has three decades of experience in the computer industry in product development, support, training, and product marketing. He is the author of the best-selling Sams Teach Yourself SQL in 10 Minutes (including spinoff titles on MariaDB, MySQL, SQL Server T-SQL, and Oracle PL/SQL), Learning Regular Expressions, as well as books on Java, Windows, and more. He has extensive experience in database design and development, has implemented databases for several highly successful commercial software programs and websites, and is a frequent lecturer and columnist on application development and Internet technologies. Ben lives in Oak Park, Michigan, with his wife, Marcy, and their children. He welcomes your email at ben@forta.com and invites you to visit his website at http://forta.com.
- Introduction 1Who Is the Teach Yourself SQL Book For? . . . . . . . . . . . . . . . . . . . . . . . . . . 1DBMSs Covered in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Conventions Used in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Understanding SQL 5Database Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5What Is SQL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Try It Yourself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Retrieving Data 13The SELECT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Retrieving Individual Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Retrieving Multiple Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Retrieving All Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Retrieving Distinct Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Limiting Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Using Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Sorting Retrieved Data 25Sorting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Sorting by Multiple Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Sorting by Column Position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28Specifying Sort Direction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 Filtering Data 33Using the WHERE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33The WHERE Clause Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405 Advanced Data Filtering 41Combining WHERE Clauses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41Using the IN Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45Using the NOT Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496 Using Wildcard Filtering 51Using the LIKE Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Tips for Using Wildcards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587 Creating Calculated Fields 59Understanding Calculated Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59Concatenating Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60Performing Mathematical Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . 65Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688 Using Data Manipulation Functions 69Understanding Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69Using Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 789 Summarizing Data 79Using Aggregate Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Aggregates on Distinct Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85Combining Aggregate Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8810 Grouping Data 89Understanding Data Grouping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89Creating Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90Filtering Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91Grouping and Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94SELECT Clause Ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9711 Working with Subqueries 99Understanding Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99Filtering by Subquery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99Using Subqueries as Calculated Fields . . . . . . . . . . . . . . . . . . . . . . . . . . 103Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10612 Joining Tables 107Understanding Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107Creating a Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11613 Creating Advanced Joins 117Using Table Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117Using Different Join Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118Using Joins with Aggregate Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 123Using Joins and Join Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12614 Combining Queries 127Understanding Combined Queries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127Creating Combined Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13415 Inserting Data 135Understanding Data Insertion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135Copying from One Table to Another . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14316 Updating and Deleting Data 145Updating Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145Deleting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147Guidelines for Updating and Deleting Data . . . . . . . . . . . . . . . . . . . . . . . 149Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15017 Creating and Manipulating Tables 151Creating Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151Updating Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155Deleting Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157Renaming Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15918 Using Views 161Understanding Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161Creating Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17019 Working with Stored Procedures 171Understanding Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171Understanding Why to Use Stored Procedures . . . . . . . . . . . . . . . . . . . . . 172Executing Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173Creating Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17820 Managing Transaction Processing 179Understanding Transaction Processing . . . . . . . . . . . . . . . . . . . . . . . . . . 179Controlling Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18521 Using Cursors 187Understanding Cursors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187Working with Cursors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19222 Understanding Advanced SQL Features 193Understanding Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193Understanding Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198Understanding Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200Database Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202A Sample Table Scripts 203B SQL Statement Syntax 209C Using SQL Datatypes 215D SQL Reserved Words 221TOC, 9780135182796, 10/9/19