-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove clustered indexes from authorization views for SQL Server
- Loading branch information
1 parent
cf6a9d3
commit 97a6a2b
Showing
2 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
.../Standard/4.0.0/Artifacts/MsSql/Structure/Ods/1490-RemoveClusteredIndexesFromAuthView.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
-- Licensed to the Ed-Fi Alliance under one or more agreements. | ||
-- The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
-- See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
IF EXISTS (SELECT 1 | ||
FROM sys.indexes | ||
WHERE name = 'UX_EducationOrganizationIdToStudentUSI' | ||
AND object_id = OBJECT_ID('auth.EducationOrganizationIdToStudentUSI')) | ||
DROP INDEX UX_EducationOrganizationIdToStudentUSI ON auth.EducationOrganizationIdToStudentUSI; | ||
GO | ||
|
||
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'auth.EducationOrganizationIdToStudentUSI')) | ||
DROP VIEW auth.EducationOrganizationIdToStudentUSI; | ||
GO | ||
|
||
CREATE VIEW auth.EducationOrganizationIdToStudentUSI AS | ||
SELECT edOrgs.SourceEducationOrganizationId, ssa.StudentUSI, COUNT_BIG(*) AS Ignored | ||
FROM auth.EducationOrganizationIdToEducationOrganizationId edOrgs | ||
INNER JOIN edfi.StudentSchoolAssociation ssa | ||
ON edOrgs.TargetEducationOrganizationId = ssa.SchoolId | ||
GROUP BY edOrgs.SourceEducationOrganizationId, ssa.StudentUSI | ||
GO | ||
|
||
IF EXISTS (SELECT 1 | ||
FROM sys.indexes | ||
WHERE name = 'UX_EducationOrganizationIdToParentUSI' | ||
AND object_id = OBJECT_ID('auth.EducationOrganizationIdToParentUSI')) | ||
DROP INDEX UX_EducationOrganizationIdToParentUSI ON auth.EducationOrganizationIdToParentUSI; | ||
GO | ||
|
||
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'auth.EducationOrganizationIdToParentUSI')) | ||
DROP VIEW auth.EducationOrganizationIdToParentUSI; | ||
GO | ||
|
||
CREATE OR ALTER VIEW auth.EducationOrganizationIdToParentUSI AS | ||
SELECT edOrgs.SourceEducationOrganizationId, spa.ParentUSI | ||
FROM auth.EducationOrganizationIdToEducationOrganizationId edOrgs | ||
INNER JOIN edfi.StudentSchoolAssociation ssa | ||
ON edOrgs.TargetEducationOrganizationId = ssa.SchoolId | ||
INNER JOIN edfi.StudentParentAssociation spa | ||
ON ssa.StudentUSI = spa.StudentUSI | ||
GROUP BY edOrgs.SourceEducationOrganizationId, spa.ParentUSI | ||
GO | ||
|
||
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'auth.EducationOrganizationIdToStaffUSI')) | ||
DROP VIEW auth.EducationOrganizationIdToStaffUSI; | ||
GO | ||
|
||
CREATE VIEW auth.EducationOrganizationIdToStaffUSI AS | ||
|
||
-- EdOrg Assignments | ||
SELECT edOrgs.SourceEducationOrganizationId, seo_assign.StaffUSI | ||
FROM auth.EducationOrganizationIdToEducationOrganizationId edOrgs | ||
INNER JOIN edfi.StaffEducationOrganizationAssignmentAssociation seo_assign | ||
ON edOrgs.TargetEducationOrganizationId = seo_assign.EducationOrganizationId | ||
|
||
UNION | ||
|
||
-- EdOrg Employment | ||
SELECT edOrgs.SourceEducationOrganizationId, seo_empl.StaffUSI | ||
FROM auth.EducationOrganizationIdToEducationOrganizationId edOrgs | ||
INNER JOIN edfi.StaffEducationOrganizationEmploymentAssociation seo_empl | ||
ON edOrgs.TargetEducationOrganizationId = seo_empl.EducationOrganizationId | ||
GO | ||
|
||
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'auth.EducationOrganizationIdToStudentUSIThroughResponsibility')) | ||
DROP VIEW auth.EducationOrganizationIdToStudentUSIThroughResponsibility; | ||
GO | ||
|
||
CREATE VIEW auth.EducationOrganizationIdToStudentUSIThroughResponsibility AS | ||
SELECT edOrgs.SourceEducationOrganizationId, seora.StudentUSI | ||
FROM auth.EducationOrganizationIdToEducationOrganizationId edOrgs | ||
INNER JOIN edfi.StudentEducationOrganizationResponsibilityAssociation seora | ||
ON edOrgs.TargetEducationOrganizationId = seora.EducationOrganizationId | ||
GROUP BY edOrgs.SourceEducationOrganizationId, seora.StudentUSI | ||
GO |
82 changes: 82 additions & 0 deletions
82
.../Standard/5.2.0/Artifacts/MsSql/Structure/Ods/1490-RemoveClusteredIndexesFromAuthView.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
-- Licensed to the Ed-Fi Alliance under one or more agreements. | ||
-- The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
-- See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
IF EXISTS (SELECT 1 | ||
FROM sys.indexes | ||
WHERE name = 'UX_EducationOrganizationIdToStudentUSI' | ||
AND object_id = OBJECT_ID('auth.EducationOrganizationIdToStudentUSI')) | ||
DROP INDEX UX_EducationOrganizationIdToStudentUSI ON auth.EducationOrganizationIdToStudentUSI; | ||
GO | ||
|
||
|
||
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'auth.EducationOrganizationIdToStudentUSI')) | ||
DROP VIEW auth.EducationOrganizationIdToStudentUSI; | ||
GO | ||
|
||
|
||
CREATE VIEW auth.EducationOrganizationIdToStudentUSI AS | ||
SELECT edOrgs.SourceEducationOrganizationId, ssa.StudentUSI, COUNT_BIG(*) AS Ignored | ||
FROM auth.EducationOrganizationIdToEducationOrganizationId edOrgs | ||
INNER JOIN edfi.StudentSchoolAssociation ssa | ||
ON edOrgs.TargetEducationOrganizationId = ssa.SchoolId | ||
GROUP BY edOrgs.SourceEducationOrganizationId, ssa.StudentUSI | ||
GO | ||
|
||
|
||
IF EXISTS (SELECT 1 | ||
FROM sys.indexes | ||
WHERE name = 'UX_EducationOrganizationIdToContactUSI' | ||
AND object_id = OBJECT_ID('auth.EducationOrganizationIdToContactUSI')) | ||
DROP INDEX UX_EducationOrganizationIdToContactUSI ON auth.EducationOrganizationIdToContactUSI; | ||
GO | ||
|
||
|
||
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'auth.EducationOrganizationIdToContactUSI')) | ||
DROP VIEW auth.EducationOrganizationIdToContactUSI; | ||
GO | ||
|
||
CREATE VIEW auth.EducationOrganizationIdToContactUSI AS | ||
SELECT edOrgs.SourceEducationOrganizationId, spa.ContactUSI, COUNT_BIG(*) AS Ignored | ||
FROM auth.EducationOrganizationIdToEducationOrganizationId edOrgs | ||
INNER JOIN edfi.StudentSchoolAssociation ssa | ||
ON edOrgs.TargetEducationOrganizationId = ssa.SchoolId | ||
INNER JOIN edfi.StudentContactAssociation spa | ||
ON ssa.StudentUSI = spa.StudentUSI | ||
GROUP BY edOrgs.SourceEducationOrganizationId, spa.ContactUSI | ||
GO | ||
|
||
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'auth.EducationOrganizationIdToStaffUSI')) | ||
DROP VIEW auth.EducationOrganizationIdToStaffUSI; | ||
GO | ||
|
||
|
||
CREATE VIEW auth.EducationOrganizationIdToStaffUSI AS | ||
|
||
-- EdOrg Assignments | ||
SELECT edOrgs.SourceEducationOrganizationId, seo_assign.StaffUSI | ||
FROM auth.EducationOrganizationIdToEducationOrganizationId edOrgs | ||
INNER JOIN edfi.StaffEducationOrganizationAssignmentAssociation seo_assign | ||
ON edOrgs.TargetEducationOrganizationId = seo_assign.EducationOrganizationId | ||
|
||
UNION | ||
|
||
-- EdOrg Employment | ||
SELECT edOrgs.SourceEducationOrganizationId, seo_empl.StaffUSI | ||
FROM auth.EducationOrganizationIdToEducationOrganizationId edOrgs | ||
INNER JOIN edfi.StaffEducationOrganizationEmploymentAssociation seo_empl | ||
ON edOrgs.TargetEducationOrganizationId = seo_empl.EducationOrganizationId | ||
GO | ||
|
||
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'auth.EducationOrganizationIdToStudentUSIThroughResponsibility')) | ||
DROP VIEW auth.EducationOrganizationIdToStudentUSIThroughResponsibility; | ||
GO | ||
|
||
CREATE VIEW auth.EducationOrganizationIdToStudentUSIThroughResponsibility AS | ||
SELECT edOrgs.SourceEducationOrganizationId, seora.StudentUSI | ||
FROM auth.EducationOrganizationIdToEducationOrganizationId edOrgs | ||
INNER JOIN edfi.StudentEducationOrganizationResponsibilityAssociation seora | ||
ON edOrgs.TargetEducationOrganizationId = seora.EducationOrganizationId | ||
GROUP BY edOrgs.SourceEducationOrganizationId, seora.StudentUSI | ||
GO |