SQL
MySQL
MySQL is a fast, easy-to-use RDBMS being used for many small and big businesses. MySQL is developed,
marketed and supported by MySQL AB, which is a Swedish company. MySQL is becoming so popular
because of many good reasons −
•MySQL is released under an open-source license. So, you have nothing to pay to use it.
•MySQL is a very powerful program in its own right. It handles a large subset of the functionality of the most
expensive and powerful database packages.
•MySQL uses a standard form of the well-known SQL data language.
•MySQL works on many operating systems and with many languages including PHP, PERL, C, C++, JAVA,
etc.
•MySQL works very quickly and works well even with large data sets.
•MySQL is very friendly to PHP, the most appreciated language for web development.
•MySQL supports large databases, up to 50 million rows or more in a table. The default file size limit for a
table is 4GB, but you can increase this (if your operating system can handle it) to a theoretical limit of 8 million
terabytes (TB).
•MySQL is customizable. The open-source GPL license allows programmers to modify the MySQL software to
fit their own specific environments.
Structured Query Language (SQL)
SQL is the core of a relational database which is used for accessing and managing the
database. By using SQL, you can add, update or delete rows of data, retrieve subsets of
information, modify databases and perform many actions. The different subsets of SQL
are as follows:
•DDL (Data Definition Language) – It allows you to perform various operations on the
database such as CREATE, ALTER and DELETE objects.
•DML (Data Manipulation Language) – It allows you to access and manipulate data. It
helps you to insert, update, delete and retrieve data from the database.
•DCL (Data Control Language) – It allows you to control access to the database.
Example – Grant or Revoke access permissions.
•TCL (Transaction Control Language) – It allows you to deal with the transaction of the
database. Example – Commit, Rollback, Savepoint, Set Transaction.
What is MySQL & its Features
MySQL is an open-source relational database management system that works on many platforms. It
provides multi-user access to support many storage engines and is backed by Oracle. So, you can buy a
commercial license version from Oracle to get premium support services.
The features of MySQL are as follows:
•Ease of Management – The software very easily gets downloaded and also uses an event
scheduler to schedule the tasks automatically.
•Robust Transactional Support – Holds the ACID (Atomicity, Consistency, Isolation,
Durability) property, and also allows distributed multi-version support.
•Comprehensive Application Development – MySQL has plugin libraries to embed the
database into any application. It also supports stored procedures, triggers, functions, views
and many more for application development.
•High Performance – Provides fast load utilities with distinct memory caches and table
index partitioning.
•Low Total Cost Of Ownership – This reduces licensing costs and hardware expenditures.
•Open Source & 24 * 7 Support – This RDBMS can be used on any platform and offers
24*7 support for open source and enterprise edition.
•Secure Data Protection – MySQL supports powerful mechanisms to ensure that only
authorized users have access to the databases.
•High Availability – MySQL can run high-speed master/slave replication configurations
and it offers cluster servers.
•Scalability & Flexibility – With MySQL you can run deeply embedded applications and
create data warehouses holding a humongous amount of data.
Why SQL or Benefits:
1.Easy to use: As it supports SQL language, users don’t need to be technically expert to
access the database. It can be easily accessed by users with basic SQL knowledge and
experience on other relational databases.
2.Cost Free: Another benefit of using this database is that the user doesn’t have to spend
money to pay the license fee, as it is free of cost and available on the official website for
download.
3.Customizable Code: As it is available as an open-source tool, software developers
have an option to customize the source code as per their own applications and use it. The
source code is freely available to web users. The do’s and don’ts of the software are
defined in GPL i.e. GNU General Public License.
4. Secured: It offers one of the most secured databases in the world and hence used by well-established web
applications like Facebook, Twitter, Instagram, etc. Its various security features like Firewall,
Encryption, and User Authentication are the helping hands in protecting sensitive user information from
intruders.
5. Better Performance: It supports the multi-engine storage feature which facilitates database administrators to
configure the database in a way to balance the workload. Hence, it makes the database flawless in terms of
performance.
6.High Availability: It offers 24*7 hours availability and offers solutions like Master/Slave Replication and
specialized Cluster Servers.
7.Scalability: It offers very good scalability to web applications through MySQL Thread Pool provided by
MySQL Enterprise Edition. A thread pool provides a model that is used for managing threads (or processes),
like the multi-user connections overhead and execution requests, in a hassle freeway.
8.Platform-Friendly: It is a platform friendly database supporting a number of platforms like Microsoft
Windows, Oracle Solaris, AIX, Symbian, Linux, MAC OS, etc.
9.Friendly Interface: It has a user-friendly interface with a lot of self-management features and different
automated processes like configuration and administration related tasks, which allows users to do the job
effectively from Day 1.
Top 7 MySQL GUI Tools
•BeeKeeper Studio
•DBeaver
•DataGrip by JetBrain
•MySQL Workbench
•HeidiSQL
•dbForge Studio for MySQL
•Navicat for MySQL
•SQLyog
• The SQL CREATE DATABASE Statement
CREATE DATABASE databasename;
• The SQL DROP DATABASE Statement
DROP DATABASE databasename;
• Be careful before using this operation because by
deleting an existing database would result in loss of
complete information stored in the database.
When you have multiple databases in your SQL Schema, then before starting your operation, you would need
to select a database where all the operations would be performed.
The SQL USE statement is used to select any existing database in the SQL schema.
Always the database name should be unique within the RDBMS.
The SQL CREATE TABLE statement is used to create a new table.
You can verify if your table has been created successfully
by looking at the message displayed by the SQL server,
otherwise you can use the DESC command as follows −
SQL - DROP or DELETE Table
The SQL DROP TABLE statement is used to remove a table definition and all the data, indexes,
triggers, constraints and permission specifications for that table.
NOTE − You should be very careful while using this command because once a table is deleted then
all the information available in that table will also be lost forever.
The basic syntax of this DROP TABLE statement is as follows −
DROP TABLE CUSTOMERS;
Now, if you would try the DESC command, then you will
get the following error −
SQL - INSERT Query
The SQL INSERT INTO Statement is used to add new
rows of data to a table in the database.
There are two basic syntaxes of the INSERT INTO
statement which are shown below.
You may not need to specify the column(s) name in the
SQL query if you are adding values for all the columns of
the table. But make sure the order of the values is in the
same order as the columns in the table.
You can create a record in the CUSTOMERS table by using the second syntax as shown below.
Populate one table using another table
You can populate the data into a table through the select statement over another table; provided the other
table has a set of fields, which are required to populate the first table.
SQL - SELECT Query
The SQL SELECT statement is used to fetch the data from a database table which returns this data in the
form of a result table. These result tables are called result-sets.
If you want to fetch all the fields available in the field, then
you can use the following syntax.
SELECT * FROM table_name;
Select * from Customers;
SQL> SELECT ID, NAME, SALARY FROM CUSTOMERS;
SQL - WHERE Clause
The SQL WHERE clause is used to specify a condition
while fetching the data from a single table or by joining
with multiple tables. If the given condition is satisfied, then
only it returns a specific value from the table. You should
use the WHERE clause to filter the records and fetching
only the necessary records.
The WHERE clause is not only used in the SELECT
statement, but it is also used in the UPDATE, DELETE
statement, etc., which we would examine in the
subsequent chapters.
SELECT column1, column2, columnN FROM table_name WHERE [condition]
• The following code is an
example which would fetch
the ID, Name and Salary
fields from the CUSTOMERS
table, where the salary is
greater than 2000 −
• Here, it is important to note that all the strings should be
given inside single quotes (''). Whereas numeric values
should be given without any quote as in the above
example.
• SQL - AND and OR Conjunctive
Operators
• The AND Operator
• The AND operator allows the
existence of multiple conditions in
an SQL statement's WHERE clause
• Following is an example, which would fetch the ID, Name
and Salary fields from the CUSTOMERS table, where the
salary is greater than 2000 and the age is less than 25 years
−
SQL - UPDATE Query
The SQL UPDATE Query is used to modify the existing
records in a table. You can use the WHERE clause with
the UPDATE query to update the selected rows, otherwise
all the rows would be affected.
SQL - DELETE Query
The SQL DELETE Query is used to delete the existing records from a table.
You can use the WHERE clause with a DELETE query to delete the selected rows, otherwise all the records
would be deleted.
SQL - LIKE Clause
The SQL LIKE clause is used to compare a value to similar values using wildcard operators. There are
two wildcards used in conjunction with the LIKE operator.
•The percent sign (%)
•The underscore (_)
The percent sign represents zero, one or multiple characters. The underscore represents a single
number or character. These symbols can be used in combinations.
SQL - ORDER BY Clause
• The SQL ORDER BY clause is used
to sort the data in ascending or
descending order, based on one or
more columns. Some databases sort
the query results in an ascending
order by default.
SQL ALTER TABLE Statement
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
The ALTER TABLE statement is also used to add and drop various constraints on an existing table.
ALTER TABLE - ADD Column
SQL Constraints
SQL constraints are used to specify rules for data in a table.
NOT Null Constraint
SQL - Group By
The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical
data into groups. This GROUP BY clause follows the WHERE clause in a SELECT statement and
precedes the ORDER BY clause.
SQL - Distinct Keyword
The SQL DISTINCT keyword is used in conjunction with the SELECT statement to eliminate all the
duplicate records and fetching only unique records.
There may be a situation when you have multiple duplicate records in a table. While fetching such records,
it makes more sense to fetch only those unique records instead of fetching duplicate records.
SQL - Using Joins
The SQL Joins clause is used to combine records from two or more tables in a database. A JOIN is a
means for combining fields from two tables by using values common to each.
SQL - UNIONS CLAUSE
• The SQL UNION clause/operator is used
to combine the results of two or more
SELECT statements without returning any
duplicate rows.
• To use this UNION clause, each SELECT
statement must have
• The same number of columns selected
• The same number of column expressions
• The same data type and
• Have them in the same order
• But they need not have to be in the
same length.
• The UNION ALL operator is used to
combine the results of two SELECT
statements including duplicate rows.

SQL PPT.pptx

  • 2.
  • 3.
    MySQL MySQL is afast, easy-to-use RDBMS being used for many small and big businesses. MySQL is developed, marketed and supported by MySQL AB, which is a Swedish company. MySQL is becoming so popular because of many good reasons − •MySQL is released under an open-source license. So, you have nothing to pay to use it. •MySQL is a very powerful program in its own right. It handles a large subset of the functionality of the most expensive and powerful database packages. •MySQL uses a standard form of the well-known SQL data language. •MySQL works on many operating systems and with many languages including PHP, PERL, C, C++, JAVA, etc. •MySQL works very quickly and works well even with large data sets. •MySQL is very friendly to PHP, the most appreciated language for web development. •MySQL supports large databases, up to 50 million rows or more in a table. The default file size limit for a table is 4GB, but you can increase this (if your operating system can handle it) to a theoretical limit of 8 million terabytes (TB). •MySQL is customizable. The open-source GPL license allows programmers to modify the MySQL software to fit their own specific environments.
  • 4.
    Structured Query Language(SQL) SQL is the core of a relational database which is used for accessing and managing the database. By using SQL, you can add, update or delete rows of data, retrieve subsets of information, modify databases and perform many actions. The different subsets of SQL are as follows: •DDL (Data Definition Language) – It allows you to perform various operations on the database such as CREATE, ALTER and DELETE objects. •DML (Data Manipulation Language) – It allows you to access and manipulate data. It helps you to insert, update, delete and retrieve data from the database. •DCL (Data Control Language) – It allows you to control access to the database. Example – Grant or Revoke access permissions. •TCL (Transaction Control Language) – It allows you to deal with the transaction of the database. Example – Commit, Rollback, Savepoint, Set Transaction.
  • 5.
    What is MySQL& its Features MySQL is an open-source relational database management system that works on many platforms. It provides multi-user access to support many storage engines and is backed by Oracle. So, you can buy a commercial license version from Oracle to get premium support services. The features of MySQL are as follows:
  • 6.
    •Ease of Management– The software very easily gets downloaded and also uses an event scheduler to schedule the tasks automatically. •Robust Transactional Support – Holds the ACID (Atomicity, Consistency, Isolation, Durability) property, and also allows distributed multi-version support. •Comprehensive Application Development – MySQL has plugin libraries to embed the database into any application. It also supports stored procedures, triggers, functions, views and many more for application development. •High Performance – Provides fast load utilities with distinct memory caches and table index partitioning. •Low Total Cost Of Ownership – This reduces licensing costs and hardware expenditures. •Open Source & 24 * 7 Support – This RDBMS can be used on any platform and offers 24*7 support for open source and enterprise edition. •Secure Data Protection – MySQL supports powerful mechanisms to ensure that only authorized users have access to the databases. •High Availability – MySQL can run high-speed master/slave replication configurations and it offers cluster servers. •Scalability & Flexibility – With MySQL you can run deeply embedded applications and create data warehouses holding a humongous amount of data.
  • 7.
    Why SQL orBenefits: 1.Easy to use: As it supports SQL language, users don’t need to be technically expert to access the database. It can be easily accessed by users with basic SQL knowledge and experience on other relational databases. 2.Cost Free: Another benefit of using this database is that the user doesn’t have to spend money to pay the license fee, as it is free of cost and available on the official website for download. 3.Customizable Code: As it is available as an open-source tool, software developers have an option to customize the source code as per their own applications and use it. The source code is freely available to web users. The do’s and don’ts of the software are defined in GPL i.e. GNU General Public License.
  • 8.
    4. Secured: Itoffers one of the most secured databases in the world and hence used by well-established web applications like Facebook, Twitter, Instagram, etc. Its various security features like Firewall, Encryption, and User Authentication are the helping hands in protecting sensitive user information from intruders. 5. Better Performance: It supports the multi-engine storage feature which facilitates database administrators to configure the database in a way to balance the workload. Hence, it makes the database flawless in terms of performance. 6.High Availability: It offers 24*7 hours availability and offers solutions like Master/Slave Replication and specialized Cluster Servers. 7.Scalability: It offers very good scalability to web applications through MySQL Thread Pool provided by MySQL Enterprise Edition. A thread pool provides a model that is used for managing threads (or processes), like the multi-user connections overhead and execution requests, in a hassle freeway. 8.Platform-Friendly: It is a platform friendly database supporting a number of platforms like Microsoft Windows, Oracle Solaris, AIX, Symbian, Linux, MAC OS, etc. 9.Friendly Interface: It has a user-friendly interface with a lot of self-management features and different automated processes like configuration and administration related tasks, which allows users to do the job effectively from Day 1.
  • 9.
    Top 7 MySQLGUI Tools •BeeKeeper Studio •DBeaver •DataGrip by JetBrain •MySQL Workbench •HeidiSQL •dbForge Studio for MySQL •Navicat for MySQL •SQLyog
  • 11.
    • The SQLCREATE DATABASE Statement CREATE DATABASE databasename; • The SQL DROP DATABASE Statement DROP DATABASE databasename; • Be careful before using this operation because by deleting an existing database would result in loss of complete information stored in the database.
  • 12.
    When you havemultiple databases in your SQL Schema, then before starting your operation, you would need to select a database where all the operations would be performed. The SQL USE statement is used to select any existing database in the SQL schema. Always the database name should be unique within the RDBMS.
  • 13.
    The SQL CREATETABLE statement is used to create a new table. You can verify if your table has been created successfully by looking at the message displayed by the SQL server, otherwise you can use the DESC command as follows −
  • 14.
    SQL - DROPor DELETE Table The SQL DROP TABLE statement is used to remove a table definition and all the data, indexes, triggers, constraints and permission specifications for that table. NOTE − You should be very careful while using this command because once a table is deleted then all the information available in that table will also be lost forever. The basic syntax of this DROP TABLE statement is as follows − DROP TABLE CUSTOMERS; Now, if you would try the DESC command, then you will get the following error −
  • 15.
    SQL - INSERTQuery The SQL INSERT INTO Statement is used to add new rows of data to a table in the database. There are two basic syntaxes of the INSERT INTO statement which are shown below. You may not need to specify the column(s) name in the SQL query if you are adding values for all the columns of the table. But make sure the order of the values is in the same order as the columns in the table.
  • 17.
    You can createa record in the CUSTOMERS table by using the second syntax as shown below.
  • 18.
    Populate one tableusing another table You can populate the data into a table through the select statement over another table; provided the other table has a set of fields, which are required to populate the first table.
  • 19.
    SQL - SELECTQuery The SQL SELECT statement is used to fetch the data from a database table which returns this data in the form of a result table. These result tables are called result-sets. If you want to fetch all the fields available in the field, then you can use the following syntax. SELECT * FROM table_name; Select * from Customers;
  • 20.
    SQL> SELECT ID,NAME, SALARY FROM CUSTOMERS;
  • 21.
    SQL - WHEREClause The SQL WHERE clause is used to specify a condition while fetching the data from a single table or by joining with multiple tables. If the given condition is satisfied, then only it returns a specific value from the table. You should use the WHERE clause to filter the records and fetching only the necessary records. The WHERE clause is not only used in the SELECT statement, but it is also used in the UPDATE, DELETE statement, etc., which we would examine in the subsequent chapters. SELECT column1, column2, columnN FROM table_name WHERE [condition]
  • 22.
    • The followingcode is an example which would fetch the ID, Name and Salary fields from the CUSTOMERS table, where the salary is greater than 2000 −
  • 23.
    • Here, itis important to note that all the strings should be given inside single quotes (''). Whereas numeric values should be given without any quote as in the above example.
  • 24.
    • SQL -AND and OR Conjunctive Operators • The AND Operator • The AND operator allows the existence of multiple conditions in an SQL statement's WHERE clause
  • 25.
    • Following isan example, which would fetch the ID, Name and Salary fields from the CUSTOMERS table, where the salary is greater than 2000 and the age is less than 25 years −
  • 27.
    SQL - UPDATEQuery The SQL UPDATE Query is used to modify the existing records in a table. You can use the WHERE clause with the UPDATE query to update the selected rows, otherwise all the rows would be affected.
  • 30.
    SQL - DELETEQuery The SQL DELETE Query is used to delete the existing records from a table. You can use the WHERE clause with a DELETE query to delete the selected rows, otherwise all the records would be deleted.
  • 33.
    SQL - LIKEClause The SQL LIKE clause is used to compare a value to similar values using wildcard operators. There are two wildcards used in conjunction with the LIKE operator. •The percent sign (%) •The underscore (_) The percent sign represents zero, one or multiple characters. The underscore represents a single number or character. These symbols can be used in combinations.
  • 36.
    SQL - ORDERBY Clause • The SQL ORDER BY clause is used to sort the data in ascending or descending order, based on one or more columns. Some databases sort the query results in an ascending order by default.
  • 39.
    SQL ALTER TABLEStatement The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. The ALTER TABLE statement is also used to add and drop various constraints on an existing table. ALTER TABLE - ADD Column
  • 45.
    SQL Constraints SQL constraintsare used to specify rules for data in a table.
  • 47.
  • 53.
    SQL - GroupBy The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into groups. This GROUP BY clause follows the WHERE clause in a SELECT statement and precedes the ORDER BY clause.
  • 54.
    SQL - DistinctKeyword The SQL DISTINCT keyword is used in conjunction with the SELECT statement to eliminate all the duplicate records and fetching only unique records. There may be a situation when you have multiple duplicate records in a table. While fetching such records, it makes more sense to fetch only those unique records instead of fetching duplicate records.
  • 55.
    SQL - UsingJoins The SQL Joins clause is used to combine records from two or more tables in a database. A JOIN is a means for combining fields from two tables by using values common to each.
  • 57.
    SQL - UNIONSCLAUSE • The SQL UNION clause/operator is used to combine the results of two or more SELECT statements without returning any duplicate rows. • To use this UNION clause, each SELECT statement must have • The same number of columns selected • The same number of column expressions • The same data type and • Have them in the same order • But they need not have to be in the same length. • The UNION ALL operator is used to combine the results of two SELECT statements including duplicate rows.