SlideShare a Scribd company logo
Introduction to MySQL
Presented by:
Amit Kumar Gupta
Flowchart-of-topic
 Database and Database Management System
 Introduction to MySQL
 Connecting and Disconnecting
 Entering Basic Queries
 Creating and Using a Database
Database and Database Management System
Student_id Student_name Branch Year
101 Rms yadav CS 3
102 Shubham Kumar CS 3
103 Sujeet Kumar CS 3
104 Rakesh Kumar ME 3
Database Management System (DBMS) is software to maintain and utilize
the collections of data (Oracle, DB2, MySQL)
MySQL Introduction
 MySQL is a database management system
 SQL stands for the Structured Query Language. It defines
how to insert, retrieve, modify and delete data
 Free from www.mysql.com
 Why are we using MySQL?
 Free (much cheaper than Oracle!)
 Each student can install MySQL locally.
 Easy to use Shell for creating tables, querying tables, etc.
 Easy to use with Java JDBC
Basic MySQL Operations
 Insert records
 Create table
 Load data
 Retrieve records
 Update records
 Delete records
 Modify table
 Join table
 Drop table
 Optimize table
 Count, Like, Order by, Group by
 More advanced ones (sub-queries, stored procedures, triggers, views …)
How MySQL stores data (by default)
 A MySQL server can store several databases
 Databases are stored as directories
 Default is at /usr/local/mysql /var/
 Tables are stored as files inside each database (directory)
 For each table, it has three files:
 table.FRM file containing information about the table structure
 table.MYD file containing the row data
 table.MYI containing any indexes belonging with this table, as well as some
statistics about the table.
Login
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 241 to server version: 3.23.49
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql>
 To exit the MySQL Shell, just type QUIT or EXIT:
mysql> QUIT
mysql> exit
Basic Queries
 Once logged in, you can try some simple queries.
 For example:
mysql> SELECT VERSION(), CURRENT_DATE;
+-----------+--------------+
| VERSION() | CURRENT_DATE |
+-----------+--------------+
| 3.23.49 | 2002-05-26 |
+-----------+--------------+
1 row in set (0.00 sec)
 Note that most MySQL commands end with a semicolon (;)
 MySQL returns the total number of rows found, and the total time to execute the
query.
Create Database
What are the current databases at the server?
mysql> show databases;
+--------------+
| Database |
+--------------+
| mysql | mysql is a database (stores users’ password …) used by system.
| test |
+--------------+
Create a database (make a directory) whose name is MyDB
mysql> create database MyDB;
Select database to use
mysql> use MyDB;
Database changed
What tables are currently stored in the MyDB database?
mysql> show tables;
Empty set (0.00 sec)
Create Table
 CREATE TABLE Table_Name (column_specifications)
 Example
mysql> CREATE TABLE student
-> (
-> Student_id INT UNSIGNED NOT NULL,
-> Student_name VARCHAR(20) NOT NULL,
-> Branch VARCHAR(5),
-> Year VARCHAR(5)
-> );
Query OK, 0 rows affected (0.00 sec)
Student_id Student_name Branch Year
Display Table Structure
mysql> show tables;
+--------------------+
| Tables_in_MyDB |
+--------------------+
| student |
+--------------------+
1 row in set (0.00 sec)
mysql> describe student;
+---------------+----------------------+------+------+----------+--------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------------------+-------+-----+-----------+-------+
| Student_id | int(10) unsigned | | | 0 | |
| Student_name | varchar(20) | | | | |
| Branch | varchar(50) | YES | | NULL | |
| Year | varchar(5) | YES | | NULL | |
+---------------+----------------------+-------+------+----------+-------+
4 rows in set (0.00 sec)
this command use for show table in current database
this this comand use for display table structure in current
database
Insert Record
 INSERT Syntax:-
 INSERT INTO table_name values(column1,column2,column3,…..);
 Example
mysql> INSERT INTO student values( 101, ‘Rms Yadav', ‘CS', ‘3’);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO student values( 102, ‘Shubham Kumar', ‘CS’,
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO student values( 103, ‘Santosh Kumar', ‘CS', ‘3’);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO student values( 104, ‘Rakesh Kumar’, ‘ME', ‘3’);
Query OK, 1 row affected (0.00 sec)
SELECT Statement
 The SELECT statement is used to select data from a database.
 The data returned is stored in a result table, called the result-set.
 SELECT Syntax
SELECT column1, column2, ...
FROM table_name;
 Here, column1, column2, ... are the field names of the table you want to
select data from. If you want to select all the fields available in the table,
 use the following syntax:
 SELECT * FROM table_name;
+---------------+--------------------- +-------+------+----------+--+
| Student_id| Student_name | Branch | Year |
+---------------+----------------------+-------+------+----------+--+
| 101 | Rms Yadav | CS | 3 |
| 102 | Shubham Kumar | CS | 3 |
| 103 | Santosh Kumar | CS | 3 |
| 104 | Rakesh Kumar | ME | 3 |
+---------------+----------------------+-------+------+-----------+---+
Selecting Particular Rows
 You can select only particular rows from your table.
 For example, if you want to verify the change that you made to Bowser's birth date,
select Bowser's record like this:
 For example:-
mysql> SELECT * FROM Student WHERE name = “Rms Yadav";
+---------------+--------------------- +-------+------+----------+--+
| Student_id| Student_name | Branch | Year |
+---------------+----------------------+-------+------+----------+--+
| 101 | Rms Yadav | CS | 3 |
+---------------+----------------------+-------+------+----------+--+
Selecting Particular Rows using Relational operator
 To find all Student record in third Year
SELECT * FROM student WHERE Year >= “3";
+---------------+--------------------- +-------+------+----------+--+
| Student_id| Student_name | Branch | Year |
+---------------+----------------------+-------+------+----------+--+
| 101 | Rms Yadav | CS | 3 |
| 102 | Shubham Kumar | CS | 3 |
| 103 | Santosh Kumar | CS | 3 |
| 104 | Rakesh Kumar | ME | 3 |
+---------------+----------------------+-------+------+-----------+---+
 To find all Student Record, use a logical AND
SELECT * FROM student WHERE Year = ‘3’ AND Branch= “CS";
 To find all Student Record, use a logical OR
SELECT * FROM student WHERE Year = “3" OR Branch=“ME”;
Selecting Particular Columns
 If you don’t want to see entire rows from your table, just name the columns in which you are
interested, separated by commas.
 For example, if you want to know when your pets were born, select the name and birth columns.
 for example:-
mysql> select Student_id, Student_name from student;
D
+---------------+--------------------- +-------+-
| Student_id | Student_name |
+---------------+----------------------+-------+
| 101 | Rms Yadav |
| 102 | Shubham Kumar |
| 103 | Santosh Kumar |
| 104 | Rakesh Kumar |
+---------------+----------------------+-------+--
Group By
 Cluster query results based on different groups
Example:-
mysql> select Branch, count(*) from student GROUP BY Branch;
+---------+----------+
| Branch | count(*)|
+---------+-----------+
| CS | 3 |
| ME | 1 |
+---------+-----------+
Different type of Key
• Super Key
• Candidate Key
• Primary Key
• Alternate key
• Composite/Compound Key
• Unique Key
• Foreign Key
Super Key and Primary Key
 1. Super Key
 Super key can be defined as a set of one or more than one keys that can be used to identify a
record/data uniquely in a table. This key includes only those fields which includes unique value as if we
take an example of Employee than Employee_Id will be the field which includes unique value and it
become easy to identify the employee from Employee_Id field.
 For Example : -Keys which can be the subset of Super Key are Primary key, Unique key and Alternate
key. As right now we don’t know about these keys so further we will discuss these keys.
 2. Primary Key
 Primary key can be defined as a set of one or more fields/columns of a table that uniquely identify a
record in database table. Record can be uniquely identify when the column which includes unique value
like Employee_Id of employee from an organization. It will not accept null values and duplicate values.
Only one primary key can be exist in a single table not more than one.
 For Example:- Suppose a table consist of Employee data with fields Employee_Name,
Employee_Address,Employee_Id and Employee_Designation so in this table only one field is there which
is used to uniquely identify detail of Employee that is Employee_Id.
Unique Key and Alternate Key
 3. Unique Key
 Unique key can be defined as a set of one or more fields/columns of a table that have the capability to
uniquely identify a record in database table. We can have other fields also in a table beyond primary key
which are also able to uniquely identify the record. It can accept only one null value and it can not have
duplicate values in it.
 For Example:-Suppose a table consist of Employee data with fields Employee_Name,
Employee_Address,Employee_Id , Employee_Designation and Employee_PhoneNo so in this table except
Employee_Id we also have an another field named Employee_PhoneNo which is can also be used to
uniquely identify the record and can termed as Unique Key.
 4. Alternate key
 Alternate key can be defined as a key that can be work as a primary key if required. We can also
understand this key as a candidate for primary key as candidate key but right now it is not a primary key.
 For Example:- Suppose a table consist of Employee data with fields Employee_Name,
Employee_Address,Employee_Id , Employee_Designation and Employee_PhoneNo in this case
Employee_PhoneNo can be the alternate key as it is also suitable to identify the record uniquely but right
now it is not primary key.
table like primary key or we can also say that other fields than primary key which can become primary key and a
table can have more than one candidate key. Each candidate key can work as primary key if required in any
case.
 For Example:- Suppose a table consist of Employee data with fields Employee_Name,
Employee_Address,Employee_Id , Employee_Designation.Employee_PANNo and Employee_PhoneNo in this table
Employee_PhoneNo and Employee_PANNo are Candidate Keys as these two fields can also work as candidate key.
 6. Composite/Compound Key
 Composite Key can be defined as a combination of more than one fields/columns of a table to uniquely identify
the record. Fields which can be combine to make composite key can be candidate, primary key.
 For Example:-Suppose a table consist of Employee data with fields Employee_Name,
Employee_Address,Employee_Id , Employee_Designation, Employee_PANNo and Employee_PhoneNo in this table
to build a composite key we combine Employee_Id and Employee_PhoneNo to fetch data from table.
 7. Foreign Key
 Foreign Key can be defined as a field/column in the Company table that is Primary key in Employee table. It can
also accept multiple null values and duplicate values. This can be easily understand with the help of example
given below.
 For Example:- We can have a Employee_Id column in the Company table which is pointing to Employee_Id
column in a Employee table where it a primary key. So with the help of foreign key we can easily identify the
data from tables.
Modify Table Structure
 ALTER TABLE table_name Operations
mysql> alter table student add primary key (Student_id);
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> describe student;
+---------------+--------------------- +-------+------+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------------------+-------+------+----------+-------+
| Student_id | int(10) unsigned | | PRI | 0 | |
| Student_name | varchar(20) | | | | |
| Branch | varchar(7) | YES | | NULL | |
| Year | varchar(5) | YES | | NULL | |
+---------------+----------------------+-------+------+-----------+-------+
4 rows in set (0.00 sec)
Update Record
 UPDATE table_name
SET which columns to change
WHERE condition
 Example
mysql> UPDATE student SET Year=‘4' WHERE Student_name='Shannon';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> SELECT * FROM student WHERE Student_name=‘Shannon’;
+------------+---------------+--------+--------+--------+
| Student_name | student_ID | Branch |Year |
+------------+---------------+--------+--------+--------+
| Rms Yadav | 101 | CS | 4 |
+------------+---------------+--------+--------+--------+
1 row in set (0.00 sec)
Delete Record
 DELETE FROM table_name WHERE condition
 Example
mysql> DELETE FROM student WHERE Student_name=‘Rms Yadav';
Query OK, 1 row affected (0.00 sec)
Mysql> DELETE FROM student;
Will delete ALL student records
Drop Table
 DROP TABLE table_name
 Example
mysql> drop table student;
Query OK, 0 rows affected (0.00 sec)
 Logout MySQL
mysq> quit;
SQL JOIN
OrderID CustomerID OrderDate
10308 2 1996-09-18
10309 37 1996-09-19
10310 77 1996-09-20
A JOIN clause is used to combine rows from two or more tables, based on a related column
between them.
Let's look at a selection from the "Orders" table:
Customer
ID
CustomerName ContactName Country
1 Alfreds Futterkiste Maria Anders Germany
2 Ana Trujillo
Emparedados y
helados
Ana Trujillo Mexico
3 Antonio Moreno
Taquería
Antonio Moreno Mexico
Customer
ID
CustomerName ContactName Country
1 Alfreds Futterkiste Maria Anders Germany
2 Ana Trujillo
Emparedados y
helados
Ana Trujillo Mexico
3 Antonio Moreno
Taquería
Antonio Moreno Mexico
Then, look at a selection from the "Customers" table:
OrderID CustomerName OrderDat
e
10308 Ana Trujillo Emparedados y helados 9/18/199
6
10365 Antonio Moreno Taquería 11/27/19
96
10383 Around the Horn 12/16/19
96
10355 Around the Horn 11/15/19
96
10278 Berglunds snabbköp 8/12/199
6
Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the
"Customers" table. The relationship between the two tables above is the "CustomerID" column.
Then, we can create the following SQL statement (that contains an INNER JOIN), that selects
records that have matching values in both tables:
Example
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers ON Orders.CustomerID= Customers.CustomerID;
Different Types of SQL JOINs
 Different Types of SQL JOINs
 Here are the different types of the JOINs in SQL:
1.(INNER) JOIN: Returns records that have matching values in both tables
SQL LEFT JOIN Keyword
 The LEFT JOIN keyword returns all records from the left table (table1), and the matched
records from the right table (table2). The result is NULL from the right side, if there is no
match.
 LEFT JOIN Syntax
 SELECT column_name(s)
FROM table1
LEFT JOIN table2 ON table1.column_name = table2.column_name;
SQL RIGHT JOIN Keyword
 The RIGHT JOIN keyword returns all records from the right table
(table2), and the matched records from the left table (table1). The
result is NULL from the left side, when there is no match.
 RIGHT JOIN Syntax
 SELECT column_name(s)
FROM table1
RIGHT JOIN table2 ON table1.column_name = table2.column_name;
SQL FULL OUTER JOIN Keyword
 SQL FULL OUTER JOIN Keyword
 The FULL OUTER JOIN keyword return all records when there is a
match in either left (table1) or right (table2) table records.
 Note: FULL OUTER JOIN can potentially return very large result-sets!
Thank You
By Ramashankar Kumar

More Related Content

What's hot

MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorial
Giuseppe Maxia
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in action
Sveta Smirnova
 
My SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTNMy SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTN
Ronald Bradford
 
Mysql basics1
Mysql basics1Mysql basics1
Mysql basics1
Steffy Robert
 
12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing
12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing
12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing
Monowar Mukul
 
Lecture3 mysql gui by okello erick
Lecture3 mysql gui by okello erickLecture3 mysql gui by okello erick
Lecture3 mysql gui by okello erick
okelloerick
 
MySQL for business developer - Titouan BENOIT
MySQL for business developer - Titouan BENOITMySQL for business developer - Titouan BENOIT
MySQL for business developer - Titouan BENOIT
Titouan BENOIT
 
MySQL constraints
MySQL constraintsMySQL constraints
MySQL constraints
Harish Gyanani
 
Performance Schema for MySQL Troubleshooting
 Performance Schema for MySQL Troubleshooting Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
Sveta Smirnova
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
Sveta Smirnova
 
w_dzon05
w_dzon05w_dzon05
w_dzon05
Ora Weinstein
 
Intro to my sql
Intro to my sqlIntro to my sql
Intro to my sql
MusTufa Nullwala
 
Cat database
Cat databaseCat database
Cat database
tubbeles
 
Pro PostgreSQL
Pro PostgreSQLPro PostgreSQL
Pro PostgreSQL
Robert Treat
 
MySQL Query tuning 101
MySQL Query tuning 101MySQL Query tuning 101
MySQL Query tuning 101
Sveta Smirnova
 
Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON?
Sveta Smirnova
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
NIRMAL FELIX
 
DB2 Basic Commands - UDB
DB2 Basic Commands - UDBDB2 Basic Commands - UDB
DB2 Basic Commands - UDB
Srinimf-Slides
 
Scripts related to temp tablespace
Scripts related to temp tablespaceScripts related to temp tablespace
Scripts related to temp tablespace
Soumya Das
 
Empowering Users with Analytical MDX
Empowering Users with Analytical MDXEmpowering Users with Analytical MDX
Empowering Users with Analytical MDX
Alithya
 

What's hot (20)

MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorial
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in action
 
My SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTNMy SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTN
 
Mysql basics1
Mysql basics1Mysql basics1
Mysql basics1
 
12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing
12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing
12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing
 
Lecture3 mysql gui by okello erick
Lecture3 mysql gui by okello erickLecture3 mysql gui by okello erick
Lecture3 mysql gui by okello erick
 
MySQL for business developer - Titouan BENOIT
MySQL for business developer - Titouan BENOITMySQL for business developer - Titouan BENOIT
MySQL for business developer - Titouan BENOIT
 
MySQL constraints
MySQL constraintsMySQL constraints
MySQL constraints
 
Performance Schema for MySQL Troubleshooting
 Performance Schema for MySQL Troubleshooting Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
w_dzon05
w_dzon05w_dzon05
w_dzon05
 
Intro to my sql
Intro to my sqlIntro to my sql
Intro to my sql
 
Cat database
Cat databaseCat database
Cat database
 
Pro PostgreSQL
Pro PostgreSQLPro PostgreSQL
Pro PostgreSQL
 
MySQL Query tuning 101
MySQL Query tuning 101MySQL Query tuning 101
MySQL Query tuning 101
 
Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON?
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
DB2 Basic Commands - UDB
DB2 Basic Commands - UDBDB2 Basic Commands - UDB
DB2 Basic Commands - UDB
 
Scripts related to temp tablespace
Scripts related to temp tablespaceScripts related to temp tablespace
Scripts related to temp tablespace
 
Empowering Users with Analytical MDX
Empowering Users with Analytical MDXEmpowering Users with Analytical MDX
Empowering Users with Analytical MDX
 

Similar to DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018

Advance MySQL Training by Pratyush Majumdar
Advance MySQL Training by Pratyush MajumdarAdvance MySQL Training by Pratyush Majumdar
Advance MySQL Training by Pratyush Majumdar
Pratyush Majumdar
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
webhostingguy
 
My sql1
My sql1My sql1
My sql1
Akash Gupta
 
My sql1
My sql1My sql1
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.ppt
KISHOYIANKISH
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
webhostingguy
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sql
smumbahelp
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sql
smumbahelp
 
Distributed databases systems-3-2015.ppt
Distributed databases systems-3-2015.pptDistributed databases systems-3-2015.ppt
Distributed databases systems-3-2015.ppt
NaglaaAbdelhady
 
Introduction To Lamp P2
Introduction To Lamp P2Introduction To Lamp P2
Introduction To Lamp P2
Amzad Hossain
 
Mysqlfunctions
MysqlfunctionsMysqlfunctions
Mysqlfunctions
N13M
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
Sveta Smirnova
 
MySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queriesMySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queries
Damien Seguy
 
mySQL and Relational Databases
mySQL and Relational DatabasesmySQL and Relational Databases
mySQL and Relational Databases
webhostingguy
 
Introduction databases and MYSQL
Introduction databases and MYSQLIntroduction databases and MYSQL
Introduction databases and MYSQL
Naeem Junejo
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
Mudasir Syed
 
Mysql
MysqlMysql
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
Valeriy Kravchuk
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQL
Georgi Sotirov
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
Raj vardhan
 

Similar to DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018 (20)

Advance MySQL Training by Pratyush Majumdar
Advance MySQL Training by Pratyush MajumdarAdvance MySQL Training by Pratyush Majumdar
Advance MySQL Training by Pratyush Majumdar
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
 
My sql1
My sql1My sql1
My sql1
 
My sql1
My sql1My sql1
My sql1
 
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.ppt
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sql
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sql
 
Distributed databases systems-3-2015.ppt
Distributed databases systems-3-2015.pptDistributed databases systems-3-2015.ppt
Distributed databases systems-3-2015.ppt
 
Introduction To Lamp P2
Introduction To Lamp P2Introduction To Lamp P2
Introduction To Lamp P2
 
Mysqlfunctions
MysqlfunctionsMysqlfunctions
Mysqlfunctions
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
MySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queriesMySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queries
 
mySQL and Relational Databases
mySQL and Relational DatabasesmySQL and Relational Databases
mySQL and Relational Databases
 
Introduction databases and MYSQL
Introduction databases and MYSQLIntroduction databases and MYSQL
Introduction databases and MYSQL
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
 
Mysql
MysqlMysql
Mysql
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQL
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 

DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018

  • 1. Introduction to MySQL Presented by: Amit Kumar Gupta
  • 2. Flowchart-of-topic  Database and Database Management System  Introduction to MySQL  Connecting and Disconnecting  Entering Basic Queries  Creating and Using a Database
  • 3. Database and Database Management System Student_id Student_name Branch Year 101 Rms yadav CS 3 102 Shubham Kumar CS 3 103 Sujeet Kumar CS 3 104 Rakesh Kumar ME 3 Database Management System (DBMS) is software to maintain and utilize the collections of data (Oracle, DB2, MySQL)
  • 4. MySQL Introduction  MySQL is a database management system  SQL stands for the Structured Query Language. It defines how to insert, retrieve, modify and delete data  Free from www.mysql.com  Why are we using MySQL?  Free (much cheaper than Oracle!)  Each student can install MySQL locally.  Easy to use Shell for creating tables, querying tables, etc.  Easy to use with Java JDBC
  • 5. Basic MySQL Operations  Insert records  Create table  Load data  Retrieve records  Update records  Delete records  Modify table  Join table  Drop table  Optimize table  Count, Like, Order by, Group by  More advanced ones (sub-queries, stored procedures, triggers, views …)
  • 6. How MySQL stores data (by default)  A MySQL server can store several databases  Databases are stored as directories  Default is at /usr/local/mysql /var/  Tables are stored as files inside each database (directory)  For each table, it has three files:  table.FRM file containing information about the table structure  table.MYD file containing the row data  table.MYI containing any indexes belonging with this table, as well as some statistics about the table.
  • 7. Login Enter password: ***** Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 241 to server version: 3.23.49 Type 'help;' or 'h' for help. Type 'c' to clear the buffer. mysql>  To exit the MySQL Shell, just type QUIT or EXIT: mysql> QUIT mysql> exit
  • 8. Basic Queries  Once logged in, you can try some simple queries.  For example: mysql> SELECT VERSION(), CURRENT_DATE; +-----------+--------------+ | VERSION() | CURRENT_DATE | +-----------+--------------+ | 3.23.49 | 2002-05-26 | +-----------+--------------+ 1 row in set (0.00 sec)  Note that most MySQL commands end with a semicolon (;)  MySQL returns the total number of rows found, and the total time to execute the query.
  • 9. Create Database What are the current databases at the server? mysql> show databases; +--------------+ | Database | +--------------+ | mysql | mysql is a database (stores users’ password …) used by system. | test | +--------------+ Create a database (make a directory) whose name is MyDB mysql> create database MyDB; Select database to use mysql> use MyDB; Database changed What tables are currently stored in the MyDB database? mysql> show tables; Empty set (0.00 sec)
  • 10. Create Table  CREATE TABLE Table_Name (column_specifications)  Example mysql> CREATE TABLE student -> ( -> Student_id INT UNSIGNED NOT NULL, -> Student_name VARCHAR(20) NOT NULL, -> Branch VARCHAR(5), -> Year VARCHAR(5) -> ); Query OK, 0 rows affected (0.00 sec) Student_id Student_name Branch Year
  • 11. Display Table Structure mysql> show tables; +--------------------+ | Tables_in_MyDB | +--------------------+ | student | +--------------------+ 1 row in set (0.00 sec) mysql> describe student; +---------------+----------------------+------+------+----------+--------+ | Field | Type | Null | Key | Default | Extra | +---------------+----------------------+-------+-----+-----------+-------+ | Student_id | int(10) unsigned | | | 0 | | | Student_name | varchar(20) | | | | | | Branch | varchar(50) | YES | | NULL | | | Year | varchar(5) | YES | | NULL | | +---------------+----------------------+-------+------+----------+-------+ 4 rows in set (0.00 sec) this command use for show table in current database this this comand use for display table structure in current database
  • 12. Insert Record  INSERT Syntax:-  INSERT INTO table_name values(column1,column2,column3,…..);  Example mysql> INSERT INTO student values( 101, ‘Rms Yadav', ‘CS', ‘3’); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO student values( 102, ‘Shubham Kumar', ‘CS’, Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO student values( 103, ‘Santosh Kumar', ‘CS', ‘3’); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO student values( 104, ‘Rakesh Kumar’, ‘ME', ‘3’); Query OK, 1 row affected (0.00 sec)
  • 13. SELECT Statement  The SELECT statement is used to select data from a database.  The data returned is stored in a result table, called the result-set.  SELECT Syntax SELECT column1, column2, ... FROM table_name;  Here, column1, column2, ... are the field names of the table you want to select data from. If you want to select all the fields available in the table,  use the following syntax:  SELECT * FROM table_name; +---------------+--------------------- +-------+------+----------+--+ | Student_id| Student_name | Branch | Year | +---------------+----------------------+-------+------+----------+--+ | 101 | Rms Yadav | CS | 3 | | 102 | Shubham Kumar | CS | 3 | | 103 | Santosh Kumar | CS | 3 | | 104 | Rakesh Kumar | ME | 3 | +---------------+----------------------+-------+------+-----------+---+
  • 14. Selecting Particular Rows  You can select only particular rows from your table.  For example, if you want to verify the change that you made to Bowser's birth date, select Bowser's record like this:  For example:- mysql> SELECT * FROM Student WHERE name = “Rms Yadav"; +---------------+--------------------- +-------+------+----------+--+ | Student_id| Student_name | Branch | Year | +---------------+----------------------+-------+------+----------+--+ | 101 | Rms Yadav | CS | 3 | +---------------+----------------------+-------+------+----------+--+
  • 15. Selecting Particular Rows using Relational operator  To find all Student record in third Year SELECT * FROM student WHERE Year >= “3"; +---------------+--------------------- +-------+------+----------+--+ | Student_id| Student_name | Branch | Year | +---------------+----------------------+-------+------+----------+--+ | 101 | Rms Yadav | CS | 3 | | 102 | Shubham Kumar | CS | 3 | | 103 | Santosh Kumar | CS | 3 | | 104 | Rakesh Kumar | ME | 3 | +---------------+----------------------+-------+------+-----------+---+  To find all Student Record, use a logical AND SELECT * FROM student WHERE Year = ‘3’ AND Branch= “CS";  To find all Student Record, use a logical OR SELECT * FROM student WHERE Year = “3" OR Branch=“ME”;
  • 16. Selecting Particular Columns  If you don’t want to see entire rows from your table, just name the columns in which you are interested, separated by commas.  For example, if you want to know when your pets were born, select the name and birth columns.  for example:- mysql> select Student_id, Student_name from student; D +---------------+--------------------- +-------+- | Student_id | Student_name | +---------------+----------------------+-------+ | 101 | Rms Yadav | | 102 | Shubham Kumar | | 103 | Santosh Kumar | | 104 | Rakesh Kumar | +---------------+----------------------+-------+--
  • 17. Group By  Cluster query results based on different groups Example:- mysql> select Branch, count(*) from student GROUP BY Branch; +---------+----------+ | Branch | count(*)| +---------+-----------+ | CS | 3 | | ME | 1 | +---------+-----------+
  • 18. Different type of Key • Super Key • Candidate Key • Primary Key • Alternate key • Composite/Compound Key • Unique Key • Foreign Key
  • 19. Super Key and Primary Key  1. Super Key  Super key can be defined as a set of one or more than one keys that can be used to identify a record/data uniquely in a table. This key includes only those fields which includes unique value as if we take an example of Employee than Employee_Id will be the field which includes unique value and it become easy to identify the employee from Employee_Id field.  For Example : -Keys which can be the subset of Super Key are Primary key, Unique key and Alternate key. As right now we don’t know about these keys so further we will discuss these keys.  2. Primary Key  Primary key can be defined as a set of one or more fields/columns of a table that uniquely identify a record in database table. Record can be uniquely identify when the column which includes unique value like Employee_Id of employee from an organization. It will not accept null values and duplicate values. Only one primary key can be exist in a single table not more than one.  For Example:- Suppose a table consist of Employee data with fields Employee_Name, Employee_Address,Employee_Id and Employee_Designation so in this table only one field is there which is used to uniquely identify detail of Employee that is Employee_Id.
  • 20. Unique Key and Alternate Key  3. Unique Key  Unique key can be defined as a set of one or more fields/columns of a table that have the capability to uniquely identify a record in database table. We can have other fields also in a table beyond primary key which are also able to uniquely identify the record. It can accept only one null value and it can not have duplicate values in it.  For Example:-Suppose a table consist of Employee data with fields Employee_Name, Employee_Address,Employee_Id , Employee_Designation and Employee_PhoneNo so in this table except Employee_Id we also have an another field named Employee_PhoneNo which is can also be used to uniquely identify the record and can termed as Unique Key.  4. Alternate key  Alternate key can be defined as a key that can be work as a primary key if required. We can also understand this key as a candidate for primary key as candidate key but right now it is not a primary key.  For Example:- Suppose a table consist of Employee data with fields Employee_Name, Employee_Address,Employee_Id , Employee_Designation and Employee_PhoneNo in this case Employee_PhoneNo can be the alternate key as it is also suitable to identify the record uniquely but right now it is not primary key.
  • 21. table like primary key or we can also say that other fields than primary key which can become primary key and a table can have more than one candidate key. Each candidate key can work as primary key if required in any case.  For Example:- Suppose a table consist of Employee data with fields Employee_Name, Employee_Address,Employee_Id , Employee_Designation.Employee_PANNo and Employee_PhoneNo in this table Employee_PhoneNo and Employee_PANNo are Candidate Keys as these two fields can also work as candidate key.  6. Composite/Compound Key  Composite Key can be defined as a combination of more than one fields/columns of a table to uniquely identify the record. Fields which can be combine to make composite key can be candidate, primary key.  For Example:-Suppose a table consist of Employee data with fields Employee_Name, Employee_Address,Employee_Id , Employee_Designation, Employee_PANNo and Employee_PhoneNo in this table to build a composite key we combine Employee_Id and Employee_PhoneNo to fetch data from table.  7. Foreign Key  Foreign Key can be defined as a field/column in the Company table that is Primary key in Employee table. It can also accept multiple null values and duplicate values. This can be easily understand with the help of example given below.  For Example:- We can have a Employee_Id column in the Company table which is pointing to Employee_Id column in a Employee table where it a primary key. So with the help of foreign key we can easily identify the data from tables.
  • 22. Modify Table Structure  ALTER TABLE table_name Operations mysql> alter table student add primary key (Student_id); Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe student; +---------------+--------------------- +-------+------+----------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+----------------------+-------+------+----------+-------+ | Student_id | int(10) unsigned | | PRI | 0 | | | Student_name | varchar(20) | | | | | | Branch | varchar(7) | YES | | NULL | | | Year | varchar(5) | YES | | NULL | | +---------------+----------------------+-------+------+-----------+-------+ 4 rows in set (0.00 sec)
  • 23. Update Record  UPDATE table_name SET which columns to change WHERE condition  Example mysql> UPDATE student SET Year=‘4' WHERE Student_name='Shannon'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT * FROM student WHERE Student_name=‘Shannon’; +------------+---------------+--------+--------+--------+ | Student_name | student_ID | Branch |Year | +------------+---------------+--------+--------+--------+ | Rms Yadav | 101 | CS | 4 | +------------+---------------+--------+--------+--------+ 1 row in set (0.00 sec)
  • 24. Delete Record  DELETE FROM table_name WHERE condition  Example mysql> DELETE FROM student WHERE Student_name=‘Rms Yadav'; Query OK, 1 row affected (0.00 sec) Mysql> DELETE FROM student; Will delete ALL student records
  • 25. Drop Table  DROP TABLE table_name  Example mysql> drop table student; Query OK, 0 rows affected (0.00 sec)  Logout MySQL mysq> quit;
  • 26. SQL JOIN OrderID CustomerID OrderDate 10308 2 1996-09-18 10309 37 1996-09-19 10310 77 1996-09-20 A JOIN clause is used to combine rows from two or more tables, based on a related column between them. Let's look at a selection from the "Orders" table:
  • 27. Customer ID CustomerName ContactName Country 1 Alfreds Futterkiste Maria Anders Germany 2 Ana Trujillo Emparedados y helados Ana Trujillo Mexico 3 Antonio Moreno Taquería Antonio Moreno Mexico Customer ID CustomerName ContactName Country 1 Alfreds Futterkiste Maria Anders Germany 2 Ana Trujillo Emparedados y helados Ana Trujillo Mexico 3 Antonio Moreno Taquería Antonio Moreno Mexico Then, look at a selection from the "Customers" table:
  • 28. OrderID CustomerName OrderDat e 10308 Ana Trujillo Emparedados y helados 9/18/199 6 10365 Antonio Moreno Taquería 11/27/19 96 10383 Around the Horn 12/16/19 96 10355 Around the Horn 11/15/19 96 10278 Berglunds snabbköp 8/12/199 6 Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the "Customers" table. The relationship between the two tables above is the "CustomerID" column. Then, we can create the following SQL statement (that contains an INNER JOIN), that selects records that have matching values in both tables: Example SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID= Customers.CustomerID;
  • 29. Different Types of SQL JOINs  Different Types of SQL JOINs  Here are the different types of the JOINs in SQL: 1.(INNER) JOIN: Returns records that have matching values in both tables
  • 30. SQL LEFT JOIN Keyword  The LEFT JOIN keyword returns all records from the left table (table1), and the matched records from the right table (table2). The result is NULL from the right side, if there is no match.  LEFT JOIN Syntax  SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;
  • 31. SQL RIGHT JOIN Keyword  The RIGHT JOIN keyword returns all records from the right table (table2), and the matched records from the left table (table1). The result is NULL from the left side, when there is no match.  RIGHT JOIN Syntax  SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name;
  • 32. SQL FULL OUTER JOIN Keyword  SQL FULL OUTER JOIN Keyword  The FULL OUTER JOIN keyword return all records when there is a match in either left (table1) or right (table2) table records.  Note: FULL OUTER JOIN can potentially return very large result-sets!