以下是我的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)
表名:产品
答案 0 :(得分: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.')
这应该有用...... Here is the SQLfiddle for it。
修改强> 这是根据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.')
你有两件事你忘记提及:
* productid
是PRIMARY KEY
(因此,自动NOT NULL
)列 - 该列中NULL
的任何插入都将失败
* productid
是一个AUTO_INCREMENT
列 - 您甚至不必将其包含在INSERT
语句中,每次插入行时都会填充唯一值
答案 1 :(得分: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.'
);