What's the differences between these 2 queries to publish/unpublish nodes? I found these 2 queries to publish or unpublish a node programmatically:

db_query("UPDATE {node} SET `status` = '1' WHERE `nid` =:nid ;"
    ,array(':nid'=&gt;$node-&gt;nid));

db_query("UPDATE {node_revision} SET `status` = '1' WHERE `nid` =:nid AND  `vid` =:vid;"
    ,array(':nid'=&gt;$node-&gt;nid,'vid'=&gt; $node-&gt;vid));


I do not understand the difference, and not sure which one use.

Any suggestions?
Let me explain you with all details....

Your First Query is update statement on node table in drupal database which sets node to publish for a particular nid...

db_query("UPDATE {node} SET `status` = '1' WHERE `nid` =:nid ;"
    ,array(':nid'=&gt;$node-&gt;nid));


Node table is a base table which stores node related information..

Your Second Query is on node_revision table which stores node revisions if you track node revisions which are nothing but updates...

db_query("UPDATE {node_revision} SET `status` = '1' WHERE `nid` =:nid AND  `vid` =:vid;"
    ,array(':nid'=&gt;$node-&gt;nid,'vid'=&gt; $node-&gt;vid));


It's discouraged in Drupal to run queries directly on Drupal for certain actions.. For example in your case you are updating a node and setting status to published.. Drupal works using concept of hooks which are events and actions.. If any module is implementing any node related hooks they won't fire if you run queries directly.. So it's discouraged..

Right way of doing above action is using node_save api function in Drupal 7...

$node = node_load($nid);
$node-&gt;status = 1;
node_save($node);