自增列的基本操作
来源:互联网 发布:矩阵式键盘使用方法 编辑:程序博客网 时间:2024/05/22 03:29
/*自增列的基本操作[為已存在的列按自增值更新]*/--表if object_id('t') is not null drop table tgocreate table t(id int,col nvarchar(20))go--測試數據insert t select null,'test1'union all select null,'test2'union all select null,'test2'union all select null,'test1'go--第一種:按指定順序設置id(但只能更新原有数据,設置不了自增,不算)update tset id=t1.rn from (select row_number() over(order by col) rn,col from t)t1where t.col=t1.col;goselect * from t order by col;go--第二種:根據數據庫實際存儲數據設置自增idalter table t drop column id;alter table t add id int identity(1,1) not null;goselect * from t;go--第三種:根據自已設置的順序設置自增idif object_id('t_copy') is not null drop table t_copyselect col into t_copy from t order by col;truncate table t;alter table t drop column id;alter table t add id int identity(1,1) not null;insert into t(col) select col from t_copy;goselect * from t order by col;go--第四種:根據自已設置的順序設置自增id,且保持原列順序if object_id('t_copy') is not null drop table t_copyselect col into t_copy from t order by col;drop table t;select id=identity(int,1,1),col into t from t_copy;goselect * from t order by col;go
- 自增列的基本操作
- 关于自增列的操作
- 数据库列的基本操作
- SQL Server自增列(Identity列)的所有操作
- DB2的自增列 标识列
- 数据结构中队列的基本操作实现
- 散列操作的基本例程(1)
- 数据库的基本操作之多列添加
- 转自coolshell--vim的基本操作
- SQLServer数据库自增长标识列的更新修改操作
- SQLServer数据库自增长标识列的更新修改操作
- java操作access创建表的自增长列
- 表的自增列问题
- hibernate设置anywhere的自增列
- 关于Orcal 数据库的自增列
- mysql 自增列的创建
- 获得自增列的值
- 解决取得自增列的问题
- U盘在XP下不能格式化,WIN7下却可以使用.
- 和菜鸟一起学证券投资之消费物价指数CPI
- 简单的 数据库 and or 逻辑
- 设置VC6.0支持Unicode编程环境
- Linux API函数大全
- 自增列的基本操作
- ASP、php与flash通信,在As3.0中编码转换,让flash读取gb2312或Ascii或其他编码。
- 7 个超级震撼的 CSS3 按钮组合
- Memcached一些特性和限制
- C++之string类型详解
- EditPlus3.4 注册码
- 从源码中Activity 的定义来理解 Activity
- Android学习系列(29)--App调试的几个命令实践
- SQL Server判断对象是否存在 (if exists (select * from sysobjects )(转)