Skip to content

TheNoteTaker/sql-bootcamp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

MySQL Master Bootcamp

General Notes:

Section 2: Overview

General Notes

  • Some of the most common DBMS's (Database Management Systems):
    • PostgreSQL
    • MySQL
    • Oracle Database
    • SQLite
  • Types cannot be mixed and are specified upon creation. (Statically Typed)

What is a Database?

  1. A collection of data
    • I.e. a phone book
  2. A method of accessing and manipulating that data
  3. A structured set of computerized data with an accessible interface

Database vs Database Management System

  • DMS or Relational Database Management System refers to an interface for the data.
    • The database is the data itself and all of it. The DBMS is the UI for it.
    • They're often referred to as the same thing

MySQL vs SQL

SQL (Structured Query Language)

  • The language we use to "talk" to our databases
  • SQL is used to write inside of DBMS's such as MySQL
  • There is a standard for how SQL should work, and all DBMS's are tasked with implementing that standard and making them work.

Two Takeaways

  • It's very easy to switch after learning SQL
  • What makes databases (DBMS) unique are the features they offer, not the language.

Using Goorm and SQL

  • mysql-ctrl {command}
    • start (will start mysql)
    • stop (will stop mysql)
    • cli (Will stop and then start mysql)
      • Stands for Command Line Interface
  • use {database_name} (Changes the database being used)
  • source {database_filename} (Run code from a query file)
  • desc {table} (Shows the contents of a table)
    • Shorthand for SHOW COLUMNS FROM {tablename}
  • create {database_name} (Creates a database)
  • drop {database_name} (permanently destroys a database)
  • SELECT database() (Tells you the current database being used)
  • show {tables | databases} (Shows all tables or databases)

What is a Table?

A table is a collection of related data held in a structured format within a database.

  • Columns (Headers)

Different Types in SQL

Numeric String Date
INT CHAR DATE
SMALLINT VARCHAR DATETIME
TINYINT BINARY TIMESTAMP
MEDIUMINT VARBINARY TIME
BIGINT BLOB YEAR
DECIMAL TINYBLOB
NUMERIC MEDIUMBLOB
FLOAT LONGBLOB
DOUBLE TEXT
BIT TINYTEXT
MEDIUMTEXT
LONGTEXT
ENUM

SQL Types

  • INT (whole number)
  • varchar (variable-length string between 1-255 characters)

Creating Tables

  • Table names should be pluralized. It's because a table describes multiple of the thing, not just one.
CREATE TABLE tablename
(
    column_name data_type,
    column_name data_type,
);

/* Example: */
CREATE TABLE cats
(
    name VARCHAR(100),
    age  INT
);

Section 4: Inserting Data (And More)

General Notes

Syntax

Incorrect syntax:

INSERT INTO <tablename>(column, column)
VALUES (value, value);

The preferred way of writing:

INSERT INTO <tablename>
            (column,
            column)
VALUES      (value,
            value);
  • The order which the columns are used matters, as the order for the values being inserted must be in the same order.

Multiple Inserts

INSERT INTO <tablename>
            (column, column)
VALUES      (value, value),
            (value, value),
            (value, value);

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors