2012-05-16 66 views
0

我是sql新手。我正在寫基於數據的查詢在mysql中更新需要好聲明

如何寫查詢來更新行;我想遵循這種格式;

UPDATE `reports_attributes` 
    (`ConID`,`CheckServices`,`Attribute1`,`Attribute2`,`Attribute3`,`Attribute4`,`Attribute5`,`Attribute6`,`Attribute7`,`Attribute8`) 
VALUES ('78','Execute Summary','criminality','color1','education','color5','employment_check_2','color7','report_status','color9') 
WHERE ConID=78 AND ReportType='interim_report' 
+1

您的查詢出了什麼問題? –

+0

你不應該引用數字,'ConID''78'應該只是78 – vimist

+0

@ Chief17不會有任何影響 - mysql只是強制類型來匹配列定義。 – AD7six

回答

2

更新語句語法與插入不同。

UPDATE reports_attributes 
Set 
ConID='78', 
CheckServices='Execute Summary', 
Attribute1='criminality', 
Attribute2='color1', 
Attribute3='education', 
Attribute4='color5', 
Attribute5='employment_check_2', 
Attribute6='color7', 
Attribute7='report_status', 
Attribute8='color9' 
WHERE ConID=78 AND ReportType='interim_report' 
1

一個UPDATE語句的語法是

UPDATE reports_attributes 
    SET ConID = 78, 
     CheckServices = xxx, 
     . 
     . 
     n 
WHERE ConID=78 AND ReportType='interim_report' 
1

在問題中的語法不匹配有效更新語句的syntax of an update statement

UPDATE [LOW_PRIORITY] [IGNORE] table_reference 
    SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ... 
    [WHERE where_condition] 
    [ORDER BY ...] 
    [LIMIT row_count] 

一個例子:

UPDATE mytable 
SET 
    foo = "bar" 
WHERE 
    id = 123 
1
UPDATE reports_attributes 
SET ConID='78', 
    CheckServices='Execute Summary' , 
    Attribute1='criminality', 
    Attribute2='color1', 
    Attribute3='education', 
    Attribute4='color5', 
    Attribute5='employment_check_2', 
    Attribute6='color7', 
    Attribute7='report_status', 
    Attribute8='color9' 
WHERE ConID=78 
     AND ReportType='interim_report'