遍歷含有標識列的表

2021-05-22 17:06:01 字數 432 閱讀 7901

declare @identitycolumn int --記錄當前要修改的標識列

select @identitycolumn=min(identitycolumn) from tablename

while @identitycolumn is not null --遍歷修改標識列

begin

update tablename

set identitycolumn=identitycolumn*2 --比如修改標識列為原來的2倍,也可修改其他列

where identitycolumn=@identitycolumn

select @identitycolumn=min(identitycolumn) from tablename

where identitycolumn>@identitycolumn

end

標識列和普通列的轉換

建立測試表 create table t1 id intidentity a int go 插入記錄 insert t1 values 1 go 1.將identity 標識 列變為普通列 alter table t1 add id temp intgo update t1 set id temp ...

資料表的完整性和標識列

每個表中有乙個必須要指定的字段,主要依賴主鍵約束 針對表中的某個字段進行特殊化限制,主要依賴剩餘的約束 表與表之間的一種特殊化關聯限制,主要依靠外來鍵約束 什麼是約束 使用約束 鍵的作用來維護資料表的完整性 約束有哪些 自增約束 非空約束 檢查約束 預設約束 唯一約束 主鍵約束 外來鍵約束 一般在設...

Oracle中為表設定自動增長的標識列

建立序列 create sequence 序列名稱 start with 1 起始值 increment by 1 增量 maxvalue 99999999 最大值 nocycle 達到最大值後是否重新計算,當前為不重新計算,cycle為重新計算 nocache 不要快取,容易跳號 建立觸發器 cr...