我正在尝试填充数据库的字段,无论我如何更改小数值,我都会遇到错误。我将我的小数第一个设置为(2,2)然后我将其更改为(4,2) - 这是在我得到一些反馈并做了一些研究之后。任何帮助都会很感激。谢谢。
我的插入声明:
INSERT INTO Ingredient(Name, Price)
values ('Chocolate', '10.50');
数据库:
-- MySQL Workbench Forward Engineering
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 BrendaStore
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `BrendaStore` ;
-- -----------------------------------------------------
-- Schema BrendaStore
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `BrendaStore` DEFAULT CHARACTER SET utf8 ;
SHOW WARNINGS;
USE `BrendaStore` ;
-- -----------------------------------------------------
-- Table `Vendor`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Vendor` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `Vendor` (
`idVendor` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(45) NOT NULL,
`Address` VARCHAR(45) NOT NULL,
PRIMARY KEY (`idVendor`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `Shop`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Shop` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `Shop` (
`idShop` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(45) NOT NULL,
`Address` VARCHAR(45) NOT NULL,
`PhoneNumber` VARCHAR(45) NOT NULL,
PRIMARY KEY (`idShop`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `Product`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Product` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `Product` (
`idProduct` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(45) NOT NULL,
`ProductPrice` DECIMAL(4,2) NOT NULL,
`Shop_idShop` INT NOT NULL,
PRIMARY KEY (`idProduct`),
INDEX `fk_Product_Shop1_idx` (`Shop_idShop` ASC),
CONSTRAINT `fk_Product_Shop1`
FOREIGN KEY (`Shop_idShop`)
REFERENCES `Shop` (`idShop`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `Recipe`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Recipe` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `Recipe` (
`idRecipe` INT NOT NULL AUTO_INCREMENT,
`IngredientAmount` VARCHAR(45) NOT NULL,
`Product_idProduct` INT NOT NULL,
PRIMARY KEY (`idRecipe`),
INDEX `fk_Recipe_Product1_idx` (`Product_idProduct` ASC),
CONSTRAINT `fk_Recipe_Product1`
FOREIGN KEY (`Product_idProduct`)
REFERENCES `Product` (`idProduct`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `Ingredient`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Ingredient` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `Ingredient` (
`idIngredient` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(45) NOT NULL,
`Price` DECIMAL(2,2) NOT NULL,
`Vendor_idVendor` INT NOT NULL,
`Recipe_idRecipe` INT NOT NULL,
`Product_idProduct` INT NOT NULL,
PRIMARY KEY (`idIngredient`),
INDEX `fk_Ingredient_Vendor_idx` (`Vendor_idVendor` ASC),
INDEX `fk_Ingredient_Recipe1_idx` (`Recipe_idRecipe` ASC),
INDEX `fk_Ingredient_Product1_idx` (`Product_idProduct` ASC),
CONSTRAINT `fk_Ingredient_Vendor`
FOREIGN KEY (`Vendor_idVendor`)
REFERENCES `Vendor` (`idVendor`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Ingredient_Recipe1`
FOREIGN KEY (`Recipe_idRecipe`)
REFERENCES `Recipe` (`idRecipe`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Ingredient_Product1`
FOREIGN KEY (`Product_idProduct`)
REFERENCES `Product` (`idProduct`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `Client`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Client` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `Client` (
`idClient` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(45) NOT NULL,
`PhoneNumber` VARCHAR(45) NOT NULL,
`Email` VARCHAR(45) NOT NULL,
PRIMARY KEY (`idClient`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `Purchase`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Purchase` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `Purchase` (
`idPurchase` INT NOT NULL AUTO_INCREMENT,
`PurchaseDate` DATETIME NOT NULL,
`PurchaseAmount` DECIMAL(2,2) NOT NULL,
`Client_idClient` INT NOT NULL,
PRIMARY KEY (`idPurchase`),
INDEX `fk_Purchase_Client1_idx` (`Client_idClient` ASC),
CONSTRAINT `fk_Purchase_Client1`
FOREIGN KEY (`Client_idClient`)
REFERENCES `Client` (`idClient`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `Orders`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Orders` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `Orders` (
`idOrders` INT NOT NULL AUTO_INCREMENT,
`Date` DATETIME NOT NULL,
`Quantity` VARCHAR(45) NOT NULL,
`Price` VARCHAR(45) NOT NULL,
PRIMARY KEY (`idOrders`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `Employee`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Employee` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `Employee` (
`idEmployee` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(45) NOT NULL,
`Address` VARCHAR(45) NOT NULL,
`PhoneNumber` VARCHAR(45) NOT NULL,
PRIMARY KEY (`idEmployee`))
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `Shop_has_Employee`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Shop_has_Employee` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `Shop_has_Employee` (
`Shop_idShop` INT NOT NULL,
`Employee_idEmployee` INT NOT NULL,
PRIMARY KEY (`Shop_idShop`, `Employee_idEmployee`),
INDEX `fk_Shop_has_Employee_Employee1_idx` (`Employee_idEmployee` ASC),
INDEX `fk_Shop_has_Employee_Shop1_idx` (`Shop_idShop` ASC),
CONSTRAINT `fk_Shop_has_Employee_Shop1`
FOREIGN KEY (`Shop_idShop`)
REFERENCES `Shop` (`idShop`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Shop_has_Employee_Employee1`
FOREIGN KEY (`Employee_idEmployee`)
REFERENCES `Employee` (`idEmployee`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `Ingredient_has_Orders`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Ingredient_has_Orders` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `Ingredient_has_Orders` (
`Ingredient_idIngredient` INT NOT NULL,
`Orders_idOrders` INT NOT NULL,
PRIMARY KEY (`Ingredient_idIngredient`, `Orders_idOrders`),
INDEX `fk_Ingredient_has_Orders_Orders1_idx` (`Orders_idOrders` ASC),
INDEX `fk_Ingredient_has_Orders_Ingredient1_idx` (`Ingredient_idIngredient` ASC),
CONSTRAINT `fk_Ingredient_has_Orders_Ingredient1`
FOREIGN KEY (`Ingredient_idIngredient`)
REFERENCES `Ingredient` (`idIngredient`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Ingredient_has_Orders_Orders1`
FOREIGN KEY (`Orders_idOrders`)
REFERENCES `Orders` (`idOrders`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SHOW WARNINGS;
-- -----------------------------------------------------
-- Table `Product_has_Purchase`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Product_has_Purchase` ;
SHOW WARNINGS;
CREATE TABLE IF NOT EXISTS `Product_has_Purchase` (
`Product_idProduct` INT NOT NULL,
`Purchase_idPurchase` INT NOT NULL,
PRIMARY KEY (`Product_idProduct`, `Purchase_idPurchase`),
INDEX `fk_Product_has_Purchase_Purchase1_idx` (`Purchase_idPurchase` ASC),
INDEX `fk_Product_has_Purchase_Product1_idx` (`Product_idProduct` ASC),
CONSTRAINT `fk_Product_has_Purchase_Product1`
FOREIGN KEY (`Product_idProduct`)
REFERENCES `Product` (`idProduct`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Product_has_Purchase_Purchase1`
FOREIGN KEY (`Purchase_idPurchase`)
REFERENCES `Purchase` (`idPurchase`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SHOW WARNINGS;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;