ajpenalosa
6/13/2018 - 8:16 PM

Commands

-- Creates a new database
CREATE DATABASE programming_db;

-- Switches to the database
USE programming_db;

-- Shows table info
DESCRIBE programming_languages;

-- Shows the actual data in table
SELECT * FROM programming_languages
WHERE rating > 8;

-- Creates a table
 CREATE TABLE programming_languages (
	id INT AUTO_INCREMENT NOT NULL,
	languages VARCHAR(30) NOT NULL,
    rating INT,
    PRIMARY KEY (id)
 );
 
 -- Insert data into the table
INSERT INTO programming_languages SET
languages = "HTML",
rating = 10;

INSERT INTO programming_languages SET
languages = "CSS",
rating = 9;

INSERT INTO programming_languages SET
languages = "JavaScript",
rating = 7;

INSERT INTO programming_languages SET
languages = "SQL",
rating = 6;

-- Insert multiple items
INSERT INTO programming_languages ( languages, rating )
VALUES ("CSS", 8),
("HTML", 7),
("JavaScript",  7),
("SQAl", 5);


-- Update content in a column at a specific ID
UPDATE programming_languages SET rating = 10
WHERE id = 2;

-- Adding a column
ALTER TABLE programming_languages
ADD mastered BOOLEAN DEFAULT FALSE;

-- Updating content
UPDATE programming_languages SET
mastered = true
WHERE id <= 2;

-- Delete a row
DELETE FROM programming_languages
WHERE id  = 4;

-- Delete column
ALTER TABLE programming_languages
DROP COLUMN mastered;