sql server往数据库疯狂写入数据、删除表的重复项
3622 点击·0 回帖
![]() | ![]() | |
![]() | 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; | |
![]() | ![]() |