-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDDL_Census_Block_Level.sql
71 lines (69 loc) · 2.93 KB
/
DDL_Census_Block_Level.sql
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
Use GerryMatter
Go
Set Quoted_Identifier On
Create Table Census_Tract (
State_FIPS TinyInt Not Null,
County_FIPS SmallInt Not Null,
Census_Tract Int Not Null,
Population_2020 Int Not Null,
Adult_Population_2020 Int Not Null,
Area BigInt Not Null,
Border Geography Not Null,
Calc_Area As Border.STArea() Persisted,
Constraint Population_Subset_CT Check (Population_2020>=Adult_Population_2020),
Constraint Census_Tract_County_FK Foreign Key(State_FIPS,County_FIPS) References County,
Constraint Census_Tract_PK Primary Key(State_FIPS,County_FIPS,Census_Tract))
Create Table Census_Block_Group (
State_FIPS TinyInt Not Null,
County_FIPS SmallInt Not Null,
Census_Tract Int Not Null,
Census_Block_Group TinyInt Not Null,
Population_2020 Int Not Null,
Adult_Population_2020 Int Not Null,
Area BigInt Not Null,
Border Geography Not Null,
Calc_Area As Border.STArea() Persisted,
Constraint Population_Subset_CBG Check (Population_2020>=Adult_Population_2020),
Constraint Census_Block_Group_Census_Tract_FK Foreign Key(State_FIPS,County_FIPS,Census_Tract) References Census_Tract,
Constraint Census_Block_Group_PK Primary Key(State_FIPS,County_FIPS,Census_Tract,Census_Block_Group))
Create Table Census_Block (
State_FIPS TinyInt Not Null,
County_FIPS SmallInt Not Null,
Census_Tract Int Not Null,
Census_Block SmallInt Not Null,
Population_2020 SmallInt Not Null,
Adult_Population_2020 SmallInt Not Null,
Area BigInt Not Null,
Border Geography Not Null,
Calc_Area As Border.STArea() Persisted,
Constraint Population_Subset_CB Check (Population_2020>=Adult_Population_2020),
Constraint Census_Block_Tract_FK Foreign Key(State_FIPS,County_FIPS,Census_Tract) References Census_Tract,
Constraint Census_Block_PK Primary Key(State_FIPS,County_FIPS,Census_Tract,Census_Block))
Set Quoted_Identifier On
Use GerryMatter_Raw
Go
Create Table Census_Tract_Geo (
State_FIPS TinyInt Not Null,
County_FIPS SmallInt Not Null,
Census_Tract Int Not Null,
Border Text Not Null,
Constraint Census_Tract_Geo_PK Primary Key(State_FIPS,County_FIPS,Census_Tract))
Exec sp_tableoption 'dbo.Census_Tract_Geo', 'table lock on bulk load', 1
Create Table Census_Block_Group_Population_Area (
State_FIPS TinyInt Not Null,
County_FIPS SmallInt Not Null,
Census_Tract Int Not Null,
Census_Block_Group TinyInt Not Null,
Population_2020 Int Not Null,
Adult_Population_2020 Int Not Null,
Area BigInt Not Null,
Constraint Census_Block_Group_Population_Area_PK Primary Key(State_FIPS,County_FIPS,Census_Tract,Census_Block_Group))
Exec sp_tableoption 'dbo.Census_Block_Group_Population_Area', 'table lock on bulk load', 1
Create Table Census_Block_Group_Geo (
State_FIPS TinyInt Not Null,
County_FIPS SmallInt Not Null,
Census_Tract Int Not Null,
Census_Block_Group TinyInt Not Null,
Border Text Not Null,
Constraint Census_Block_Group_Geo_PK Primary Key(State_FIPS,County_FIPS,Census_Tract,Census_Block_Group))
Exec sp_tableoption 'dbo.Census_Block_Group_Geo', 'table lock on bulk load', 1