我是否想通过程序实现"用导入\导出功能,可在选择对象中选择要导的全部存储过程"
以便让不懂sql server 的人来操作
以便让不懂sql server 的人来操作
解决方案 »
- 求ORACLE数据库字符串转换成列的问题
- 急!!!!sql 值比较。。。
- SQL Server 2000触发器问题
- 请数据库高手出来帮忙
- 如何将一个存储过程的结果集保存进一个临时表?
- 如何用ado连接linked server
- SQLException: Cannot resolve collation conflict for equal to operation
- 如何学习SQL?
- 求助!!!存储过程的问题,高手赐教
- SQL Server2000最近总是出现:绑定在TCP端口1433上失败!的错误?怎么办?
- 关于触发器 在线求救
- javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.的问题
SELECT name, owner = USER_NAME(uid), objtype = power(2,sysstat & 0xf) FROM sysobjects WHERE (POWER(2, sysstat & 0xf) & 253 <> 0) AND NOT ((OBJECTPROPERTY(id, N'IsDefaultCnst') = 1) AND (category & 0x0800 <> 0)) AND (OBJECTPROPERTY(id, N'IsMSShipped') <> 1 AND (name NOT LIKE N'#%')) and power(2,sysstat & 0xf) = 16 ORDER BY name, owner 2、根据存储过程名,通过结构同以下SQL语句依次获取用户存储过程脚本信息:if exists (select * from dbo.syscomments where id=object_id(N'[dbo].[sp_test]'))
select c.text, c.encrypted, c.number, xtype=convert(nchar(2), o.xtype), datalength(c.text), convert(varbinary(8000), c.text), 0 from dbo.syscomments c, dbo.sysobjects o where o.id = c.id and c.id = object_id(N'[dbo].[sp_test]') order by c.number, c.colid
if exists (select * from dbo.syscomments where id=object_id(N'[dbo].[sp_test]'))
select text from dbo.syscomments
where id = object_id(N'[dbo].[sp_test]'
if exists (select * from dbo.syscomments where id=object_id(N'[dbo].[sp_test]'))
select text from dbo.syscomments
where id = object_id(N'[dbo].[sp_test]'
所得的存储过程脚本与数据库中现有的sp并不一致,好像是以前的一个版本
goif exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_copyProce]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_copyProce]
GO/*--生成表数据脚本的通用存储过程, 功能:将一个数据库中的存储过程,复制到另一数据库中
目标数据库中已经有的存储过程不覆盖--邹建 2005.01(引用请保留此信息)--*//*--调用示例 exec master.dbo.sp_copyProce 'a','b'
--*/create proc sp_copyProce
@s_dbname sysname, --要复制存储过程的源数据库名
@d_dbname sysname --目标数据库名
as
set nocount on
if db_id(@s_dbname) is null
begin
raiserror('数据库"%s"不存在',1,16,@s_dbname)
return
end
if db_id(@d_dbname) is null
begin
raiserror('数据库"%s"不存在',1,16,@d_dbname)
return
end
select @s_dbname='['+replace(@s_dbname,']',']]')+']'
,@d_dbname='['+replace(@d_dbname,']',']]')+']'--复制存储过程信息到临时表
create table #sys_syscomments_bak(name sysname,xtype char(2),number smallint,colid smallint,status smallint,ctext varbinary(8000))
exec('
insert #sys_syscomments_bak
(name,xtype,number,colid,status,ctext)
select o.name,o.xtype,c.number,c.colid,c.status,c.ctext
from '+@s_dbname+'.dbo.syscomments c,'+@s_dbname+'.dbo.sysobjects o
where c.id=o.id
and o.status>=0
and o.xtype=''P''
and not exists(
select * from '+@d_dbname+'.dbo.sysobjects where name=o.name)
')--创建存储过程
declare tb cursor local for
select 'use '+@d_dbname+' exec(''create proc dbo.['+replace(name,N']',N']]')+'] as --'') exec sp_recompile ['+replace(name,N']',N']]')+']'
from #sys_syscomments_bak
declare @s nvarchar(4000)
open tb
fetch tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch tb into @s
end
close tb
deallocate tb--复制存储过程结构
exec sp_configure 'allow updates',1 reconfigure with override
begin tran
exec('
delete c
from '+@d_dbname+'.dbo.syscomments c,'+@d_dbname+'.dbo.sysobjects o,#sys_syscomments_bak ob
where c.id=o.id and o.name=ob.name and o.xtype=ob.xtype
insert '+@d_dbname+'.dbo.syscomments([id],[number],[colid],[status],[ctext])
select o.[id],ob.[number],ob.[colid],ob.[status],ob.[ctext]
from '+@d_dbname+'.dbo.sysobjects o,#sys_syscomments_bak ob
where o.name=ob.name and o.xtype=ob.xtype')
commit tran
exec sp_configure 'allow updates',0 reconfigure with override
go
--使用测试
create database a
go
use a
go
create proc p_test1
as
select 'test1'
go
create proc p_test2
as
select 'test2'
gocreate database b
goexec master.dbo.sp_copyProce 'a','b'
go
select * from b.dbo.sysobjects where xtype='P'exec b.dbo.p_test1
exec b.dbo.p_test2
gouse master
godrop database a,b
drop proc sp_copyProce
不得不顶!!!!厉害!!怎么FAQ啊!:D