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