1

以下是我的 SQL 查询:

尝试 1

INSERT INTO `product`(`productid`, `title`, `category`, `description`) 
VALUES (NULL,`iMac`,`Desktop`,`With its enhanced, big and beautiful display, the new Apple iMac M-D093-B/A 21.5 Desktop Computer renders your movies, photos, web pages and other graphics in truly jaw-dropping detail.`)

尝试 2

INSERT INTO `product`(`productid`, `title`, `category`, `description`) 
VALUES(` `,`iMac`,`Desktop`,`With its enhanced, big and beautiful display, the new Apple iMac M-D093-B/A 21.5 Desktop Computer renders your movies, photos, web pages and other graphics in truly jaw-dropping detail.`)

我不断收到以下错误:MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0003 sec )

我不明白我在做什么错。这是我的列名列表

1  productid int(11)    
2  title varchar(100)
3  category varchar(100)
4  description varchar(2000) 

表名:产品

4

2 回答 2

4

对于值,使用'字符,而不是这个字符:```(对不起,我必须找出如何在 Markdown 中将单个反引号放入内联代码块中......)

INSERT INTO `product`(`productid`, `title`, `category`, `description`) 
VALUES (NULL,'iMac','Desktop','With its enhanced, big and beautiful display, the new Apple iMac M-D093-B/A 21.5 Desktop Computer renders your movies, photos, web pages and other graphics in truly jaw-dropping detail.')

这应该工作......这是它的SQLfiddle

编辑 这是根据 zour 表定义的解决方案:

INSERT INTO `product`(`title`, `category`, `description`) 
VALUES ('iMac','Desktop','With its enhanced, big and beautiful display, the new Apple iMac M-D093-B/A 21.5 Desktop Computer renders your movies, photos, web pages and other graphics in truly jaw-dropping detail.')

您有两件事忘记提及: *productidPRIMARY KEY(因此,自动NOT NULL)列 - 在该列中带有 a 的任何插入NULL都将失败 *productid是一AUTO_INCREMENT列 - 您甚至不必将它包含在INSERT语句中,它每次插入一行时都会填充一个唯一值

用于此的 SQL 小提琴

于 2013-02-28T14:12:09.797 回答
0

您必须使用'每个varchar数据类型,因此在您的情况下:

INSERT INTO product(productid, title, category, description) VALUES 
(
    NULL,
    'iMac',
    'Desktop', 
    'With its enhanced, big and beautiful display, the new Apple iMac M-D093-B/A 21.5 Desktop Computer renders your movies, photos, web pages and other graphics in truly jaw-dropping detail.'
);
于 2013-02-28T14:12:23.793 回答