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

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41
