灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:2517回复:0

[SQL Server]sql server往数据库疯狂写入数据、删除表的重复项

楼主#
更多 发布于:2012-09-04 18:05

sql server往数据库疯狂写入数据、删除表的重复项、内连(左连,右连)、分页查询

--疯狂往数据库里面插入内容的数据库代码。

create table test(
testId int primary key identity(1,1),
testName varchar(30),
testPass varchar(30)
);  www.atcpu.com  
insert into test (testName, testPass) values('zhuang wei hong','zhuang wei hong');
--疯狂插入表的语句。一直执行。再强悍的机器也都会崩。
insert into test (testName, testPass) select testName, testPass from test;
select * from test;
select count(*) from test;
drop table test;
select * from test;

--删除表的重复项演示
create table temp(
  tempId int,
  tempName varchar(30)
);
insert into temp values(2,'beiwei');
--核心部分,先选择出来。
select distinct * into #temp1 from temp;
--再把原先那张表里面的数据全部删除。
delete from temp;
--再把选择出来的那些插入前面所说的那张表里。
insert into temp select * from #temp1;
--然后。把一张临时表删除。
drop table #temp1;
   www.atcpu.com  
select * from temp;

--左连。left join   on   、right join     on     (inner join    on)

    select w.ename, b.ename from emp w left join emp b on w.mgr=b.empno;

--分页查询。(第五个到第十个-->按入职时间来排序)

    select top 6 * from emp where empno not in (

        select top 4 empno from emp order by hiredate

    ) order by hiredate;



喜欢0 评分0
游客

返回顶部