Basic SQL
January 22, 2020
DROP DATABASE IF EXISTS top_songsDB;
CREATE database top_songsDB;
USE top_songsDB;
CREATE TABLE top5000 (
id INT NOT NULL AUTO_INCREMENT,
position INT NOT NULL,
artist VARCHAR(100) NULL,
song VARCHAR(100) NULL,
year INT NULL,
starting_bid INT default 0,
raw_total DECIMAL(10,4) NULL,
raw_usa DECIMAL(10,4) NULL,
has_pet BOOLEAN NOT NULL,
PRIMARY KEY (id)
);
SELECT * FROM top5000;
-- Seed data
INSERT INTO products (flavor, price, quantity)
VALUES ("vanilla", 2.50, 100);
INSERT INTO products (flavor, price, quantity)
VALUES ("chocolate", 3.10, 120);
INSERT INTO products (flavor, price, quantity)
VALUES ("strawberry", 3.25, 75);
-- ### Alternative way to insert more than one row
-- INSERT INTO products (flavor, price, quantity)
-- VALUES ("vanilla", 2.50, 100), ("chocolate", 3.10, 120), ("strawberry", 3.25, 75);
-- UPDATE
UPDATE people
SET has_pet = true, pet_name = "Franklin", pet_age = 2
WHERE name = "Peter";