Basic operation of temp table on SQL Server 2005
1
2
-- Create a temp table
3
create table #test1(aa varchar(10))
4
5
6
-- 清空表
7
truncate table #test
8
truncate table Course
9
10
-- 删除表
11
drop table #test
12
drop table #UniqueTable
13
14
15
-- 查看数据
16
select * from #test
17
select * from #UniqueTable
18
19
-- Select rows that are identical
20
select ID into #test
21
from Course
22
group by (ID)
23
having count(ID) >1
24
25
-- select the rows that are unique
26
select * into #UniqueTable
27
from Course
28
where ID not in
29
(select ID from #test)
30
31
-- Add the rows to temp table
32
insert #UniqueTable
33
select distinct *
34
from Course
35
where ID in
36
(select ID from #test)
37
38
-- Insert into table
39
insert Course
40
select *
41
from #UniqueTable

2
-- Create a temp table3
create table #test1(aa varchar(10))4

5

6
-- 清空表7
truncate table #test8
truncate table Course9

10
-- 删除表11
drop table #test12
drop table #UniqueTable13

14

15
-- 查看数据16
select * from #test17
select * from #UniqueTable18

19
-- Select rows that are identical 20
select ID into #test21
from Course22
group by (ID)23
having count(ID) >124

25
-- select the rows that are unique 26
select * into #UniqueTable27
from Course28
where ID not in 29
(select ID from #test)30

31
-- Add the rows to temp table32
insert #UniqueTable33
select distinct * 34
from Course35
where ID in 36
(select ID from #test)37

38
-- Insert into table39
insert Course40
select * 41
from #UniqueTable


浙公网安备 33010602011771号