mysql-ppt
mysql-ppt
CAREERER
A
A Warm Welcome To Careerera Family
®
CAREERER
A
In SQL, whenever we wish to alter the table structure, we will use the ALTER
command.
Example :
ALTER TABLE table_name DROP COLUMN column_name;
ALTER TABLE table_name RENAME COLUMN old_column_
name TO new_column_name;
3. DROP Command
• DROP command is used to remove or delete the table's records and the
table's structure from the database.
Syntax :
DROP TABLE table_name;
Example :
Write a query to delete the school table from the SCHOOL database.
DROP TABLE school;
4.TRUNCATE Command
A TRUNCATE command is used to delete the table's records, but the table's
structure will remain unaffected in the database.
Syntax:
TRUNCATE TABLE table_name;
Example :
TRUNCATE TABLE t_school;
5.RENAME Command
Example :
RENAME TABLE student TO top_student;
WHAT IS DATA MANIPULATION LANGUAGE?
Syntax:
UPDATE table_name SET column_name = value
WHERE condition;
4.DELETE Command
1. GRANT
Access privileges can be assigned to a user for the databases and
tables using the GRANT command.
2. REVOKE
All the access privileges which are already assigned to the user can
be revoked by using the REVOKE command.
WHAT IS TCL COMMANDS?
2. ROLLBACK
Using the rollback command in SQL, you can roll to the last
saved state of a transaction.
3. SAVEPOINT
Using the SAVEPOINT command, you can assign a name to a
specific part of the transaction.
WHAT IS DATA QUERY LANGUAGE?
• Step 1: Open the MySQL server by using the mysql client tool.
• Step 2: Enter the password for the account and press Enter.
Enter Password: ****
• Step 3: Execute the following command to show all users in the
current MySQL server.
MySQL> select user from MySQL. User;
GRANT PRIVILEGES TO THE MYSQL NEW USER
-
mysql> SELECT user, host, db, command FROM information_schema.processlist;
CHANGE USER PASSWORD
• To change the password of any user account, you must have to
keep this information in your mind:
-The details of the user account that you want to change.
-An application used by the user whose password you want
to change. If you reset the user account password without
changing an application connection string, then the application
cannot connect with the database server.
• MySQL allows us to change the user account password in three
different ways, which are given below:
1. UPDATE Statement
2. SET PASSWORD Statement
CHANGE USER ACCOUNT PASSWORD USING THE UPDATE STATEMENT
1. USE mysql;
2. UPDATE user SET password = PASSWORD('jtp12345') WHERE
user = 'peter' AND host = 'localhost';
3. FLUSH PRIVILEGES;
CHANGE USER ACCOUNT PASSWORD USING SET PASSWORD STATEMENT
1. USE mysql;
2. UPDATE user SET password = PASSWORD('jtp12345') WHERE
user = 'peter' AND host = 'localhost';
3. FLUSH PRIVILEGES;
CREATE DATABASE
Parameter Description
• SHOW TABLES;
• DESCRIBE employee;
ALTER TABLE
• SYNTAX:
ALTER TABLE table_name
ADD new_column_name column_definition
[ FIRST | AFTER column_name ],
ADD new_column_name column_definition
[ FIRST | AFTER column_name ], ... ;
For example:
MODIFY COLUMN IN THE TABLE
• SYNTAX:
1. ALTER TABLE table_name
2. DROP COLUMN column_name;
• For example:-
RENAME COLUMN IN TABLE
• SYNTAX:
1. ALTER TABLE table_name
2. CHANGE COLUMN old_name new_name
3. column_definition
4. [ FIRST | AFTER column_name ]
• For Example:-
RENAME TABLE
• SYNTAX:
1. ALTER TABLE table_name
2. RENAME TO new_table_name;
For example:-
TRUNCATE TABLE
• SQL constraints are used to specify rules for the data in a table.
• Constraints are used to limit the type of data that can go into a table.
This ensures the accuracy and reliability of the data in the table. If
there is any violation between the constraint and the data action, the
action is aborted.
• Constraints can be column level or table level. Column level
constraints apply to a column, and table level constraints apply to
the whole table.
CONSTRAINTS
The following are the most common constraints used in the
MySQL:
• NOT NULL
• CHECK
• DEFAULT
• PRIMARY KEY
• AUTO_INCREMENT
• UNIQUE
• INDEX
• ENUM
• FOREIGN KEY
NOT NULL CONSTRAINT
• By default, a column can hold NULL values.
• This constraint specifies that the column cannot have NULL
or empty values. The below statement creates a table with
NOT NULL constraint.
• The table with the foreign key is called the child table, and the
table with the primary key is called the referenced or parent
table.
CHECK CONSTRAINT
• The following SQL creates a CHECK constraint on the "Age"
column when the "Persons" table is created.
The CHECK constraint ensures that the age of a person must
be 18, or older:
CHECK CONSTRAINT
CHECK ON ALTER TABLE
To create a CHECK constraint on the "Age" column when the
table is already created, use the following SQL:
ALTER TABLE Persons
ADD CHECK (Age>=18);
DEFAULT CONSTRAINT
• The DEFAULT constraint is used to set a default value for a
column.
• The default value will be added to all new records, if no other
value is specified
DEFAULT ON CREATE TABLE:
The following SQL sets a DEFAULT value for the "City" column when the
"Persons" table is created:
CREATE INDEX STATEMENT
The CREATE INDEX statement is used to create indexes in
tables.
Indexes are used to retrieve data from the database more
quickly than otherwise. The users cannot see the indexes, they
are just used to speed up searches/queries.
GROUP BY It is optional. It collects data from multiple records and grouped them
by one or more columns.
HAVING It is optional. It works with the GROUP BY clause and returns only
those rows whose condition is TRUE.
ORDER BY It is optional. It is used for sorting the records in the result set.
SELECT *
FROM EMPLOYEE
WHERE NAME = ’PETER';
WHERE CLAUSE WITH AND CONDITION
SELECT *
FROM officers
WHERE WORKING_DATE =“2020-10-04”
OR WORKING_HOURS >=10;
WHERE CLAUSE WITH COMBINATION OF AND & OR
CONDITIONS
SELECT *
FROM officers
WHERE (OCCUPATION = ’ACTOR' AND WORKING_DATE = ’2020-10-04')
OR (WORKING_HOURS>= 13);
ORDER BY CLAUSE
Parameters
1. expressions: It specifies the columns that you want to retrieve.
2. tables: It specifies the tables, from where you want to retrieve
records. There must be at least one table listed in the FROM
clause.
3. WHERE conditions: It is optional. It specifies conditions that
must be fulfilled for the records to be selected.
4. ASC: It is optional. It sorts the result set in ascending order by
expression (default, if no modifier is provider).
5. DESC: It is also optional. It sorts the result set in descending
order by expression.
ORDER BY: WITHOUT USING ASC/DESC
ATTRIBUTE
• If you use MySQL ORDER BY clause without specifying the ASC
and DESC modifier then by default you will get the result in
ascending order.
syntax
SELECT *
FROM officers
WHERE address = 'Lucknow'
ORDER BY officer_name;
ORDER BY: WITH ASC ATTRIBUTE
SELECT *
FROM EMPLOYEE
WHERE WORKING_DATE= ’2020-10-04'
ORDER BY NAME DESC;
ORDER BY: USING BOTH ASC AND DESC ATTRIBUTES
SELECT NAME,OCCUPATION
FROM EMPLOYEE
WHERE WORKING_HOURS >10
ORDER BY NAME DESC, OCCUPATION ASC;
GROUP BY CLAUSE
• The GROUP BY Clause is used to collect data from multiple
records and group the result by one or more column. It is
generally used in a SELECT statement.
• You can also use some aggregate functions like COUNT, SUM,
MIN, MAX, AVG etc. on the grouped column.
• Syntax:
SELECT expression1, expression2, ... expression_n,
aggregate_function (expression)
FROM tables
[WHERE conditions]
GROUP BY expression1, expression2, ... expression_n;
GROUP BY CLAUSE WITH COUNT FUNCTION
• Now, the following query will GROUP BY the example using the
SUM function and return the emp_name and total working hours
of each employee.
SELECT emp_name, SUM(working_hours) AS "Total working hours"
FROM employees
GROUP BY emp_name;
GROUP BY CLAUSE WITH MIN FUNCTION
• The Inner Join can also be used with the GROUP BY clause.
SELECT STUDENTS.STUDENT_ID, TECHNOLOGY.INST_NAME, STUDENTS.CIT
Y, TECHNOLOGY.TECHNOLOGY
FROM STUDENT
INNER JOIN TECHNOLOGY
ON STUDENTS.STUDENT_ID = TECHNOLOGY.TECH_ID GROUP BY INST_NA
ME;
INNER JOIN WITH WHERE CLAUSE
• The WHERE clause enables you to return the filter result. The
following example illustrates this clause with Inner Join:
SELECT TECH_ID, INST_NAME, CITY, TECHNOLOGY
FROM STUDENTS
INNER JOIN TECHNOLOGY
USING (STUDENT_ID) WHERE TECHNOLOGY = "JAVA";
LEFT JOIN
• The Left Join in MySQL is used to query records from multiple tables.
This clause is similar to the Inner Join clause that can be used with a
SELECT statement immediately after the FROM keyword.
• When we use the Left Join clause, it will return all the records from
the first (left-side) table, even no matching records found from the
second (right side) table. If it will not find any matches record from
the right side table, then returns null.
• We can understand it with the following visual representation where
Left Joins returns all records from the left-hand table and only the
matching records from the right side table:
LEFT JOIN
The Left Join can also be used with the GROUP BY clause. The following
statement returns customer id, customer name, qualification, price,
and date using the Left Join clause with the GROUP BY clause.
RIGHT JOIN
• The Right Join is used to joins two or more tables and returns all rows
from the right-hand table, and only those results from the other table
that fulfilled the join condition.
• If it finds unmatched records from the left side table, it returns Null
value. It is similar to the Left Join, except it gives the reverse result of
the join tables. It is also known as Right Outer Join. So, Outer is the
optional clause used with the Right Join.
• We can understand it with the following visual representation where
Right Outer Join returns all records from the left-hand table and only
the matching records from the other table:
RIGHT JOIN
• MySQL uses the WHERE clause to provide the filter result from
the table. The following example illustrates this with the Right
Join clause:
CROSS JOIN
• CROSS JOIN is used to combine all possibilities of the two or more
tables and returns the result that contains every row from all
contributing tables.
• The CROSS JOIN is also known as CARTESIAN JOIN, which provides
the Cartesian product of all associated tables. The Cartesian product
can be explained as all rows present in the first table multiplied by
all rows present in the second table. It is similar to the Inner Join,
where the join condition is not available with this clause.
• We can understand it with the following visual representation where
CROSS JOIN returns all the records from table1 and table2, and each
row is the combination of rows of both tables.
CROSS JOIN
• The CROSS JOIN keyword is always used with the SELECT
statement and must be written after the FROM clause.
UNION Syntax:
SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;
UNION OPERATOR
Example:
• The inner query executed first gives the result to the outer
query, and then the main/outer query will be
performed. MySQL allows us to use subquery anywhere, but it
must be closed within parenthesis.
SUBQUERY
The following are the rules to use subqueries:
• Subqueries should always use in parentheses.
• If the main query does not have multiple columns for
subquery, then a subquery can have only one column in the
SELECT command.
• We can use various comparison operators with the subquery,
such as >, <, =, IN, ANY, SOME, and ALL. A multiple-row
operator is very useful when the subquery returns more than
one row.
• We cannot use the ORDER BY clause in a subquery, although it
can be used inside the main query.
• If we use a subquery in a set function, it cannot be
immediately enclosed in a set function.
SUBQUERY
The following are the advantages of using subqueries:
• The subqueries make the queries in a structured form that
allows us to isolate each part of a statement.
• The subqueries provide alternative ways to query the data from
the table; otherwise, we need to use complex joins and unions.
• The subqueries are more readable than complex join or union
statements.
SUBQUERY SYNTAX:
1.SELECT column_list (s) FROM table_name
2.WHERE column_name OPERATOR
3.SELECT column_list (s) FROM table_name [WHERE])
SUBQUERY
Subquery Example:
Suppose we have a table named “customer" that contains the
following data:
SUBQUERY
• ANY OPERATOR
SUBQUERIES WITH ALL, ANY, AND SOME
• ALL OPERATOR
WHAT IS ETL?
ETL, which stands for extract, transform and load, is a data
integration process that combines data from multiple
data sources into a single, consistent data store that is
loaded into a data warehouse or other target system.
INTRODUCTION TO ETL
1. Extract
During data extraction, raw data is copied or exported from
source locations to a staging area. Data management teams
can extract data from a variety of data sources, which can be
structured or unstructured.
Those sources include but are not limited to:
• SQL or NoSQL servers
• CRM and ERP systems
• Flat files
• Email
• Web pages
HOW ETL WORKS
2. Transform
In the staging area, the raw data undergoes data processing. Here, the data is
transformed and consolidated for its intended analytical use case.
This phase can involve the following tasks:
• Filtering, cleansing, de-duplicating, validating, and authenticating the data.
• Performing calculations, translations, or summarizations based on the raw
data. This can include changing row and column headers for consistency,
converting currencies or other units of measurement, editing text strings, and
more.
• Conducting audits to ensure data quality and compliance
• Removing, encrypting, or protecting data governed by industry or
governmental regulators
• Formatting the data into tables or joined tables to match the schema of the
target data warehouse.
HOW ETL WORKS
3. Load
In this last step, the transformed data is moved from the staging
area into a target data warehouse.
•Typically, this involves an initial loading of all data, followed by
periodic loading of incremental data changes and, less often,
full refreshes to erase and replace data in the warehouse.
• For most organizations that use ETL, the process is automated,
well-defined, continuous and batch-driven.
•Typically, ETL takes place during off-hours when traffic on the
source systems and the data warehouse is at its lowest.
THANK YOU !!!
(USA) (INDIA)
2-Industrial Park Drive, E-
Waldorf, MD, 20602, B-44, Sector-
United States 59, Noida
Uttar
(USA) Pradesh
+1-844-889-4054 201301
(Singapore)
3 Temasek Avenue, Singapore (INDIA)
039190 +91-92-5000-
[email protected] 4000
www.careerera.com