当我尝试生成整个代码时,我收到错误代码 1050 表“sakila.jrey_author”已存在,当我尝试单独生成报告时,它可以工作,但它只生成表中列的名称。 (免责声明:这些不是表格的原始名称,我对其中的一些个人信息感到不舒服)
create table sakila.jrey_author (
author_id int,
author_name VARCHAR(50),
dateofbirth DATE,
nationality VARCHAR(56)
);
create table sakila.jrey_books(
bookID int,
title VARCHAR(50),
IBSN INT,
genreID INT,
publicationyear INT,
numAvailable INT,
AuthorID INT,
PublisherID INT
);
create table sakila.jrey_member(
memberID INT,
membername varchar(50),
age INT,
address varchar(25),
phonenumber int,
email varchar(61)
);
create table sakila.jrey_borrowedbooks(
title varchar(60),
bookID int,
duedate DATE,
transactionID int
);
create table sakila.jrey_transaction(
transactionID int,
transactiondate DATE,
memberID int,
bookID int,
duedate DATE,
status varchar(8)
);
insert into sakila.jrey_author (author_id, author_name, dateofbirth ,nationality) Values
('12','J.K. Rowlin','7/31/1965','British'),
('45','Stephen King','9/21/1947','American'),
('78','Jane Austen','12/16/1775','British'),
('32','George Orwell','6/25/1903','British'),
('23','Agatha Christie','9/15/1890','British'),
('56','Ernest Hemingway','7/21/1899','American');
insert into sakila.jrey_books values
('21',"Harry Potter and the Sorcerer's Stone",'978-0439708180','1','1997','5','12'),
('78','The Shining','978-0307743657','2','1977','3','45'),
('34','Pride and Prejudice','978-0141439518','3','1813','2','78'),
('54','1984','978-0451524935','4','1949','8','32'),
('67','Murder on the Orient Express','978-0062073495','5','1934','4','23'),
('98','The Old Man and the Sea','978-0684801223','6','1952','7','56');
insert into sakila.jrey_member values
('34','John Moe','25','123 Main St, City','555-1234','[email protected]'),
('45','Jane Smith','30','456 Oak St, Town','555-5678','[email protected]'),
('56','Bob Johnson','40','789 Elm St, Village','555-9101','[email protected]'),
('67','Sarah Williams','28','321 Pine St, Hamlet','555-1212','[email protected]'),
('78','Michael Brown','35','654 Cedar St, County','555-3434','[email protected]'),
('98','Emily Davis','42','987 Maple St, Village','555-5656','[email protected]');
insert into sakila.jrey_borrowedbooks values
("Harry Potter and the Sorcerer's Stone",'21','4/3/2024','12'),
('The Shining','78','4/5/2024','67'),
('Pride and Prejudice','34','4/6/2024','56'),
('1984','54','4/7/2024','23'),
('Murder on the Orient Express','67','4/8/2024','78'),
('The Old Man and the Sea','98','4/9/2024','45');
insert into sakila.jrey_transaction values
('12','3/20/2024','45','21','4/3/2024','Borrowed'),
('67','3/21/2024','34','78','4/5/2024','Returned'),
('56','3/22/2024','98','34','4/6/2024','Borrowed'),
('23','3/23/2024','21','54','4/7/2024','Borrowed'),
('78','3/24/2024','12','67','4/8/2024','Returned'),
('45','3/25/2024','67','98','4/9/2024','Borrowed');
SELECT *
FROM sakila.jrey_author;
SELECT *
FROM sakila.jrey_books;
SELECT *
FROM sakila.jrey_member;
SELECT *
FROM sakila.jrey_borrowedbooks;
SELECT *
FROM sakila.jrey_transaction;
我尝试查看是否错误地插入了数据,因此我通过在值之前添加列的全名来更改“插入表名称值”,但它给了我相同的结果。
Sakila 是由 Mike Hillyer 开发的 MySQL 示例数据库。
查看 MySQL 文档了解详细信息。
您收到错误:
Error Code 1050 table 'sakila.jrey_author' already exist
因为您没有删除现有的
Sakila
数据库表。
所以,先删除表,然后创建 使用顶部的查询:
DROP TABLE IF EXISTS sakila.jrey_author;
DROP TABLE IF EXISTS sakila.jrey_books;
DROP TABLE IF EXISTS sakila.jrey_member;
DROP TABLE IF EXISTS jrey_borrowedbooks;
DROP TABLE IF EXISTS sakila.jrey_transaction;
接下来更正您的数据。我发现有很多数据问题如下:
MM/DD/YYYY
到 YYYY-MM-DD
(标准格式)的正确日期格式。sakila.jrey_books
表的列 PublisherID INT
数据在 insert query
中不可用(检查图像)好的,我做了一些正确的事情并且它工作正常。 这是完整的代码:
USE sakila;
DROP TABLE IF EXISTS sakila.jrey_author;
DROP TABLE IF EXISTS sakila.jrey_books;
DROP TABLE IF EXISTS sakila.jrey_member;
DROP TABLE IF EXISTS jrey_borrowedbooks;
DROP TABLE IF EXISTS sakila.jrey_transaction;
create table sakila.jrey_author (
author_id int,
author_name VARCHAR(50),
dateofbirth DATE,
nationality VARCHAR(56)
);
create table sakila.jrey_books(
bookID int,
title VARCHAR(50),
IBSN VARCHAR(20),
genreID INT,
publicationyear INT,
numAvailable INT,
AuthorID INT
-- PublisherID INT
);
create table sakila.jrey_member(
memberID INT,
membername varchar(50),
age INT,
address varchar(25),
phonenumber varchar(20),
email varchar(61)
);
create table sakila.jrey_borrowedbooks(
title varchar(60),
bookID int,
duedate DATE,
transactionID int
);
create table sakila.jrey_transaction(
transactionID int,
transactiondate DATE,
memberID int,
bookID int,
duedate DATE,
status varchar(8)
);
insert into sakila.jrey_author (author_id, author_name, dateofbirth ,nationality) Values
(12,'J.K. Rowlin','1965-07-31','British'),
(45,'Stephen King','1947-09-21','American'),
(78,'Jane Austen','1775-12-16','British'),
(32,'George Orwell','1903-06-25','British'),
(23,'Agatha Christie','1890-09-15','British'),
(56,'Ernest Hemingway','1899-07-21','American');
insert into sakila.jrey_books values
(21,"Harry Potter and the Sorcerer's Stone",'978-0439708180',1,1997,5,12),
(78,'The Shining','978-0307743657',2,1977,3,45),
(34,'Pride and Prejudice','978-0141439518',3,1813,2,78),
(54,'1984','978-0451524935',4,1949,8,32),
(67,'Murder on the Orient Express','978-0062073495',5,1934,4,23),
(98,'The Old Man and the Sea','978-0684801223',6,1952,7,56);
insert into sakila.jrey_member values
(34,'John Moe',25,'123 Main St, City','555-1234','[email protected]'),
(45,'Jane Smith',30,'456 Oak St, Town','555-5678','[email protected]'),
(56,'Bob Johnson',40,'789 Elm St, Village','555-9101','[email protected]'),
(67,'Sarah Williams',28,'321 Pine St, Hamlet','555-1212','[email protected]'),
(78,'Michael Brown',35,'654 Cedar St, County','555-3434','[email protected]'),
(98,'Emily Davis',42,'987 Maple St, Village','555-5656','[email protected]');
insert into sakila.jrey_borrowedbooks values
("Harry Potter and the Sorcerer's Stone",21,'2024-04-03',12),
('The Shining',78,'2024-04-05',67),
('Pride and Prejudice',34,'2024-04-06',56),
('1984',54,'2024-04-07',23),
('Murder on the Orient Express',67,'2024-04-08',78),
('The Old Man and the Sea',98,'2024-04-09',45);
insert into sakila.jrey_transaction values
(12,'2024-03-20',45,21,'2024-04-03','Borrowed'),
(67,'2024-03-21',34,78,'2024-04-05','Returned'),
(56,'2024-03-22',98,34,'2024-04-06','Borrowed'),
(23,'2024-03-23',21,54,'2024-04-07','Borrowed'),
(78,'2024-03-24',12,67,'2024-04-08','Returned'),
(45,'2024-03-25',67,98,'2024-04-09','Borrowed');
SELECT *
FROM sakila.jrey_author;
SELECT *
FROM sakila.jrey_books;
SELECT *
FROM sakila.jrey_member;
SELECT *
FROM sakila.jrey_borrowedbooks;
SELECT *
FROM sakila.jrey_transaction;
谢谢你!!!