Cannot update identity column 'XXX',identitycolumn

來源:互聯網
上載者:User

Cannot update identity column 'XXX',identitycolumn

Sqlserver -- 如何修改設定主鍵的id可以手動更新?

#1 開啟表的設計介面

#2 將主鍵id的is Identity的屬性改成No

這樣就可以通過Update語句來更新表的主鍵id了。

如何重新設定主鍵id的自增長開始值呢?

#1 命令:DBCC CHECKIDENT (tableName, reseed, 1000000)

#2 DBCC:

DBCC help('?') 查看所有的dbcc命令

DBCC HELP('checkdb') 查看單個命令的詳細


update 表A set xxx=(select xxx from 表B where Axxx=xxx and Ayyy=yyy)

舉例子的話,不要用這麼拗口的表名和欄位名了就,最好給UPDATE後的表也起個別名,
不過這個SQL寫的確實不錯。
 
資料更改:根據id更改多條資料,是1條1條的更改,還是update tablename set XXX=xxx where id in(?)

in代表這條語句同時處理一批資料
而分別執行update語句效率相比要低很多
結果是一樣的,但是注意在這個事務執行要進行表的鎖定,不然別人也操作這個表容易出問題
 

相關文章

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.