reconfigure WITH OVERRIDE
exec sp_configure 'Ad Hoc Distributed Queries',1--允许openrowset opendatasource访问
reconfigure WITH OVERRIDE
exec sp_configure 'show advanced options',0 --关闭高级设置
reconfigure WITH OVERRIDE
加入 我创建一个存储过程:create porc AB_CDE
@A int,
@B int
as
这里面就是内容了
就在阵容里面具体 操作 存储过程~~~~~~~~
给一个例子:
--插入时要判断是否重复插入
declare @id int
declare @sNo varchar(100)
declare @sName varchar(100)
declare @sex varchar(10)
declare @jiguan varchar(100)
declare @gongzuodanwei varchar(200)
declare @zhiwu varchar(100)
declare @tongxundizhi varchar(200)
declare @youzhengbianma varchar(100)
declare @lianxidianhua varchar(100)
declare @yidongdianhua varchar(100)
declare @dianziyouxiang varchar(100)
declare @shenfenzheng varchar(100)
declare @chushengriqi datetime
declare @xueli varchar(100)
declare @biyexuexiao varchar(100)
declare @biyezhuanye varchar(100)
declare @biyenianyue datetime
declare @xuewei varchar(100)
declare @mingzhu varchar(100)
declare @zhengzhimianmao varchar(100)
declare @regDate datetime
declare @result int
set @result=0
set @regDate=getdate()
begin tran
declare cur cursor for select 学号,姓名,性别,籍贯,工作单位,职务,通讯地址,邮政编码,联系电话,移动电话,电子邮箱,身份证号码,出生日期,学历,毕业学校,毕业专业名称,毕业年月,学位,民族,政治面貌 from #tmp
open cur
fetch next from cur into @sNo,@sName,@sex,@jiguan,@gongzuodanwei,@zhiwu,@tongxundizhi,@youzhengbianma,@lianxidianhua,@yidongdianhua,@dianziyouxiang,@shenfenzheng,@chushengriqi,@xueli,@biyexuexiao,@biyezhuanye,@biyenianyue,@xuewei,@mingzhu,@zhengzhimianmao
while @@fetch_status=0
begin
--学生在学生表中不存在才插入
if not exists (select 1 from vtd02 where 学号=@sNo)
begin
--插入学生资料
exec @id=PTD02_Insert @F01=@sName,@F02=@sex,@F36=@sNo,@FIDTB01=@classId,@F32=10,@F05=@jiguan,
@F17=@gongzuodanwei,@F15=@zhiwu,@F11=@tongxundizhi,
@F07=@youzhengbianma,@F10=@lianxidianhua,@F09=@yidongdianhua,
@F08=@dianziyouxiang,@F18=@shenfenzheng,@F06=@chushengriqi,
@F43=@xueli,@F12=@biyexuexiao,@F13=@biyezhuanye,
@F14=@biyenianyue,@F44=@xuewei,@F04=@mingzhu,@F45=@zhengzhimianmao
--插入学生帐号
exec PUB02_Insert @F01=@sNo,@F02=@password,@FIDUB01=3,@FIDF03=@id,@F04=1,@F05=@regDate
fetch next from cur into @sNo,@sName,@sex,@jiguan,@gongzuodanwei,@zhiwu,@tongxundizhi,@youzhengbianma,@lianxidianhua,@yidongdianhua,@dianziyouxiang,@shenfenzheng,@chushengriqi,@xueli,@biyexuexiao,@biyezhuanye,@biyenianyue,@xuewei,@mingzhu,@zhengzhimianmao
end
else
begin
fetch next from cur into @sNo,@sName,@sex,@jiguan,@gongzuodanwei,@zhiwu,@tongxundizhi,@youzhengbianma,@lianxidianhua,@yidongdianhua,@dianziyouxiang,@shenfenzheng,@chushengriqi,@xueli,@biyexuexiao,@biyezhuanye,@biyenianyue,@xuewei,@mingzhu,@zhengzhimianmao
end
end
close cur
deallocate cur
if @@error<>0 rollback tran
commit tran
上面比如是一个存储过程。
然后: exec PUB02_Insert @F01=@sNo,@F02=@password,@FIDUB01=3,@FIDF03=@id,@F04=1,@F05=@regDate
这个就是在上面掉用的存储过程。 exec 存储过程name 具体参数
如果对您有帮助,请记得采纳为满意答案,谢谢!祝您生活愉快!
vaela
SQL code--访问不同电脑上的数据库(远程只要联好网就一样)
--创建链接服务器
exec sp_addlinkedserver 'srv_lnk ', ' ', 'SQLOLEDB ', '远程服务器名或ip地址 '
exec sp_addlinkedsrvlogin 'srv_lnk ', 'false ',null, '用户名 ', '密码 '
go
--查询示例
select * from srv_lnk.数据库名.dbo.表名
--导入示例
select * into 表 from srv_lnk.数据库名.dbo.表名
go
--处理完成后删除链接服务器
exec sp_dropserver 'srv_lnk ', 'droplogins '
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)