如何去除表中的标识列(ID),改为常用的 ID int not null???

baiyongchun 2003-11-20 10:45:36
如何去除表中的标识列(ID),改为常用的 ID int not null???
...全文
37 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 元老 2003-11-20
  • 打赏
  • 举报
回复
发错地方,不好意思
zjcxc 元老 2003-11-20
  • 打赏
  • 举报
回复
最基本的处理方法:

如果表中有主键(记录不重复的字段也可以),可以用类似下面的方法,当然x,y要换成具体的数字,不能用变量:

select top y * from 表 where 主键 not in(select top (x-1)*y 主键 from 表)



如果表中无主键,可以用临时表,加标识字段解决.这里的x,y可以用变量.

select id=identity(int,1,1),* into #tb from 表
select * from #tb where id between (x-1)*y and x*y-1
baiyongchun 2003-11-20
  • 打赏
  • 举报
回复
谢谢!
大力真是高手啊。
pengdali 2003-11-20
  • 打赏
  • 举报
回复
--去标识
alter table tablename add id1 int not null

update tablename set id1=id

alter table tablename drop column id

exec sp_rename 'tablename.id1','id'



select cast (id as int) id,列..... into #temp from 表
drop table 表
select * into 表 from #temp
drop table #temp
txlicenhe 2003-11-20
  • 打赏
  • 举报
回复

如何用语句添加或去除表字段的自增属性
http://expert.csdn.net/Expert/topic/2217/2217137.xml?temp=.8302118

34,499

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧