--
--  File:     INITIAL_RI_CHECK.SQL
--

PRINT   ''
PRINT   ''
PRINT   '-----------------------------------'
PRINT   '|  DB Primary Key Check - Begin   |'
PRINT   '-----------------------------------'
PRINT   ' '
SELECT  CONVERT(CHAR(30), GETDATE(), 21)
GO


USE tpch1gcci
GO

PRINT   ''
PRINT   ''
PRINT   '-----------------------------------'
PRINT   '|  DB Initial RI Check - Begin   |'
PRINT   '-----------------------------------'
PRINT   ' '
SELECT  CONVERT(CHAR(30), GETDATE(), 21)
GO

SELECT  COUNT_BIG(*)
FROM    PARTSUPP
WHERE   PS_PARTKEY NOT IN ( SELECT  P_PARTKEY
                            FROM    PART)

SELECT  COUNT_BIG(*)
FROM    PARTSUPP
WHERE   PS_SUPPKEY NOT IN ( SELECT  S_SUPPKEY
                            FROM    SUPPLIER)

SELECT  COUNT_BIG(*)
FROM    SUPPLIER
WHERE   S_NATIONKEY NOT IN ( SELECT N_NATIONKEY
                             FROM   NATION)

SELECT  COUNT_BIG(*)
FROM    LINEITEM
WHERE   L_SUPPKEY NOT IN (  SELECT  S_SUPPKEY
                            FROM    SUPPLIER)

SELECT  COUNT_BIG(*)
FROM    LINEITEM
WHERE   L_PARTKEY NOT IN (  SELECT  P_PARTKEY
                            FROM    PART)

SELECT  COUNT_BIG(*)
FROM    LINEITEM
WHERE   L_ORDERKEY NOT IN ( SELECT  O_ORDERKEY
                            FROM    ORDERS)
SELECT  COUNT_BIG(*)
FROM    LINEITEM
WHERE   L_SUPPKEY NOT IN (  SELECT  PS_SUPPKEY
                            FROM    PARTSUPP WHERE PS_PARTKEY = L_PARTKEY)
SELECT  COUNT_BIG(*)
FROM    ORDERS
WHERE   O_CUSTKEY NOT IN (  SELECT  C_CUSTKEY
                            FROM    CUSTOMER)

SELECT  COUNT_BIG(*)
FROM    CUSTOMER
WHERE   C_NATIONKEY NOT IN (SELECT  N_NATIONKEY
                            FROM    NATION)

SELECT  COUNT_BIG(*)
FROM    NATION
WHERE   N_REGIONKEY NOT IN (SELECT  R_REGIONKEY
                            FROM    REGION)
GO

PRINT   ''
PRINT   ''
PRINT   '-----------------------------------'
PRINT   '|  DB Initial RI Check - End   |'
PRINT   '-----------------------------------'
PRINT   ' '
SELECT  CONVERT(CHAR(30), GETDATE(), 21)
GO
