diff --git a/update.php b/update.php
index bfb9382206ed5fc4331b71c1bc2c029aa9d29606..a67b923d2c6e3acb6a2fe67de260cba59ba45fb2 100644
--- a/update.php
+++ b/update.php
@@ -51,7 +51,8 @@
   "2002-08-16" => "update_36",
   "2002-08-19" => "update_37",
   "2002-08-26" => "update_38",
-  "2002-09-15" => "update_39"
+  "2002-09-15" => "update_39",
+  "2002-09-17" => "update_40"
 );
 
 // Update functions
@@ -581,6 +582,12 @@ function update_39() {
   );");
 }
 
+function update_40() {
+  if ($max = db_result(db_query("SELECT MAX(cid) FROM comments;"))) {
+    update_sql("REPLACE INTO sequences VALUES ('comments', $max);");
+  }
+}
+
 function update_upgrade3() {
   update_sql("INSERT INTO system VALUES ('archive.module','archive','module','',1);");
   update_sql("INSERT INTO system VALUES ('block.module','block','module','',1);");