zoukankan
html css js c++ java
查询重复记录
if
exists
(
select
*
from
dbo.sysobjects
where
id
=
object_id
(N
'
[dbo].[p_qry]
'
)
and
OBJECTPROPERTY
(id, N
'
IsProcedure
'
)
=
1
)
drop
procedure
[
dbo
]
.
[
p_qry
]
GO
/**/
/*
--查询重复记录的通用存储过程
可以查询出表中那些数据是重复的,这里的重复,是指除主键外重复的记录
如果表中有主键,请指定主键.
如果表中有标识字段,而且标识字段无重复,请在调用时,将主键指定为标识字段
如果标识字段重复,不能用此存储过程
-- 2004.4--
*/
create
proc
p_qry
@tbname
sysname,
--
要查询的表名
@keyfdname
sysname
=
null
--
表中的主键,如果未指定,则表中无主键
as
declare
@nokey
bit
,
@fd
varchar
(
8000
),
@tj
varchar
(
8000
)
set
nocount
on
if
isnull
(
@keyfdname
,
''
)
=
''
begin
select
@keyfdname
=
cast
(
newid
()
as
char
(
36
)),
@nokey
=
1
exec
(
'
alter table [
'
+
@tbname
+
'
] add [
'
+
@keyfdname
+
'
] decimal(38,0) identity(1,1)
'
)
end
select
@fd
=
''
,
@tj
=
''
select
@fd
=
@fd
+
'
,[
'
+
name
+
'
]
'
,
@tj
=
@tj
+
'
[
'
+
name
+
'
]=a.[
'
+
name
+
'
] and
'
from
syscolumns
where
object_name
(id)
=
@tbname
and
name
<>
@keyfdname
set
@fd
=
substring
(
@fd
,
2
,
8000
)
exec
(
'
select
'
+
@fd
+
'
from [
'
+
@tbname
+
'
] a
where exists(select 1 from [
'
+
@tbname
+
'
] where
'
+
@tj
+
'
[
'
+
@keyfdname
+
'
]<>a.[
'
+
@keyfdname
+
'
])
'
)
if
@nokey
=
1
exec
(
'
alter table [
'
+
@tbname
+
'
] drop column [
'
+
@keyfdname
+
'
]
'
)
set
nocount
off
go
--
调用示例
--
创建测试数据
create
table
表(f1
int
,f2
int
,f3
int
,f4
int
,f5
int
)
insert
into
表
select
1
,
1
,
1
,
1
,
1
union
all
select
2
,
1
,
1
,
1
,
1
union
all
select
3
,
2
,
1
,
23
,
1
union
all
select
4
,
2
,
3
,
1
,
3
union
all
select
5
,
1
,
1
,
1
,
1
go
--
调用通用存储过程实现楼主的查询
exec
p_qry
'
表
'
,
'
f1
'
--
删除测试环境
drop
table
表
/**/
/*
--测试结果
f2 f3 f4 f5
----------- ----------- ----------- -----------
1 1 1 1
1 1 1 1
1 1 1 1
--
*/
查看全文
相关阅读:
流量染色与gRPC服务托管 微服务协作开发、灰度发布之流量染色 灰度发布与流量染色
http://www.cnblogs.com/sealedbook/p/6194047.html
celery 原理
修改织梦默认栏目页、文章页URL命名规则
Dede首页幻灯版显示Bug修正
DEDECMS5.7 首页和栏目页调用文章按权重排序
dede文章摘要字数的设置方法
DEDECMS登录后台慢的完美解决方案
DedeCMS去掉友情链接中“织梦链投放”“织梦链”的方法
删除dedecms5.7后台登陆验证码
原文地址:https://www.cnblogs.com/ghd258/p/260769.html
最新文章
netty 聊天室
c++ 套接字 --->2002 java NIO --->netty
关注点分离
Apache 后台服务器(主要处理php及一些功能请求 如:中文url) Nginx 前端服务器(利用它占用系统资源少得优势来处理静态页面大量请求) Lighttpd 图片服务器 总体来说,随着nginx功能得完善将使他成为今后web server得主流。
oneway modifier MQ 发送请求不接受任何响应
Thrift: Scalable Cross-Language Services Implementation
如果你处理的是字节,那么 Go 语言可能是一个不错的选择。 如果你处理的是数据,那么 Go 语言可能不是一个好的选择。
环境初始化 Build and Install the Apache Thrift IDL Compiler Install the Platform Development Tools
协程中的取消和异常 使用堆栈帧来管理要运行哪个函数以及所有局部变量
配置文件监听 与加载
热门文章
How can I get a Netty server to reload a TLS certificate when it is renewed?
lua ngx 定时器
架构理念 只使用原生组件的核心优势功能点,尽量避免二次开发,可通过加层实现功能的定制化
对请求数据的格式化 方案 Spring Cloud Gateway features:
Nginx可以说是标配组件,但是主要场景还是负载均衡、反向代理、代理缓存、限流等场景;而把Nginx作为一个Web容器使用的还不是那么广泛。
nginx使用ngx_lua访问后端Thrift-Server实现和介绍
不建议在for循环中使用”+”进行字符串拼接
事件驱动型应用
APM 原理与框架选型
Flume-Hbase-Sink针对不同版本flume与HBase的适配研究与经验总结
Copyright © 2011-2022 走看看