English 中文(简体)
如何更新数据库中的栏目记录?
原标题:How to update column records in database?

I m试图在数据库内一栏中更新记录。 我目前的法典如下:

curs = conn.cursor()
statement= SELECT column FROM table 
curs.execute(statement)
curs.execute("INSERT INTO table VALUES (4,  Five )")

In my understanding, the 4th row of the column should be updated to Five . After I ran it, there is no error, but no update neither. There must be something wrong in my codes, or I m missing something important. What if I want to update the whole column s records? Thanks in advance for any clarification.

最佳回答

我用以下法典解决了我的问题:

conn = psycopg2.connect(conn_string)
curs = conn.cursor()
statement= UPDATE table SET column = false 
curs.execute(statement)
conn.commit()
conn.close()

你们的帮助

问题回答
update `table_name` set `column_name` = value 

虽然你想要使核查组相信,你会试图将新一栏的数值中的所有段落加以更新,否则,你需要增加。

where `unique_key` = unique_value 

根据你使用MSSQL、Oracle、MySQL的版本,你需要不同的辛加税。 你们喜欢再次使用劳动和社会保障部,因此,你希望从此开始:

UPDATE table SET column = "Five"

但你只能说第4行至X射线,没有像Excel电子表格这样固定的流量。 你希望增加一栏,把它称为PK——表名,把它定为表上的主要关键。 然后,你可以作类似发言,并总是更新正确的行文:

UPDATE table SET column = "Five" WHERE PK_tablename = 4

我建议阅读一下你帮助的“小学钥匙”。

<编码>insert/code>没有更新数据库中的数值,而是增加了记录。 页: 1

页: 1 正如其他人所说的那样,这将添加记录而不是更新记录。

基本上有4项简单查询的基本业务:

  • SELECT: Use this to view data. JOIN tables, set a WHERE clause, etc. to manipulate the view of the data. This is the safest operation (though a bad SELECT can bring a server s performance to its knees).
  • INSERT: This will insert a row into the table. It s fairly safe, as it doesn t change any existing data.
  • UPDATE: This will update one or _more_ rows in the table. The main thing to worry about here is the WHERE clause. If you don t include one, you will update every row in the table. Generally you want to test your WHERE clause in a SELECT statement first to make absolutely sure you re updating only the rows you want to update.
  • DELETE: This is, naturally, the most dangerous. Again, without a WHERE clause it will delete all rows in the table. Test your WHERE clause to make sure you re deleting only the rows you want to delete.

根据您的<代码>INSERT说明,你似乎重新尝试根据钥匙(号码4)更新一行。 由于缺乏错误,这似乎实际上不是一个关键因素。 如果该表是关键,它本会再回一个错误,说你可以插入一条带有重复钥匙的行文。

seems (根据有关信息的有限,自然)你想要的是:

UPDATE table SET column =  five  WHERE id = 4

详情见here





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签