尝试在 mysql 上开设课程,关注视频和文字。从我的想法来看,我一直在完美地遵循它,但是当我尝试将数据插入表时出现很多错误。
这是我的代码:
-- 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);
关于为什么我应该在插入数据时出现错误,有什么特别明显的吗?
这是我特别遇到错误的地方: