I am very new to MySQL coding I assure you my question will make me look like a fool. However despite constantly looking for good example code I constantly come across varying syntax and organizational habits; I simply want to know once I create a table and fill it with data is it acceptable to just enter in my queries or should there be some break in the code, For example a language like java or C would use curly brackets,{ }. My Problem is the assignment requires us not to use foreign keys but instead, to just set up a general model; that while not functional looks right, This is part of my Code.
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `mydb` ;
-- -----------------------------------------------------
-- Table `mydb`.`Music`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`Music` (
`Title` VARCHAR(25) NOT NULL,
`Artist` VARCHAR(30) NOT NULL,
`Producer` VARCHAR(45) NOT NULL,
`Genre` VARCHAR(20) NOT NULL,
`Year` YEAR NOT NULL,
`Price` DOUBLE NOT NULL,
`CD Quantity` INT NOT NULL,
`Cassette Quantity` INT NOT NULL,
`Sheet Music Quantity` INT NOT NULL,
`MID` INT NOT NULL,
`VID` INT NOT NULL,
PRIMARY KEY (`Title`, `Artist`, `Producer`, `Genre`, `Year`, `Price`, `CD Quantity`, `Cassette Quantity`, `Sheet Music Quantity`, `MID`, `VID`))
ENGINE = InnoDB
COMMENT = ' ';
Hear I create more tables, then I insert into this table;
#Inserts for Music
$sql = INSERT INTO Music.
(Title, Artist, Producer, Genre, Year, Price, CD Quantity, Cassette Quantity, Sheet Music Quantity, MID, VID) .
VALUES .
('Jazz Hits ', 'Dizzy gillespi', 'Jazz co.', 'Jazz', '1990','12.00','2', '5', '8', '1', '1');
$sql = INSERT INTO Music.
(Title, Artist, Producer, Genre, Year, Price, CD Quantity, Cassette Quantity, Sheet Music Quantity, MID, VID) .
VALUES .
('Funky Fresh', 'Snoop', 'HOV', 'Hip Hop', '1997', '6.00', '5', '3', , '2', '2', '3');
$sql = INSERT INTO Music.
(Title, Artist, Producer, Genre, Year, Price, CD Quantity, Cassette Quantity, Sheet Music Quantity, MID, VID) .
VALUES .
('Classic Jazz', 'Cole Train', 'Jazz inc.', 'Jazz', '1992', '8.00', '5', '3 ', '4', '3', '1');
$sql = INSERT INTO Music.
(Title, Artist, Producer, Genre, Year, Price, CD Quantity, Cassette Quantity, Sheet Music Quantity, MID, VID) .
VALUES .
('Rock Hits', 'ACDC', 'Rocafella', 'Rock', '1989', '11.00', '7', '5 ', '1', '4', '2');
$sql = INSERT INTO Music.
(Title, Artist, Producer, Genre, Year, Price, CD Quantity, Cassette Quantity, Sheet Music Quantity, MID, VID) .
VALUES .
('Jazz Masterpiece', 'Jazzy J', 'Jazz Bros', 'Jazz', '1990', '1', '5 ', '15.00', '2', '5', '1');
Lastly I add some action Statements;
DELETE FROM Music
WHERE Title='Classic Jazz' AND Artist='Cole Train' AND Producer='Jazz inc.' AND Genre = 'Jazz' AND Year='1992' AND Price='8.00' AND CD Quantity='5'AND Cassette Quantity= '3' AND Sheet MusicQuantity='4' AND VID='1';
UPDATE Music
SET Title='Rockhits', Artist='The Beats', Producer='RockProductions', Genre='rock', Year='1977', Price='12.25', CD Quantity='2', Cassette Quantity='5', Sheet Music Quantity='2', VID='2'
WHERE MID='3';
SELECT SUM(CD Quantity)
-> FROM Music;
SELECT SUM(Cassette Quantity)
-> FROM Music;
SELECT SUM(Sheet Music Quantity)
-> FROM Music;
My question is does the setup look right or should my action statements have some sort of separation, weather it be via bracketing/headers or another organizational manor?