0% found this document useful (0 votes)
51 views

MySQL DB Topic To Learn Database

The document provides an overview of a 17 day introduction to MySQL course, outlining topics covered each day including database architecture, installation, data types, queries, functions, joins, views, stored procedures and more. Key concepts introduced include SQL, relational databases, tables, rows, columns, primary keys, foreign keys, aggregation, string and date functions, subqueries, case statements, joins and self joins. Practical examples are provided throughout to demonstrate each new concept.

Uploaded by

Lokesh Dhakar
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

MySQL DB Topic To Learn Database

The document provides an overview of a 17 day introduction to MySQL course, outlining topics covered each day including database architecture, installation, data types, queries, functions, joins, views, stored procedures and more. Key concepts introduced include SQL, relational databases, tables, rows, columns, primary keys, foreign keys, aggregation, string and date functions, subqueries, case statements, joins and self joins. Practical examples are provided throughout to demonstrate each new concept.

Uploaded by

Lokesh Dhakar
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

Day 01 --Introduction to MySQL

--Understanding the architecture of an application


--Frontend, backend, database, RestAPI, Holders(JSON or XML),
Client-Server architecture
--Where to save data ?
--Memory - RAM, Cache, HDD, SSD
--Ways - File System, DBMS
--Disadvantages of file system
--No Security, No concurrency
--Difference between Database and DBMS ?
--Type of DBMS in it
--NoSQL
--Key-Value, Wide Column, Document, Graph.
--SQL
--MySQL, Oracle, SQL Server, Postgres, DB2
--What exactly is RDBMS ?
--Why do we need relation among data ?
--Ex - A social media app like fb or ig
--Installation of MySQL
--What you will be getting into this course ?
--Basics, Advanced, Multiple tables, Complex queries, Sub
queries, Triggers, Events, Transactions
--Full on guidance on hackerrank to practice on online IDE
--Interview Questions practice
--Mini CRUD App with Java and Node.js

Day 02 --Understanding data


--Types of data
--How they are stored inside a database
--Different types of applications you get in MySQL
--Database Server
--MySQL Workbench
--MySQL cmd line client
--Connectors or drivers
--Basic rules
--MySQL is case-insensitive
--Use of semicolon is must
--Use snake_case
--How RDBMS stores data
--DB
--CREATE DATABASE <db_name>;
--USE <db_name>;
--SHOW DATABASES;
--DROP DATABASE <db_name>;
--SELECT DATABASE();
--Basic Datatypes
--INT
--VARCHAR(up to 255 characters)
--Table
--Columns & Rows
--CREATE TABLE <tab_name>(col_name datatype, .....);
--SHOW TABLES;
--DESC <tab_name>;
--SHOW COLUMNS FROM <tab_name>;
--DROP TABLE <tab_name>;
--COMMIT
--By default Autocommit is active
Day 03 --Insertion of data
--INSERT INTO <tab_name>(col_name...) VALUES (val...);
--INSERT INTO <tab_name> VALUES(val1...);
--DEFAULT keyword
--NULL values
--Inserting multiple rows at once
--Retrieving data
--SELECT * FROM <tab_name>;
--Constraints on columns
--NOT NULL
--DEFAULT
--UNIQUE
--PRIMARY KEY
--AUTO INCREMENT

Day 04 --Selecting particular column(s) from table


--Math Operations can also be performed on columns
--Another way of setting primary key
--Clasuses
--FROM
--WHERE
--AS (aliase)
--Comparison operators
--Updating Rows
--E <condition>;
--UPDATE <tab_name> SET <col_name> = 'updated_value';
--Deleting Data
--DELETE FROM <tab_name> WHERE <condition>;
--DELETE FROM <tab_name>;

Day 05 --Introduction to GUI


--Writing/Running/Loading MySQL scripts.
--Relational Operator
-- >, >=, <, <=, !=, =
--Logical Operator
--OR
--AND
--NOT
--Boolean Values
--0 or 1
--truth tables
--Hackerrank
--IN & NOT IN operator
--works with list
--Ex - SELECT * FROM STUDENT WHERE sem IN (2, 4, 6);

Day 06 --Clasuses
--LIMIT
--Let's understand pagination first
--Ex - SELECT * FROM <tab_name> LIMIT quantity;
--OFFSET
--Must be in the end
--ORDER BY
--Ascending by default
--single column, multiple column
--DESC
--DISTINCT
--To avoid duplicacy
--Ex - SELECT DISTINCT col_name FROM <tab_name>;
--Comes right after SELECT
--Multiple Columns

Day 07 --IS NULL / IS NOT NULL


--BETWEEN-AND
--Ex - SELECT * FROM <tab_name> WHERE sem BETWEEN 4 AND 6;
--Inclusive range
--LIKE
--Used to refine selection on the basis of pattern
-- ... WHERE name LIKE 'pattern'
'%' - Return all
'%lab%' - Return all which have 'lab' in between
'_' - One character
--REGEXP
-^ represent the start, $ represent end, | - or
--[] - list
--GFG
--COUNT
--COUNT(*)
--COUNT(DISTINCT <col_name>)
--COUNT(*) WHERE <condition>

Day 08 --Aggregate functions


--COUNT
--MIN
--MAX
--SUM
--AVG
--GROUP BY
--More on Data types
--CHAR
--DECIMAL
--(6, 2)
--BLOB
--FLOAT
--DOUBLE
--JSON
--DECIMAL vs FLOAT/DOUBLE

Day 09 --String Functions


--CHAR_LENGTH or CHARACTER LENGTH
--CONCAT(args1, args2, ....) / CONCAT_WS(seperator, args1, args2...)
--UPPER or UCASE
--LOWER or LCASE
--TRIM
--SUBSTRING / SUBSTR(col_name, start_index, no_of_char )
--INSERT(ori_string, index, no_of_char_to_be_replaced, string2)
--REPLACE(ori_str, from_str, new_str)
--REVERSE
--STRCMP(str1, str2)

Day 10 --Numeric Functions


--ABS
--CEIL
--FLOOR
--MOD
--PI
--POW
--RAND
--ROUND
--SQRT
--TRUNCATE(number, no_of_characters_to_be_after_point)
--DIV Ex - SELECT 40 DIV 2;
--Working with Date and Time
--Datatype
--DATE
YYYY-MM-DD
--TIME
hh:mm:ss
--DATETIME
YYYY-MM-DD hh:mm:ss
--TIMESTAMP
same as datetime but it has a range - epoch time
'1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC
--DEFAULT NOW()
--ON UPDATE CURRENT_TIMESTAMP or NOW()

Day 11 --Date Functions


--CURDATE
--CURTIME
--NOW
--Rest from docs

Day 12 --Subqueries
-- SELECT .......WHERE creditlimit = (another select query which
returns a creditlimit val)
--Case
--SELECT customername, country,
CASE
WHEN country = 'USA' THEN 'US'
WHEN country = 'INDIA' THEN 'IN'
ELSE 'some text'
END AS country_code
FROM customers;

--IFNULL(column_name, alt_value)
--Altering table structure
--ALTER TABLE <tab_name>
ADD col_name data_type;
DROP COLUMN col_name;
MODIFY COLUMN col_name data_type;
--Let's talk about relationships
--ONE TO ONE
--ONE TO MANY
--MANY TO MANY
--FOREIGN KEY

Day 13 --Creating table with foreign key


--FOREIGN KEY (current_col) REFERENCES other_tab(other_tab_pk)
--UNIQUE constraint
--Using subqueries with multiple tables
--JOINS
--CROSS JOIN
--SELECT * FROM customers, orders;
--IMPLICIT INNER JOIN
--SELECT * FROM customers, orders where customers.customernumber
= orders.customernumber
--EXPLICIT INNER JOIN (Intersection)
--SELECT * FROM tab_name1 INNER JOIN tab_name2 ON col_name =
col_name
--ALIAS for TABLE
Day 14 --OUTER JOINS
--LEFT JOIN
--RIGHT JOIN
--CASCADE CONSTRAINT
--ON DELETE CASCADE
--Joining more than two tables

Day15 --USING clause


--can be used in place of joining column with the same name
...USING(customernumber)
--UNION clause
--To join multiple queries
--NATURAL JOIN
--automatically matches the same columns
--Not recommended
--SELF INNER JOIN
FROM employees e JOIN employees r ON e.reportsTo = r.employeeNumber
--SELF OUTER JOIN
--Can use left or right joins in self joins
--COMPUND JOIN
--on the basis of composite(multiple) primary keys
--JOINS across DBs
db_name.tab_name aliase

Day 16 --VIEWS
--Facts
--View is a named query stored in the database catalog.
--Increases security - Restrict Access
--Virtual tables
--Creating views
CREATE VIEW view_name AS select query
--Operations
SELECT * from view_name
Can also apply conditions in where clause, join with other data
--Dropping views
DROP VIEW view_name;
--Altering views
CREATE OR REPLACE VIEW view_name AS select query
--Editing views
--Deleting data & Updating data from views
--Also effects the origional data
--WITH CHECK OPTION

--Renaming a table or view


--RENAME TABLE old_name TO new_name;

Day 17 --Delimiter
--DELIMITER $$
--Stored procedures
--Saves the mysql queries inside the database itself
--Can do the programming stuff like if-else, loops
--Optimization from db side
--Creating a stored procedure
DELIMITER $$
CREATE PROCEDURE cust_info()
BEGIN
SELECT customerName, country
FROM customers ORDER BY customerName;
END$$
DELIMITER ;
--Calling
CALL cust_info();
--Deleting
DROP PROCEDURE prod_name;
--IF EXISTS
--Parameter or Argument passing
--Types
--IN
--OUT
--INOUT
--Syntax
prod_name(IN val_name data_type(size), ...)
--Task - Make a prod which accepts customernumber and returns the total
number of orders by customer
--Defining variables
--User variable (for queries)
SET @var_name = val;
--Inside procedure
--DECLARE var_name data_type DEFAULT val;
--Setting values in variables
--SELECT col_name INTO var_name FROM......;

Day 18 --Functions
--Same as procedures but can return only one val
--CREATE FUNCTION fun_name (args)
RETURNS data_type
attribute - DETERMINISTIC - returns the same val - do not
modifies data
--general use is formula based calculations
READS SQL DATA - retrieve data
MODIFIES SQL DATA - DML commands
BEGIN
...
RETURN val;
END
--DROP FUNCTION IF EXISTS fun_name;
--IF ...THEN...END IF;
--IF ...THEN ... ELSE ...END IF;
--IF ...THEN ... ELSEIF ...END IF;
--Triggers
--What ?
--Used for updating data automatically
--Use for logging
--when
--BEFORE or AFTER
--Actions
--INSERT or UPDATE or DELETE
--Type
--FOR EACH ROW
--Statement level (Unsupported in MySQL)
--Fetching row data
--OLD/NEW
--Creating Trigger
DELIMITER $$
CREATE TRIGGER trigger_name
<when> <action>
ON table_name FOR EACH ROW
BEGIN
...
END;
$$
DELIMITER ;
--SHOW TRIGGERS;
--LIKE clause in showing tables or functions or triggers
--DROP TRIGGER IF EXISTS trig_name

Day 19 --User
--CREATE USER username IDENTIFIED BY 'passowrd';
--SELECT * FROM mysql.user;
--DROP USER IF EXISTS user_name;
--Privilages
--GRANT {SELECT, INSERT, DELETE, UPDATE or ALL}
ON {db_name or *(for all db)}.{tab_name or * (for all tab)} TO
username;
--REVOKE ...

Topics to be explored
--Events
--Transaction
--Indexing
--Normalization
--MySQL Errors
--Can validate the inputs
--MySQL Docs
--SIGNAL SQLSTATE 'sql_err_code'
SET MESSAGE_TEXT = 'msg';
--45000

You might also like