Der Versuch, einen Kurs auf mysql, folgenden Videos und Text zu tun. Von dem, was ich dachte, habe ich es perfekt verfolgt, aber ich bekomme viele Fehler, wenn ich versuche, Daten in Tabellen einzufügen.MySQL Fehler 1062 und 1452 beim Einfügen von Daten in Tabellen
Hier ist mein Code:
-- MyExercises
CREATE DATABASE MyExercises;
USE MyExercises;
CREATE TABLE Categories
(CategoryID INT NOT NULL,
CategoryName VARCHAR(20) NOT NULL,
Description TEXT NULL,
PRIMARY KEY (CategoryID))
ENGINE = InnoDB;
SHOW COLUMNS FROM Categories;
DESC Categories;
CREATE TABLE Suppliers
(City VARCHAR(20) NULL,
CompanyName VARCHAR(30) NOT NULL,
SupplierID INT NOT NULL,
PRIMARY KEY (SupplierID))
ENGINE = InnoDB;
CREATE TABLE Products
(ProductID INT NOT NULL,
ProductName VARCHAR(40) NOT NULL,
CategoryID INT NULL,
SupplierID INT NULL,
UnitPrice DECIMAL(5,2) NULL,
UnitsInStock SMALLINT NULL,
PRIMARY KEY (ProductID),
FOREIGN KEY (CategoryID) REFERENCES Categories(CategoryID))
ENGINE = INNODB;
INSERT INTO Categories (CategoryID, CategoryName, Description)
VALUES (1, 'Beverages', 'Soft drinks, coffees, teas, beers, and ales');
INSERT INTO Categories (CategoryID, CategoryName, Description)
VALUES (2, 'Condiments', 'Sweet and savory sauces');
INSERT INTO Categories (CategoryID, CategoryName, Description)
VALUES (3, 'Confections', 'Desserts, candies, and sweet breads');
INSERT INTO Categories (CategoryID, CategoryName, Description)
VALUES (4, 'Dairy Products', 'Cheese, Milk, Cream');
INSERT INTO Suppliers (SupplierID, CompanyName, City)
VALUES (1, 'Exotic Liquids', 'London');
INSERT INTO Suppliers (SupplierID, CompanyName)
VALUES (2, 'New Orleans Cajun Delights');
INSERT INTO Suppliers (SupplierID, CompanyName, City)
VALUES (3, 'Grandma Kelly''s Homestead', 'Adelaide');
INSERT INTO Suppliers (SupplierID, CompanyName)
VALUES (4, 'Tokyo Traders');
INSERT INTO Products (ProductID, ProductName, SupplierID, CategoryID, UnitPrice, UnitsInStock)
VALUES (1, 'Chai', 1, 1, 18, 39);
INSERT INTO Products (ProductID, ProductName, SupplierID, UnitPrice, UnitsInStock)
VALUES (2, 'Chang', 1, 19, 17);
INSERT INTO Products (ProductID, ProductName, CategoryID, UnitPrice, UnitsInStock)
VALUES (3, 'Ani Seed Syrup', 2, 10, 13);
INSERT INTO Products (ProductID, ProductName, SupplierID, CategoryID, UnitPrice)
VALUES (4, 'Chef Anton''s Cajun Seasoning', 2, 2, 22);
INSERT INTO Products (ProductID, ProductName, SupplierID, CategoryID, UnitsInStock)
VALUES (5, 'Chef Anton''s Gumbo Mix', 2, 2, 0);
INSERT INTO Products (ProductID, ProductName, SupplierID, CategoryID)
VALUES (6, 'Grandma''s Boysenberry Spread', 3, 2);
INSERT INTO Products (ProductID, ProductName, SupplierID, CategoryID, UnitPrice, UnitsInStock)
VALUES (7, 'Uncle Bob''s Organic Dried Pears', 5, 4, 30, 15);
INSERT INTO Products (ProductID, ProductName, SupplierID, CategoryID, UnitPrice, UnitsInStock)
VALUES (8, 'Northwood''s Cranberry Sauce', 4, 5, 40, 6);
Ist alles da, daß ich immer Fehler Einfügen von Daten bilden, wie bleedingly offensichtlich, warum sticht?
Hier ist, wo ich Fehler speziell bin immer:
Viele der Fehler sind Dinge sagen Fehlercode 1062 für die Vervielfältigung und Fehlercode 1452.
Leeren Sie die Tabellen und versuchen Sie es erneut. Diese Schlüsselwerte befinden sich bereits in der Datenbank. Berücksichtigen Sie auch, dass id als auto_increment festgelegt wird. –
versuchen Sie Kleinbuchstaben Version der Tabellen für einen Start –
Sobald Sie beginnen, sauber, wie oben vorgeschlagen, müssen Sie auch Ihre '' CategoryID' Wert der letzten 'einfügen' Anweisung zu respektieren die Fremdschlüssel-Einschränkung. – sstan