MySQL PHPMyAdmin 上的 SQL 查询插入数据不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15137569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL query on PHPMyAdmin to insert data not working
提问by kiran patel
Following is my SQL query:
以下是我的 SQL 查询:
Attempt 1
尝试 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.`)
Attempt 2
尝试 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.`)
I keep getting an error of : MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0003 sec )
我不断收到以下错误: MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0003 sec )
I don't understand what am i doing wrong. Here is my column name list
我不明白我做错了什么。这是我的列名列表
1 productid int(11)
2 title varchar(100)
3 category varchar(100)
4 description varchar(2000)
table name:product
表名:产品
回答by ppeterka
For the values, use the '
character, not this one: ``` (sorry, I'll have to find out how to put a single backtick into an inline code block in Markdown...)
对于值,使用'
字符,而不是这个:```(抱歉,我必须找出如何在 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.')
And this should work... Here is the SQLfiddle for it.
这应该工作......这是它的SQLfiddle。
EDITThis is the solution as per zour table definition:
编辑这是根据 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.')
You had two things you forgot to mention:
* productid
is a PRIMARY KEY
(and hence, automatically NOT NULL
) column -- any inserts with a NULL
in that column will fail
* productid
is an AUTO_INCREMENT
column -- you don't even have to include it in the INSERT
statement, it will get filled with an unique value each time you insert a row
您有两件事忘了提及:*productid
是PRIMARY KEY
(因此,自动NOT NULL
)列——NULL
在该列中插入任何带有 a的内容都将失败 *productid
是一AUTO_INCREMENT
列——您甚至不必将它包含在INSERT
语句中,它每次插入一行时都会填充一个唯一值
回答by puchmu
You have to use '
with every varchar
, datatype, so in your case:
您必须使用'
every 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.'
);