方法一:
insert into
dbo.News (NewsTitle,TypeID,Typename,[content])
select NewsTitle,[content]
from dbo.News2 b
where b.NewsTitle not in(select NewsTitle from dbo.News)
方法二:
insert into
dbo.News (NewsTitle,[content]
from dbo.News2 b
where not exists
(select * from dbo.news where NewsTitle=b.NewsTitle)
游标 *** 作示例一:
declare @cur_pos int
declare mycursor cursor for select NewsTitle,TypeID from dbo.News
declare @col1 char(10)
declare @col2 char(10)
open mycursor
fetch next from mycursor into @col1,@col2
while @@fetch_status<>-1
begin
print @col1+@col2
--select @cur_pos=@cur_pos+1
fetch next from mycursor into @col1,@col2
end
close mycursor
deallocate mycursor
游标 *** 作示例二:
declare @cur_pos int
declare @newsID int
declare @newsTitle varchar(20)
declare mycursor cursor for select NewsID,NewsTitle from dbo.News2
open mycursor
fetch next from mycursor into @newsID,@newsTitle
while @@fetch_status<>-1
begin
if not exists
(select * from dbo.News where NewsTitle=@newsTitle)
begin
insert into dbo.News(NewsTitle,[content])
select NewsTitle,[content]
from dbo.News2 where NewsID=@newsID
end
fetch next from mycursor into @newsID,@newsTitle
end
close mycursor
deallocate mycursor 转自: http://www.thaught.cn/go.php/category/16/1/2/ 总结
以上是内存溢出为你收集整理的sqlserver常用 *** 作——判断关键字段是否重复插入记录全部内容,希望文章能够帮你解决sqlserver常用 *** 作——判断关键字段是否重复插入记录所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)