📕
Dan Fitz's Notes
  • README
  • Ai
    • Supervised Machine Learning
      • Introduction To Machine Learning
      • Regression With Multiple Input Variables
      • Classification
  • Csharp
    • C Sharp Advanced
      • Generics
      • Delegates
      • Lambda Expressions
      • Events
    • C Sharp Fundamentals
      • Intro To C
      • Primitive Types And Expressions
      • Non Primitive Types
      • Control Flow
      • Arrays And Lists
      • Working With Dates
      • Working With Text
      • Working With Files
      • Debugging Applications
    • C Sharp Intermediate
      • Classes
      • Association Between Classes
      • Inheritance
      • Polymorphism
      • Interfaces
  • Java
    • Inheritance Data Structures Java
      • Inheritance Polymorphism Using Overriding And Access Modifiers
      • Abstract Classes And Debugging
      • File I O And Exceptions
      • Collections Maps And Regular Expressions
    • Intro To Java
      • Introduction To Java Classes And Eclipse
      • Unit Testing Arrays And Array Lists
      • Static Variables Methods And Polymorphism Using Overloading
  • Javascript
    • Algorithms Data Structures
      • Big O Notation
      • Analyzing Performance Of Arrays And Objects
      • Problem Solving Approach
      • Problem Solving Patterns
      • Recursion
      • Searching Algorithms
      • Bubble Selection And Insertion Sort
      • Merge Sort
      • Quick Sort
      • Radix Sort
      • Data Structures Introduction
      • Singly Linked Lists
      • Doubly Linked Lists
      • Stacks And Queues
      • Binary Search Trees
      • Tree Traversal
      • Binary Heaps
    • Complete Nodejs
      • Understanding Node.js
      • REST AP Is And Mongoose
      • API Authentication And Security
      • Node.js Module System
      • File System And Command Line Args
      • Debugging Node.js
      • Asynchronous Node.js
      • Web Servers
      • Accessing API From Browser
      • Application Deployment
      • Mongo DB And Promises
    • Complete React Native
      • Working With Content
      • Building Lists
      • Navigating Users Between Screens
      • State Management
      • Handling Screen Layout
      • Setting Up An App
      • More On Navigation
      • Advanced Statement Management With Context
      • Building A Custom Express API
      • In App Authentication
    • Epic React
      • React Fundamentals
      • React Hooks
      • Advanced React Hooks
      • Advanced React Patterns
      • React Performance
    • Fireship Firestore
      • Firestore Queries And Data Modeling Course
      • Model Relational Data In Firestore No SQL
    • Functional Light Javascript
      • Intro
      • Function Purity
      • Argument Adapters
      • Point Free
      • Closure
      • Composition
      • Immutability
      • Recursion
      • List Operations
      • Transduction
      • Data Structure Operations
      • Async
    • Js Weird Parts
      • Execution Contexts And Lexical Environments
      • Types And Operators
      • Objects And Functions
      • Object Oriented Java Script And Prototypal Inheritance
      • Defining Objects
    • Mastering Chrome Dev Tools
      • Introduction
      • Editing
      • Debugging
      • Networking
      • Auditing
      • Node.js Profiling
      • Performance Monitoring
      • Image Performance
      • Memory
    • React Complete Guide
      • What Is React
      • React Basics
      • Rendering Lists And Conditionals
      • Styling React Components
      • Debugging React Apps
      • Component Deep Dive
      • Building A React App
      • Reaching Out To The Web
      • Routing
    • React Testing
      • Intro To Jest Enzyme And TDD
      • Basic Testing
      • Redux Testing
      • Redux Thunk Testing
    • Serverless Bootcamp
      • Introduction
      • Auction Service Setup
      • Auction Service CRUD Operations
      • Auction Service Processing Auctions
    • Testing Javascript
      • Fundamentals Of Testing
      • Static Analysis Testing
      • Mocking Fundamentals
      • Configuring Jest
      • Test React Components With Jest And React Testing Library
    • Typescript Developers Guide
      • Getting Started With Type Script
      • What Is A Type System
      • Type Annotations In Action
      • Annotations With Functions And Objects
      • Mastering Typed Arrays
      • Tuples In Type Script
      • The All Important Interface
      • Building Functionality With Classes
    • Web Performance With Webpack
      • Intro
      • Code Splitting
      • Module Methods Magic Comments
  • Other
    • Algo Expert
      • Defining Data Structures And Complexity Analysis
      • Memory
      • Big O Notation
      • Logarithm
      • Arrays
      • Linked Lists
      • Hash Tables
      • Stacks And Queues
      • Strings
      • Graphs
      • Trees
    • Aws Solutions Architect
      • AWS Fundamentals IAM EC 2
    • Fundamentals Math
      • Numbers And Negative Numbers
      • Factors And Multiples
      • Fractions
    • Mysql Bootcamp
      • Overview And Installation
      • Creating Databases And Tables
      • Inserting Data
      • CRUD Commands
      • The World Of String Functions
      • Refining Our Selections
      • The Magic Of Aggregate Functions
    • Random Notes
      • Understanding React Hooks
  • Python
    • Data Analysis Using Python
      • Loading Querying And Filtering Data Using The Csv Module
      • Loading Querying Joining And Filtering Data Using Pandas
      • Summarizing And Visualizing Data
    • Intro To Python
      • Course Introduction Intro To Programming And The Python Language Variables Conditionals Jupyter Notebook And IDLE
      • Intro To Lists Loops And Functions
      • More With Lists Strings Tuples Sets And Py Charm
      • Dictionaries And Files
Powered by GitBook
On this page
  • SELECT (Read)
  • Adding conditions using WHERE
  • Aliases
  • UPDATE
  • DELETE
  • Running SQL Files
  1. Other
  2. Mysql Bootcamp

CRUD Commands

CRUD is an acronym for the different types of interactions you have with a database:

  • Create

  • Read

  • Update

  • Delete

You've already seen create and a bit of read:

-- Create
INSERT INTO <tablename>(col1, col2) VALUES('value1', 2);

-- Read (BUT there's way more to it)
SELECT * from <tablename>;

This section will focus on reading via SELECT, updating via UPDATE, and deleting via DELETE.

SELECT (Read)

Here's the basic syntax for selecting all data with restrictions on what columns you want back:

SELECT * from cats; -- ALL columns
SELECT name from cats; -- one column
SELECT name, age from cats; -- multiple columns

Adding conditions using WHERE

When reading a database, you're almost never reading every row. You usually are trying to pull out particular pieces. That's where the WHERE clause comes in.

Here's the basic syntax for WHERE:

SELECT * FROM cats WHERE age=4;
SELECT * FROM cats WHERE name='eGg'; -- <= case insensitive

Note: The WHERE clause is useful for UPDATE and DELETE too, not just SELECT. (You usually want to update or delete specific things, not your entire database/table.)

Aliases

When displaying a table's columns, I can specify an alias that changes how it appears (without changing the database).

Syntax:

SELECT id AS cat_id, name AS 'cat name' FROM cats;
-- Notice that you can provide a string as alias

Pro tip: Aliases are useful when you create JOIN tables. For example, if you have a dogs table and cats table, they may both have the column name. During your JOIN, you can create aliases to make it clear which is which, i.e., dog_name and cat_name.

UPDATE

Sometimes you need to UPDATE values in a database. For example, maybe a user forgot their password and wants to change it. Here's the syntax for that:

-- This command updates breed to 'Shorthair' for every cat with the breed 'Tabby'
UPDATE cats SET breed='Shorthair' WHERE breed='Tabby';

Pro tip: Run the SELECT equivalent of your UPDATE command first. Once your SELECT command returns the data you expect, then update it. Example:

SELECT * FROM cats WHERE name='no name provided';

-- Check if the data returned is what you want to update, then...

UPDATE cats SET name='Cat Doe' WHERE name='no name provided';

DELETE

The basic syntax for the DELETE command is this:

SELECT * FROM cats WHERE name='Ringo';

-- Once your `SELECT` returns what you want, then...

DELETE FROM cats WHERE name='Ringo';

Running SQL Files

Bonus!

You can run a series of SQL commands by running source filename.sql inside of mysql-ctl cli (provided you're in the same directory as filename.sql).

This is a quick way of executing a bunch of commands at once after having written it in a nice text editor.

PreviousInserting DataNextThe World Of String Functions

Last updated 3 years ago