forked from vitortff/DBAToolKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPATeVTRprepare.sql
88 lines (64 loc) · 1.93 KB
/
PATeVTRprepare.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
USE DTCORP
go
ALTER TABLE PAT NOCHECK CONSTRAINT ALL
go
ALTER TABLE ARM NOCHECK CONSTRAINT ALL
go
ALTER TABLE VTR NOCHECK CONSTRAINT ALL
go
ALTER TABLE Psi_Vtr NOCHECK CONSTRAINT ALL
go
DELETE FROM PAT
go
-- (495403 row(s) affected)
DELETE FROM VTR
go
-- (18692 row(s) affected)
-- copia registros
ALTER TABLE PAT WITH CHECK CHECK CONSTRAINT ALL
go
ALTER TABLE ARM WITH CHECK CHECK CONSTRAINT ALL
go
ALTER TABLE VTR WITH CHECK CHECK CONSTRAINT ALL
go
ALTER TABLE Psi_Vtr WITH CHECK CHECK CONSTRAINT ALL
go
-- verifica integridade
USE [DTCORP]
GO
select distinct b.[MATCLECOD], b.[MATSCSCOD], b.[MATGRPCOD], b.[MATSBOCOD], b.[MATTIPCOD]
from pat b left outer join mat a on
a.[MATCLECOD] = b.[MATCLECOD] and
a.[MATSCSCOD] = b.[MATSCSCOD] and
a.[MATGRPCOD] = b.[MATGRPCOD] and
a.[MATSBOCOD] = b.[MATSBOCOD] and
a.[MATTIPCOD] = b.[MATTIPCOD]
where a.[MATCLECOD] is null and a.[MATSCSCOD] is null and a.[MATGRPCOD] is null
and a.[MATSBOCOD] is null and a.[MATTIPCOD] is null
select a.vtrpatnum from psi_vtr a left outer join vtr b on
a.vtrpatnum = b.vtrpatnum
where b.vtrpatnum is null
select distinct o.name, f.* from sys.foreign_keys f join sys.objects o on
f.parent_object_id = o.object_id
where is_not_trusted = 1
select * from sys.check_constraints where is_not_trusted = 1
-- extarir registros da MAT, pai da PAT
select * from mat where
matclecod = 1 and matscscod = 1 and matgrpcod = 40 and matsbocod = 142 and mattipcod = 3
SELECT MATCLECOD
,MATSCSCOD
,MATGRPCOD
,MATSBOCOD
,MATTIPCOD
,MATTIPDES
,MATDGT
,MATDURTPON
,MATETQFLG
,MATHISFLG
,MATREMNT
,CASE WHEN MATDATMNT < '1753-01-01-00.00.00'
THEN TIMESTAMP ('1753-01-01-00.00.00')
ELSE MATDATMNT END AS MATDATMNT
FROM PMESP.MAT
where
matclecod = 1 and matscscod = 1 and matgrpcod = 40 and matsbocod = 142 and mattipcod = 3