--使用游标循环来更改主键约束---------------------------------------Declare @TbName sysname
Declare @sql varchar(4000)Declare c_Key cursor for
select [name] from sysobjects where xtype='U' and name like 'sb_%'
open c_Key
fetch next from c_Key into @TbNamewhile(@@fetch_status=0)
Begin
set @sql='alter table '+@TbName+' add constraint PK_'+@TbName+' primary key([sbbh])'
Exec(@sql)
fetch next from c_Key into @TbName
End
Go
Declare @sql varchar(4000)Declare c_Key cursor for
select [name] from sysobjects where xtype='U' and name like 'sb_%'
open c_Key
fetch next from c_Key into @TbNamewhile(@@fetch_status=0)
Begin
set @sql='alter table '+@TbName+' add constraint PK_'+@TbName+' primary key([sbbh])'
Exec(@sql)
fetch next from c_Key into @TbName
End
Go
解决方案 »
- 急用!!!!在线,sql server 2005 企业版 序列号
- 求一个存储过程“订单金额大于500,下订单会员自动升级VIP会员”!
- vc++中连接使用sqlserver的方法.
- 如何生成重复记录?
- 如何解决插入日期时,SqlServer会自动加上“上午”或“下午”字样?
- 在线等高人 解决关于用户默认架构的问题
- 一个稍复杂的sql语句的问题。(标题加长。。。)
- 问个模糊的问题?左连接?右连接?有没有这个概念?如果有是啥?
- 存儲過程調用存儲過程問題
- 一个关于数据库连接的问题,很着急
- 将字符串20060102133059转换为datetime类型2006-01-02 13:30:59
- 请教:什么不能建全文索引呢?
现更正一下自己学习:
Declare @TbName sysname
declare @sql1 varchar(4000),@sql2 varchar(4000)Declare c_Key cursor for
select [name] from sysobjects where xtype='U' and name like 'sb_%'
open c_Key
fetch next from c_Key into @TbNamewhile(@@fetch_status=0)
Begin
set @sql1 = 'alter table '+@TbName+' alter column sbbh varchar(20) not null'
set @sql2='alter table '+@TbName+' add constraint PK_'+@TbName+' primary key([sbbh])'
Exec(@sql)
fetch next from c_Key into @TbName
End
Go