Djoni Darmawikarta - SQL For MySQL_A Beginner's Tutorial.pdf
(
1043 KB
)
Pobierz
SQL for MySQL
A Beginner’s Tutorial
Djoni Darmawikarta
SQL for MySQL: A Beginner’s Tutorial
Copyright © 2014 Brainy Software Inc.
First Edition: June 2014
All rights reserved. No part of this book may be reproduced or transmitted in any form or
by any means, electronic or mechanical, including photocopying, recording, or by any
information storage and retrieval system, without written permission from the publisher,
except for the inclusion of brief quotations in a review.
ISBN: 978-0-9808396-7-8
Book and Cover Designer: Mona Setiadi
Technical Reviewer: Budi Kurniawan
Indexer: Chris Mayle
Trademarks
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
UNIX is a registered trademark of The Open Group.
Microsoft Internet Explorer is either a registered trademark or a trademark of Microsoft
Corporation in The United States and/or other countries.
Apache is a trademark of The Apache Software Foundation.
Firefox is a registered trademark of the Mozilla Foundation.
Google is a trademark of Google, Inc.
Throughout this book the printing of trademarked names without the trademark symbol is
for editorial purpose only. We have no intention of infringement of the trademark.
Warning and Disclaimer
Every effort has been made to make this book as accurate as possible. The author and the
publisher shall have neither liability nor responsibility to any person or entity with respect
to any loss or damages arising from the information in this book.
Table of Contents
Introduction..................................................................................................1
SQL Overview...........................................................................................1
About This Book.......................................................................................2
Code Conventions......................................................................................3
Code Download.........................................................................................3
Chapter 1: Storing and Maintaining Data.................................................5
Creating and Selecting A Default Database..............................................5
Creating a Table.........................................................................................6
Adding Data...............................................................................................7
Updating Data............................................................................................8
Deleting Data...........................................................................................10
Summary..................................................................................................11
Chapter 2: Basic Queries...........................................................................13
The SELECT statement...........................................................................13
Querying All Data...................................................................................13
Selecting Specific Columns.....................................................................14
Selecting Rows with WHERE.................................................................15
Compound Conditions.............................................................................16
Evaluation Precedence and the Use of Parentheses.................................18
The NOT logical operator........................................................................19
The BETWEEN Operator........................................................................20
The IN Operator.......................................................................................20
The LIKE Operator..................................................................................21
Escaping the Wildcard Character............................................................22
Combining the NOT operator..................................................................22
Summary..................................................................................................24
iv
SQL for MySQL: A Beginner's Tutorial
Chapter 3: Full-Text Search......................................................................25
Natural Language Searches.....................................................................25
Boolean Searches.....................................................................................29
Summary..................................................................................................31
Chapter 4: Query Output..........................................................................33
Column Aliases........................................................................................33
Expressions..............................................................................................34
Limiting the Number of Rows.................................................................35
The DISTINCT Keyword........................................................................36
Aggregate Functions................................................................................37
The CASE Expression.............................................................................38
Ordering Output Rows.............................................................................42
Storing Query Output..............................................................................46
Summary..................................................................................................48
Chapter 5: Grouping..................................................................................49
The GROUP BY Clause..........................................................................49
The HAVING Keyword..........................................................................51
Summary..................................................................................................53
Chapter 6: Joins.........................................................................................55
Primary Keys and Foreign Keys..............................................................55
Querying Multiple Tables........................................................................56
Using Table Aliases.................................................................................58
Joining More than Two Tables................................................................59
The Outer Join.........................................................................................62
Self-Joins.................................................................................................64
Multiple Uses of A Table........................................................................65
Natural Joins............................................................................................67
Summary..................................................................................................69
Chapter 7: Subqueries...............................................................................71
Single-Row Subqueries...........................................................................71
Multiple-Row Subqueries........................................................................73
Multiple Nested Subqueries.....................................................................77
Correlated Subqueries..............................................................................78
Summary..................................................................................................79
Chapter 8: Compound Queries.................................................................81
UNION ALL............................................................................................81
UNION....................................................................................................83
Summary..................................................................................................84
Table of Contents
v
Chapter 9: Views........................................................................................85
Creating and Using Views.......................................................................85
Nested Views...........................................................................................89
Managing Views......................................................................................89
Summary..................................................................................................90
Chapter 10: Built-in Functions.................................................................91
Numeric Functions..................................................................................91
Character Functions.................................................................................94
Datetime Functions..................................................................................98
NULL-related functions..........................................................................99
Summary................................................................................................102
Chapter 11: Transactions........................................................................103
Overview...............................................................................................103
SAVEPOINT.........................................................................................104
AutoCommit..........................................................................................105
Summary................................................................................................106
Chapter 12: Stored Routines...................................................................107
Row-by-row Processing........................................................................107
If-Then-Else Decision Logic.................................................................110
Exception Handling...............................................................................112
User-defined Functions..........................................................................112
Transactions...........................................................................................113
Summary................................................................................................114
Chapter 13: The Data Dictionary...........................................................115
The Schemata Table..............................................................................115
The Tables Table...................................................................................116
The Columns Table...............................................................................117
The Routines Table................................................................................118
Summary................................................................................................118
Appendix A: Installing MySQL Community Edition...........................119
Downloading MySQL Community Edition..........................................119
Installing MySQL Community Edition.................................................120
Appendix B: MySQL Built-in Data Types.............................................127
Appendix C: Indexes................................................................................129
Creating an Index...................................................................................129
Multi-Column Indexes...........................................................................130
Unique Indexes......................................................................................130
Plik z chomika:
jonedave3
Inne pliki z tego folderu:
D&D 4th Edition - Player's Handbook 3.pdf
(54995 KB)
D'Amato_The.Savage.Garden.Revised.epub
(35045 KB)
D is for Derby - Helen L. Wilbur.pdf
(11267 KB)
D-Day_ Battle on the Beach.epub
(28924 KB)
D-Day - Lance Goddard.epub
(14284 KB)
Inne foldery tego chomika:
@other-lang
@packed
0
1
2-1
Zgłoś jeśli
naruszono regulamin