John
John

Reputation: 4533

SQL Update Query help

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;

Upvotes: 0

Views: 84

Answers (4)

Marco
Marco

Reputation: 57583

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...

Upvotes: 3

xdazz
xdazz

Reputation: 160863

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

Upvotes: 0

Grant Barrington
Grant Barrington

Reputation: 1

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'); 

Upvotes: 0

Mouli
Mouli

Reputation: 1651

"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');

Upvotes: 0

Related Questions