|
发表于 2012-11-20 14:06:30
|
显示全部楼层
本帖最后由 liugegexj 于 2012-11-20 14:12 编辑
存储过程就是程序集
打开数据库,与“表”同组有个“可编程性”如图
点存储过程
你也可以对你升级出错的帐套在SQL执行仓里执行如下语句
USE [UFDATA_问题帐套号_问题帐套年度]
GO
/****** 对象: StoredProcedure [dbo].[AlterTable] 脚本日期: 11/20/2012 14:08:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[AlterTable] (
@TableName nvarchar(50),
@FldName nvarchar(50),
@AlterSql nvarchar(1000),
@ForeignFldType nvarchar(50),
@ForeignFldLen nvarchar(50)
)
AS
BEGIN
declare @fConst nvarchar (100)
declare @fTbl nvarchar (100),@fCol nvarchar (100)
declare @rTbl nvarchar (100),@rCol nvarchar (100)
declare @Sql nvarchar(500)
if exists(select top 1 * from tempdb..sysobjects where id=object_id('tempdb..tblfkey') )--and OBJECTPROPERTY(id,N'IsUserTable')=1
drop table tempdb..tblfkey
select object_name(constid) as col1,object_name(fkeyid) as col2,object_name(rkeyid) as col3,
col_name(fkeyid,fkey) as col4,col_name(rkeyid,rkey) as col5
into tempdb..tblfkey
from sysforeignkeys
where object_name(rkeyid)=@TableName and col_name(rkeyid,rkey)=@FldName
declare Rst cursor for select * from tempdb..tblfkey
--删除关系并改变长度
open Rst
fetch next from Rst into @fConst, @fTbl, @rTbl, @fCol,@rCol
while @@fetch_status=0
begin
exec ('ALTER TABLE ' + @fTbl + ' Drop Constraint ' + @fConst)
if @ForeignFldType is not null
begin
set @Sql= 'ALTER TABLE ' + @fTbl + ' alter column ' + @fCol +' '+@ForeignFldType +' ('+@ForeignFldLen+') NULL'
exec (@Sql)
end
fetch next from Rst into @fConst, @fTbl, @rTbl, @fCol,@rCol
end
exec(@AlterSql)
close Rst
--恢复原来的关系
open Rst
fetch next from Rst into @fConst, @fTbl, @rTbl, @fCol,@rCol
while @@fetch_status=0
begin
print @fConst
exec ('ALTER TABLE ' + @fTbl + ' ADD
CONSTRAINT ' + @fConst + ' FOREIGN KEY
( ' +
@fCol
+ ') REFERENCES ' + @rTbl + ' ( ' +
@rCol
+ ')')
fetch next from Rst into @fConst, @fTbl, @rTbl, @fCol,@rCol
end
close Rst
deallocate Rst
drop table tempdb..tblfkey
END
|
评分
-
查看全部评分
|