Repository navigation
Expand file tree
/
Copy pathcreatetablewithindex.sql
More file actions
87 lines (87 loc) · 2.32 KB
/
Copy pathcreatetablewithindex.sql
File metadata and controls
87 lines (87 loc) · 2.32 KB
1
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
-- This script creates airlineWithIndex table needed for running perf tuning tests.
use PerfTuning;
go
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = N'airlineWithIndex')
BEGIN
PRINT 'dropping existing table airlineWithIndex'
drop table [airlineWithIndex];
END
GO
CREATE TABLE [dbo].airlineWithIndex(
[Year] [int] NULL,
[Month] [int] NULL,
[DayofMonth] [int] NULL,
[DayOfWeek] [bigint] NULL,
[FlightDate] [float] NULL,
[UniqueCarrier] [nvarchar](255) NULL,
[TailNum] [nvarchar](255) NULL,
[FlightNum] [nvarchar](255) NULL,
[OriginAirportID] [nvarchar](255) NULL,
[Origin] [nvarchar](255) NULL,
[OriginState] [nvarchar](255) NULL,
[DestAirportID] [nvarchar](255) NULL,
[Dest] [nvarchar](255) NULL,
[DestState] [nvarchar](255) NULL,
[CRSDepTime] [float] NULL,
[DepTime] [float] NULL,
[DepDelay] [int] NULL,
[DepDelayMinutes] [int] NULL,
[DepDel15] [bit] NULL,
[DepDelayGroups] [nvarchar](255) NULL,
[TaxiOut] [int] NULL,
[WheelsOff] [float] NULL,
[WheelsOn] [float] NULL,
[TaxiIn] [int] NULL,
[CRSArrTime] [float] NULL,
[ArrTime] [float] NULL,
[ArrDelay] [int] NULL,
[ArrDelayMinutes] [int] NULL,
[ArrDel15] [bit] NULL,
[ArrDelayGroups] [nvarchar](255) NULL,
[Cancelled] [bit] NULL,
[CancellationCode] [nvarchar](255) NULL,
[Diverted] [bit] NULL,
[CRSElapsedTime] [int] NULL,
[ActualElapsedTime] [int] NULL,
[AirTime] [int] NULL,
[Flights] [int] NULL,
[Distance] [int] NULL,
[DistanceGroup] [nvarchar](255) NULL,
[CarrierDelay] [int] NULL,
[WeatherDelay] [int] NULL,
[NASDelay] [int] NULL,
[SecurityDelay] [int] NULL,
[LateAircraftDelay] [int] NULL,
[MonthsSince198710] [int] NULL,
[DaysSince19871001] [int] NULL,
[rowNum] [int] NULL
);
GO
CREATE CLUSTERED INDEX simple_index ON airlineWithIndex (rowNum);
GO
PRINT 'inserting data from airlineWithIntCol into airlineWithIndex'
GO
INSERT INTO airlineWithIndex SELECT * FROM airlineWithIntCol
GO
PRINT 'inserting data done'
GO
ALTER TABLE airlineWithIndex
ADD Late BIT
ALTER TABLE airlineWithIndex
ADD CRSDepHour int
GO
PRINT 'computing Late and ArrDelay column values.'
GO
update airlineWithIndex
set CRSDepHour=ROUND(CRSDepTime, 0, 1), Late=case when ArrDelay>15 then 1 else 0 end
GO
PRINT 'computing done'
GO
PRINT 'rebuilding index after insert operations'
GO
ALTER INDEX simple_index ON airlineWithIndex
REBUILD
GO
PRINT 'rebuilding done'
GO