關於access資料庫裡的AutoNumber欄位類型的…

來源:互聯網
上載者:User

今天遇到一個Access的問題:如何直接利用一條直接修改的SQL語句來讓我的表中AutoNumber的類型的欄位重新排列一遍呢?大家都知道對於AutoNumber類型的欄位,當delete一條記錄後再insert一條,那麼AutoNumber會繼續加1,所以有過刪除記錄的表的AutoNumber欄位總是不能連續的,今天想把他們弄成連續的,搞了半天,除非用把這個表匯出到另一張表,重建立一個AutoNumber欄位來實現外,還真找不出能直接修改的辦法。

另外,記錄一下,建立一個帶有自動增加類型的欄位的SQL語句是:
CREATE TABLE tblUserInfo(user_id AUTOINCREMENT);
這樣用可以定義init和step的值:
CREATE TABLE tblUserInfo(user_id AUTOINCREMENT(200,50));
用Counter來替換AutoIncrement也可以。
如果想修改這個表的自動增加欄位的init和step值時可以這樣:
ALTER TABLE tblOrder ALTER COLUMN OrderId COUNTER (2000, 50);
但是如果我想單獨的增加init或step值該怎麼寫呢?

其他的:
Please realize that Jet won't prevent you from altering AutoNumber seed and increment values that produce duplicate values. However, if the AutoNumber column has been designated as the primary key or it contains a unique index, you will be prevented from saving rows with duplicates.

  //增加一個自動成長的欄位
  ADOX.ColumnClass col = new ADOX.ColumnClass();
col.ParentCatalog = cat;
col.Type=ADOX.DataTypeEnum.adInteger; // 必須先設定欄位類型
col.Name = "id";
col.Properties["Jet OLEDB:Allow Zero Length"].Value= false;
col.Properties["AutoIncrement"].Value= true;
tbl.Columns.Append (col,ADOX.DataTypeEnum.adInteger,0);

關於用ADOX建立ACCESS資料庫和表的方法:
http://blog.csdn.net/net_lover/archive/2004/06/08/6963.aspx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.