SQL Cookbook
How to Quickly Learn Structured Query Language Programming, Server Administration, Computer and Database Management Step-by-Step
[Jake Palmer]
Text Copyright [Jake Palmer]
All rights reserved. No part of this guide may be reproduced in any form without permission in writing from the publisher except in the case of brief quotations embodied in critical articles or reviews.
Legal & Disclaimer
The information contained in this book and its contents is not designed to replace or take the place of any form of medical or professional advice; and is not meant to replace the need for independent medical, financial, legal or other professional advice or services, as may be required. The content and information in this book has been provided for educational and entertainment purposes only.
The content and information contained in this book has been compiled from sources deemed reliable, and it is accurate to the best of the Author's knowledge, information and belief. However, the Author cannot guarantee its accuracy and validity and cannot be held liable for any errors and/or omissions. Further, changes are periodically made to this book as and when needed. Where appropriate and/or necessary, you must consult a professional (including but not limited to your doctor, attorney, financial advisor or such other professional advisor) before using any of the suggested remedies, techniques, or information in this book.
Upon using the contents and information contained in this book, you agree to hold harmless the Author from and against any damages, costs, and expenses, including any legal fees potentially resulting from the application of any of the information provided by this book. This disclaimer applies to any loss, damages or injury caused by the use and application, whether directly or indirectly, of any advice or information presented, whether for breach of contract, tort, negligence, personal injury, criminal intent, or under any other cause of action.
You agree to accept all risks of using the information presented inside this book.
You agree that by continuing to read this book, where appropriate and/or necessary, you shall consult a professional (including but not limited to your doctor, attorney, or financial advisor or such other advisor as needed) before using any of the suggested remedies, techniques, or information in this book.
Table of Contents
Book
Introduction
Anything that stores data records is called a database. It can be a file, CD, hard disk, or any number of storage solutions. From a programming point of view, a database is a methodically structured repository of indexed data information that can be easily accessed by the users for creating, retrieving, updating and deleting information. Data can be stored in many forms. Most applications require a database for storing information.
A database can be of two types: (1) flat database and (2) relational database. As, the name suggests a flat database has a two dimensional structure that has data fields and records stored in one large table. It is not capable of storing complex information, which creates a need for relational databases. A relational database stores data in several tables that are related to each other.
Lets take the example of a school. A school will have to maintain data for several students. To find information for a student, we will first ask the class name. After the class name, we will ask for the first name. However, if there are two children with the same first name, then we will ask for the surname. If there are two children will identical names, we can still discriminate the information related to them based on their student id, parents name, date of birth, siblings in same school, etc. This is all related information. When all of this information is stored on paper, it takes a lot of time to retrieve it. Relational database allow easy access to all of this information.
Lets suppose Alex is not feeling well in school and the teacher wants to call his parents to come and pick him up. In the traditional way of maintaining information on paper, if the teacher loses the file with Alexs moms number, she would not be able to contact her. However, if this information is stored in a database, she just needs to go to the administrator. The administrator will search for Alexs home records and within a matter of seconds, the teacher will have the contact details. This will also free her from the burden of maintaining separate records for each child, allowing her to focus more time on other teaching related activities.
What is SQL?
SQL is a very popular programming language in the world of software development. It allows direct communication with the relational database management system. It acts as a bridge between the application, and the database. If you want to transfer money from your bank to another bank, you log onto the website and fill in the details, then press the Submit button for the work to get processed. Once the button is pressed, the SQL commands (embedded in the application by the developer) are carried out to do the needed tasks. These commands locate your data on the database, and if all the details are correct, the transaction would be carried out.
SQL basics are easy to learn. If you want to learn it for advanced purposes, like setting up relational database management systems, then you will have to learn how these commands can be used to carry out complex functions.
Installing and configuring MySql on your system
If you already have MySql server installed on your server then you can skip this section.
Here, I am going to provide you the steps required to install MySQL 6.0 on Windows computer. I have Windows 8.1. Here is the link to the software https://dev.mysql.com/downloads/mysql/6.0.html . If you are not using Windows then under the heading MySQL Community Server 5.7.19 you will see the Select Operating System: dropbox. Select your Operating system and you will be provided with all the options.
If you are learning on a standalone system and you are a beginner, I would recommend that you install Windows Essentials from https://mysql-essential.en.uptodown.com/windows .
While looking for information on MySql you will come across terms like MySQl community server, MySql installer and MySql essentials. As the name suggests Essentials provides just what is essential without any additional components and ideal to start learning. Both installer and community server have full server features, but the community server is only installed online. For the installer, you have to download the package and then install it offline.
Back to MySql Essential. Once you click the download button, the installer package can be found in the downloads folder by the name of mysql-essential-6.0.0.msi. Follow the steps given below for installing the software.
Double click on the mysql-essential-6.0.0.msi package to start the installation process. You would see a MySQL Server 6.0 Setup Wizard Window. To continue with the installation process click on Next button.
You will now have to select the Setup Type. Setup can be one of three types:
Typical for general use
Complete for installation of all program features
Custom to select which programs you want to install.
You can go ahead with Typical installation. If you want to change the path where the software is installed, you will have to opt for custom installation.
- For this book, I went with custom installation because I wanted to change the path of installation. Click Next.
- The next screen will prompt you to login or create a MySql account. Signing up is not mandatory. You can create an account or click on the Skip Sign-Up radio button and click the Next button.