SQL 更新查询帮助

发布于 2024-12-03 09:05:04 字数 831 浏览 1 评论 0原文

我有一个名为“Subject_table”的表..我正在尝试更新该表中的一个字段....但我不断收到语法错误....不确定我做错了。表中的所有字段都是 VARCHAR(30) 类型

这是 queryString 的样子

queryString2 = "update "+tablename+" set tittle='"+tittle+"' , desc='"+desc+"', creditPoints='"+creditPoints+"' where cid='"+cid+"'";   

实际查询

UPDATE subject_table 
SET tittle='Subject 1', desc='Subject 1', creditPoints='5' 
WHERE cid='CSE11111';

我也有删除查询,效果很好...

非常感谢您的帮助..!!! 桌子

DROP TABLE IF EXISTS `dummy`.`subject_table`;
CREATE TABLE  `dummy`.`subject_table` (
  `cid` varchar(15) NOT NULL DEFAULT '',
  `tittle` varchar(45) NOT NULL DEFAULT '',
  `desc` varchar(550) NOT NULL DEFAULT '',
  `creditPoints` varchar(45) NOT NULL DEFAULT '',
  PRIMARY KEY (`cid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

I have a table called Subject_table.. I'm trying to update a field in that table.... but i keep getting a syntax error.... Not sure wad i'm doing wrong. All fields in the table are of type VARCHAR(30)

This is what the queryString looks like

queryString2 = "update "+tablename+" set tittle='"+tittle+"' , desc='"+desc+"', creditPoints='"+creditPoints+"' where cid='"+cid+"'";   

Actual query

UPDATE subject_table 
SET tittle='Subject 1', desc='Subject 1', creditPoints='5' 
WHERE cid='CSE11111';

I also have delete query which works fine...

Would appreciate the help..!!!
The table

DROP TABLE IF EXISTS `dummy`.`subject_table`;
CREATE TABLE  `dummy`.`subject_table` (
  `cid` varchar(15) NOT NULL DEFAULT '',
  `tittle` varchar(45) NOT NULL DEFAULT '',
  `desc` varchar(550) NOT NULL DEFAULT '',
  `creditPoints` varchar(45) NOT NULL DEFAULT '',
  PRIMARY KEY (`cid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

凉月流沐 2024-12-10 09:05:04

您确定 desc 未被识别为保留字吗?
也许我错了...

试试这个:

UPDATE subject_table 
SET tittle='Subject 1', `desc`='Subject 1', creditPoints='5' 
WHERE cid='CSE11111';

在删除查询中,您使用带引号的 desc...

Are you sure that desc is not recognized as a reserved word?
Maybe I'm wrong...

Try this:

UPDATE subject_table 
SET tittle='Subject 1', `desc`='Subject 1', creditPoints='5' 
WHERE cid='CSE11111';

In your delete query you use quoted desc...

说谎友 2024-12-10 09:05:04

“desc”是一个关键字。尝试将其放在方括号内,如下所示:

update subject_table set tittle='Subject 1' , [desc]='Subject 1', creditPoints='5' where cid=('CSE11111');

"desc" is a keyword. Try putting that within square brackets like this:

update subject_table set tittle='Subject 1' , [desc]='Subject 1', creditPoints='5' where cid=('CSE11111');
骄傲 2024-12-10 09:05:04

语法错误可能来自列名“desc”。

尝试转义此列,并从 where 子句中删除括号。

update subject_table set tittle='Subject 1' , [desc]='Subject 1', creditPoints='5' where cid=('CSE11111'); 

The syntax error might be coming from the column name "desc".

Try escaping this column, as well as removing the brackets from the where clause.

update subject_table set tittle='Subject 1' , [desc]='Subject 1', creditPoints='5' where cid=('CSE11111'); 
谜兔 2024-12-10 09:05:04

应该是where cid='CSE11111',而desc可能是你数据库的保留关键字,尝试用`引用它。

Should be where cid='CSE11111', and desc maybe the reserved keyword of your database, try to quote it by `.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文