我有一个现有的表,它使用自动递增的 import javax.swing.*;
import java.io.File;
import org.w3c.dom.Document;
import org.w3c.dom.*;
import java.awt.*;
import java.awt.event.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class MasterScreen{
public static void main (String argv []){
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new File("MasterXML.xml"));
System.out.println("Siri");
doc.getDocumentElement ().normalize ();
System.out.println("Siriri");
}
catch (SAXParseException err) {
System.out.println ("** Parsing error" + ", line " + err.getLineNumber () + ", uri " + err.getSystemId ());
System.out.println(" " + err.getMessage ());
}catch (SAXException e) {
Exception x = e.getException ();
((x == null) ? e : x).printStackTrace ();
}catch (Throwable t) {
t.printStackTrace ();
}
}
}
作为主键。
表中有条目,其id从1开始:
id
有没有办法更新所有现有条目的id field1
== ======
1 foo1
2 foo2
3 foo3
,以便auto_increment从另一个号码开始?:
id
(如果不可能,则不一定要保留订单)
答案 0 :(得分:3)
您可以使用update
更改值,alter table
将自动增量更新为新值:
alter table t set auto_increment = 1003; -- the next value
update t
set id = id + 999;
答案 1 :(得分:1)
在Sql Server中它是可行的,MySql我不确定
DECLARE @NewRowId int = 998;
DBCC CHECKIDENT('MyTableName', RESEED, @NewRowId)