--循环执行插入10000条数据

declare @ID int
begin
set @ID=1

while @ID<=10000
begin
insert into table_name values('','','')--要循环的sql语句
set @ID=@ID+1
end
end

--获取随机数

select rand()--获取0~1之间的float型的数字

DECLARE @NumBegin Int=60 --随机数的最小值
DECLARE @NumEnd Int=100 --随机数的最大值
DECLARE @Decimal Int=2 --保留小数点几位
SELECT @NumBegin+round((@NumEnd-@NumBegin)*rand(),@Decimal)

--删除表中数据,不可恢复

truncate table table_name

--查找重复数据

select * from tablename
where user_id in(select  user_id from tablename group by  user_id having COUNT(*)>1)
order by  user_id

--删去重复的,只留下重复记录中编码最大的一条

delete from 表名 where

编码 in(select 编码 from 表名 group by 编码 having count(1) >= 2) 

and 编码 not in (select max(编码)from 表名 group by 编码 having count(1) >=2)
--查找数据(排除重复数据)

select * from [表名] where 编码 not in (
select 编码 from [表名] where
编码 in(select 编码 from [表名] group by 编码 having count(1) >= 2)
and 编码 not in (select max(编码) from [表名] group by 编码 having count(1) >=2))

 或

select * from [表名] where 自增主键 in (
select max(自增主键) from [表名] group by 编码 )

 

SQL server中常用sql语句的更多相关文章

  1. SQL Server中常用的SQL语句(转):

    SQL Server中常用的SQL语句 转自:http://www.cnblogs.com/rainman/archive/2013/05/04/3060428.html 1.概述 名词 笛卡尔积.主 ...

  2. SQL Server中的流控制语句

    begin···end 该语句定义sql代码块,通常在if和while语句中使用 declare @num int ; ; begin ; print 'hello word' end if···el ...

  3. SQL Server中常用的SQL语句

    1.概述 名词 笛卡尔积.主键.外键 数据完整性 实体完整性:主属性不能为空值,例如选课表中学号和课程号不能为空 参照完整性:表中的外键取值为空或参照表中的主键 用户定义完整性:取值范围或非空限制,例 ...

  4. SQL Server中常用全局变量介绍

    在SQL Server中,全局变量是一种特殊类型的变量,服务器将维护这些变量的值.全局变量以@@前缀开头,不必进行声明,它们属于系统定义的函数.下表就是SQL Server中一些常用的全局变量. 全局 ...

  5. MS SQL SERVER 2000 常用 Tran-SQL 语句

    一.创建数据库:create database mydb-创建数据库mydbon primary-在primary文件组中( name = mydb_data1,filename = 'd:\sql ...

  6. SQL Server中的SQL语句优化与效率问题

    很多人不知道SQL语句在SQL SERVER中是如何执行的,他们担心自己所写的SQL语句会被SQL SERVER误解.比如: select * from table1 where name='zhan ...

  7. SQL Server中的SQL语句优化与效率

    很多人不知道SQL语句在SQL SERVER中是如何执行的,他们担心自己所写的SQL语句会被SQL SERVER误解.比如: select * from table1 where name='zhan ...

  8. SQL Server中执行Sql字符串,返回执行结果

    今天遇到一个问题:想把sql字符串在SQL Server 中执行了,并获取执行的结果 ); SET @tablename='select @table3 = count(1) from UserVis ...

  9. Oracle 和SQL Server 中的SQL语句使用区别

    最近开始接触Oracle,想要了解下同SQL Server使用时的区别.搜寻网上信息找到具体区别分类如下: 一.数据类型比较 类型名称 Oracle SQLServer 比较  字符数据类型  CHA ...

随机推荐

  1. Tomcat服务器编码格式设置

    /** *1.找到.xml server文件 */ /** * 2. 设置encoding */

  2. 【前端_React】npm常用命令

    安装模块(包): //全局安装 $ npm install 模块名 -g //本地安装 $ npm install 模块名 //一次性安装多个 $ npm install 模块1 模块2 模块n -- ...

  3. intellij idea 2019 右键包新建文件是没有java Class选项

    今天要测试一个技术点于是新建了一个springboot工程, 在新建文件的时候发现右键后java class文件选项不见了. 以前真的没有碰到这种问题, 感觉很是意外于是百度Google后找到了解决办 ...

  4. Nacos 1.1.0发布,支持灰度配置和地址服务器模式

    https://nacos.io/zh-cn/blog/nacos%201.1.0.html

  5. ajax jQ写的上传进度条

    XML/HTML Code <form id="myForm" action="upload.php" method="post" e ...

  6. 小程序开发第一天josn和wxml

    视频中只有app.josn路径还有wxm文本.js中没有调用page.原视频中是可以出来文本内容的. 但是把js调用page以后是可以呈现的 所以疑问点就是为什么以前可以? 1.微信开发工具改了,强制 ...

  7. 使用spring boot 2.1.8生成的maven项目pom.xml第一行报错unknown error

    问题:eclipse neon4.6.3新建springboot项目时pom.xml报错unknown error 原因: spring boot 2.1.8更新了maven插件,eclipse不兼容 ...

  8. 如何关闭/禁用.NET JIT调试对话框

    当.NET程序有未处理的异常时,您可能会希望关闭出现的调试对话框.下面有两个选项: 1.启用JIT调试的注册表项 对于包含托管代码的应用程序,公共语言运行库将显示类似于JIT附加调试器的对话框.控制此 ...

  9. Codeforces886(Technocup2018) F Symmetric Projections

    Codeforces886(Technocup2018) F Symmetric Projections You are given a set of n points on the plane. A ...

  10. js 将图片转换为 base64

    var img = document.getElementById('s_lg_img'); function getBase64Image(img) { var canvas = document. ...