-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndices.sql
99 lines (73 loc) · 2.4 KB
/
Indices.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
-- INDICES
-- Indice nocluster para la tabla PacienteNoIndex
-- Para queryes que tengan como filtro el primer nombre (name)
SELECT *
INTO Paciente_noindex
FROM Paciente
SELECT *
FROM Paciente_noindex
SET STATISTICS TIME ON;
SELECT name
FROM Paciente_noindex
where name = 'Marina';
SET STATISTICS TIME OFF;
CREATE NONCLUSTERED INDEX IDX_Name ON
Paciente_noindex (Name)
-- Indice nocluster para la tabla SeguroNoIndex
-- Para queryes que tengan como filtro tipo de seguro (insurance_type)
SELECT *
INTO Seguro_NoIndex
FROM SeguroMedico
SELECT *
FROM Seguro_NoIndex
SET STATISTICS TIME ON;
SELECT ID, company_name, insurance_type
FROM Seguro_NoIndex
where insurance_type = 'Seguro de Salud';
SET STATISTICS TIME OFF;
CREATE NONCLUSTERED INDEX IDX_InsuranceType ON
Seguro_NoIndex(insurance_type)
-- En medicamento NoIndex crear una llave Primaria clustered para el ID
-- Mejora eficiencia para el tipo de query mostrada
SELECT *
INTO Medicamento_NoIndex
FROM Medicamento
select * from Medicamento_NoIndex
SET STATISTICS TIME ON;
SELECT *
FROM Medicamento
where stock BETWEEN 30 AND 70
SET STATISTICS TIME OFF;
ALTER TABLE Medicamento_NoIndex
ADD CONSTRAINT
PK_Medicamento_NoIndex
PRIMARY KEY CLUSTERED (ID);
Cita (patient_id, appointment_date, doctor_id, diagnosis, treatment, office_number)
-- Clustered Index for CitaNoIndex (clustered para mejorar la eficiencia para la query que tengo)
-- Este Index con la intenciode poder consultar
-- id paciente, app date, diagnosis, treatment
SELECT *
INTO Cita_NoIndex
FROM Cita
SET STATISTICS TIME ON;
SELECT patient_id, appointment_date, diagnosis, treatment
FROM Cita_NoIndex
WHERE appointment_date > '2009-12-31 11:59:59'
SET STATISTICS TIME OFF;
CREATE CLUSTERED INDEX IDX_appointment_date ON
Cita_NoIndex(appointment_date)
DROP INDEX IDX_appointment_date ON Cita_NoIndex
-- Clustered index para CitaNoIndex2
-- Este indice es para buscar cuantos diagnosticos iguales ha hecho un doctor especifico en un periodo de tiempo
SELECT *
INTO Cita_NoIndex2
FROM Cita
SELECT * FROM Cita_NoIndex2
SET STATISTICS TIME ON;
SELECT doctor_id, appointment_date, diagnosis
FROM Cita_NoIndex2
WHERE doctor_id = '3056030532 ' AND appointment_date > '2023-12-31 11:59:59' AND UPPER(diagnosis) = UPPER('dolor de garganta')
SET STATISTICS TIME OFF;
CREATE CLUSTERED INDEX IDX_diagnostico_doctor ON
Cita_NoIndex2(doctor_id, appointment_date, diagnosis)
DROP INDEX IDX_diagnostico_doctor ON Cita_NoIndex2