Rohit Prasan Mandal, dbms
Back

About

Data is useful as long as we've control over storing, reading, updating and deleting it as per our needs. MySQL is a Database Management System which allows us to use the CRUD(create, read, update, and delete) method. Database Management Systems can be used for data collection and storage through the training of machine learning models, or to deploy real-time prediction endpoints.

Prerequisites

  1. Programming sense
  2. MySQL community server
  3. PopSQL 1

Index:

  1. Important Commands
  2. Introduction
  3. Types of Keys
  4. Creating Tables
  5. Inserting Data
  6. Constraints
  7. Update & Delete
  8. Basic Queries
  9. Company Database Intro
  10. Creating Company Database
  11. More Basic Queries
  12. Functions
  13. Wildcards
  14. Union
  15. Joins
  16. Nested Queries
  17. On Delete
  18. Triggers
  19. ER Diagrams Intro
  20. Designing an ER Diagram
  21. Converting ER Diagrams to Schemas

0. Important Commands

SELECT - extracts data from a database
UPDATE - updates data in a database
DELETE - deletes data from a database
INSERT INTO - inserts new data into a database
CREATE DATABASE - creates a new database
ALTER DATABASE - modifies a database
CREATE TABLE - creates a new table
ALTER TABLE - modifies a table
DROP TABLE - deletes a table
CREATE INDEX - creates an index (search key)
DROP INDEX - deletes an index
-- - comment 
AUTO_INCREMENT - auto increment values. eg. 1 2 3 4 ...

1. Introduction

2. Types of Keys

  1. Super Key
  2. Candidate Key
  3. Primary Key
  4. Alternate key
  5. Composite/Compound Key
  6. Unique Key
  7. Foreign Key

3. Creating tables


INT                           -- Whole Numbers
DECIMAL(M,N)                  -- Decimal Numbers - Exact Value
VARCHAR(l)                    -- String of text of length l
BLOB                          -- Binary Large Object, Stores large data
DATE                          -- 'YYYY-MM-DD'
TIMESTAMP                     -- 'YYYY-MM-DD HH:MM:SS' - used for recording events

-- Creating tables
CREATE TABLE student (
  student_id INT PRIMARY KEY,
  name VARCHAR(40),
  major VARCHAR(40)
  -- PRIMARY KEY(student_id)
);

DESCRIBE student;
DROP TABLE student;
ALTER TABLE student ADD gpa DECIMAL;
ALTER TABLE student DROP COLUMN gpa;

4. Inserting Data


INSERT INTO student VALUES(1, 'Jack', 'Biology');
INSERT INTO student VALUES(2, 'Kate', 'Sociology');
INSERT INTO student(student_id, name) VALUES(3, 'Claire');
INSERT INTO student VALUES(4, 'Jack', 'Biology');
INSERT INTO student VALUES(5, 'Mike', 'Computer Science');

SELECT * FROM student;

5.Constraints

PRIMARY KEY = NOT NULL and UNIQUE

CREATE TABLE student (
  student_id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(40) NOT NULL,                        -- name VARCHAR(40) UNIQUE
  major VARCHAR(40) DEFAULT 'undecided',            -- major VARCHAR(40) UNIQUE
);

INSERT INTO student(name, major) VALUES(1, 'Jack', 'Biology');
INSERT INTO student(name, major) VALUES(2, 'Kate', 'Sociology');
INSERT INTO student(name) VALUES('Kate');
-- INSERT INTO student(name, major) VALUES(NULL, 'Sociology'); -- Error it can't be NULL as defined.

6. Update & Delete

DELETE FROM student;

DELETE FROM student
WHERE student_id = 4;

DELETE FROM student
WHERE major = 'Sociology' AND name = 'Kate';

UPDATE student
SET major = 'Undecided';

UPDATE student
SET name = 'Johnny'
WHERE student_id = 4;

UPDATE student
SET major = 'Bio'
WHERE major = 'Biology';

UPDATE student
SET major = 'Biosociology'
WHERE major = 'Biology' OR major = 'sociology'

UPDATE student
SET major = 'Undecided', name = 'Tom'
WHERE student_id = 4;

7. Basic Queries

8. Company Database Intro

9. Creating Company Database

10. More Basic Queries

11. Functions

12. Wildcards

13. Union

14. Joins

15. Nested Queries

16. On Delete

17. Triggers

18. ER Diagrams Intro

19. Designing an ER Diagram

20. Converting ER Diagrams to Schemas


  1. MLDB is an open-source database designed for machine learning.
© xiaowuc2RSS