----------------------------------------------------------------
--                                                              
--  File:   DB_Primary_Key_Check.SQL                            
--          Microsoft TPC-E Benchmark Kit Ver. 1.14.0-1031      
--          Copyright Microsoft, 2008-2015                  
--                                                              
----------------------------------------------------------------
USE tpce
GO

SET NOCOUNT ON
GO

-- set the MAX Degree of Parallelism to 0 for this runtime
sp_configure    'max degree of parallelism',0
GO

-- reconfigure the server so the MAXDOP will take effect
RECONFIGURE WITH OVERRIDE
GO

PRINT   ''
PRINT   ''
PRINT   '-----------------------------------'
PRINT   '|  DB Primary Key Check - Begin   |'
PRINT   '-----------------------------------'
PRINT   ' '
SELECT  CONVERT(CHAR(30), GETDATE(), 21)
GO
                                    
DECLARE 
        --- Fixed Tables Local Variables ---
        @VAL            bigint,
        @CH_TT_ID       char(3),
        @CH_C_TIER      tinyint,
        @CR_C_TIER      tinyint,
        @CR_TT_ID       char(3),
        @CR_EX_ID       char(6),
        @CR_FROM_QTY    numeric(6),
        @EX_ID          char(6),
        @IN_ID          char(2),
        @SC_ID          char(2),
        @ST_ID          char(4),
        @TX_ID          char(4),
        @TT_ID          char(3),
        @ZC_CODE        varchar(12),
        --- Scaling Tables Local Variables --
        @AP_CA_ID       bigint,
        @AP_TAX_ID      char(20),
        @AD_ID          bigint,
        @CO_ID          bigint,
        @CP_CO_ID       bigint,
        @CP_COMP_CO_ID  bigint,
        @CP_IN_ID       char(2),
        @C_ID           bigint,
        @CA_ID          bigint,
        @CX_C_ID        bigint,
        @CX_TX_ID       char(4),
        @DM_DATE        datetime,
        @DM_S_SYMB      varchar(15),
        @FI_CO_ID       bigint,
        @FI_YEAR        smallint,
        @FI_QTR         tinyint,
        @LT_S_SYMB      varchar(15),
        @NI_ID          bigint,
        @NX_CO_ID       bigint,
        @NX_NI_ID       bigint,
        @S_SYMB         varchar(15),
        @WI_WL_ID       bigint,
        @WI_S_SYMB      varchar(15),
        @WL_ID          bigint,
        --- Growing Tables Local Variables --
        @B_ID           bigint,
        @TH_T_ID        bigint,
        @TH_ST_ID       char(4),
        @CT_T_ID        bigint,
        @SE_T_ID        bigint,
        @H_T_ID         bigint,
        @HH_H_T_ID      bigint,
        @HH_T_ID        bigint,
        @HS_CA_ID       bigint,
        @HS_S_SYMB      varchar(15),
        @T_ID           bigint,
        @TR_T_ID        bigint,
        --- Other Local Variables --
        @num_custs      bigint,
        @cust_id1       bigint,
        @cust_id2       bigint,
        @acct_id1       bigint,
        @acct_id2       bigint,
        @id1            bigint,
        @id2            bigint,
        @trade_id1      bigint,
        @trade_id2      bigint

PRINT   'TPC-E Fixed Tables Start'
SELECT  CONVERT(CHAR(30), GETDATE(), 21)
PRINT   ' '

--------------
--- CHARGE ---
--------------
PRINT   ' '
PRINT   '**************'
PRINT   '*** CHARGE ***'
PRINT   '**************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From CHARGE'
SELECT  TOP (1) CH_TT_ID,
        CH_C_TIER
FROM    CHARGE
ORDER   BY CH_TT_ID     ASC,
           CH_C_TIER    ASC

SELECT  @VAL    = ( (SELECT NUM_CHARGE_ROWS
                     FROM   TPCE_FIXED_TABLES)
                    + 1) / 3    
		
SET     ROWCOUNT    @VAL

SELECT  @CH_TT_ID   = CH_TT_ID,
        @CH_C_TIER  = CH_C_TIER
FROM    CHARGE
ORDER   BY  CH_TT_ID        ASC,
            CH_C_TIER       ASC

PRINT   ' '
PRINT   'One-Third Through CHARGE'
SELECT  CH_TT_ID,
        CH_C_TIER
FROM    CHARGE
WHERE   CH_TT_ID    = @CH_TT_ID AND
        CH_C_TIER   = @CH_C_TIER


SET     ROWCOUNT    @VAL

SELECT  @CH_TT_ID   = CH_TT_ID,
        @CH_C_TIER  = CH_C_TIER
FROM    CHARGE
ORDER   BY  CH_TT_ID     DESC,
            CH_C_TIER    DESC

PRINT   ' '
PRINT   'Two-Thirds Through CHARGE'
SELECT  CH_TT_ID,
        CH_C_TIER
FROM    CHARGE
WHERE   CH_TT_ID    = @CH_TT_ID AND
        CH_C_TIER   = @CH_C_TIER

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From CHARGE'
SELECT  TOP (1) CH_TT_ID,
        CH_C_TIER
FROM    CHARGE
ORDER   BY  CH_TT_ID     DESC,
            CH_C_TIER    DESC

-----------------------
--- COMMISSION_RATE ---
-----------------------
PRINT   ' '
PRINT   '***********************'
PRINT   '*** COMMISSION_RATE ***'
PRINT   '***********************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From COMMISSION_RATE'
SELECT  TOP (1) CR_C_TIER,
        CR_TT_ID,
        CR_EX_ID,
        CR_FROM_QTY
FROM    COMMISSION_RATE
ORDER   BY CR_C_TIER    ASC,
        CR_TT_ID        ASC,
        CR_EX_ID        ASC,
        CR_FROM_QTY     ASC

SELECT  @VAL    = ( (SELECT NUM_COMM_RATE_ROWS
                     FROM   TPCE_FIXED_TABLES)
                    + 1) / 3    
		
SET     ROWCOUNT    @VAL

SELECT  @CR_C_TIER      = CR_C_TIER,
        @CR_TT_ID       = CR_TT_ID,
        @CR_EX_ID       = CR_EX_ID,
        @CR_FROM_QTY    = CR_FROM_QTY
FROM    COMMISSION_RATE
ORDER   BY CR_C_TIER    ASC,
        CR_TT_ID        ASC,
        CR_EX_ID        ASC,
        CR_FROM_QTY     ASC

PRINT   ' '
PRINT   'One-Third Through COMMISSION_RATE'
SELECT  CR_C_TIER,
        CR_TT_ID,
        CR_EX_ID,
        CR_FROM_QTY
FROM    COMMISSION_RATE
WHERE   CR_C_TIER      = @CR_C_TIER AND
        CR_TT_ID       = @CR_TT_ID AND
        CR_EX_ID       = @CR_EX_ID AND
        CR_FROM_QTY    = @CR_FROM_QTY

SET     ROWCOUNT    @VAL

SELECT  @CR_C_TIER      = CR_C_TIER,
        @CR_TT_ID       = CR_TT_ID,
        @CR_EX_ID       = CR_EX_ID,
        @CR_FROM_QTY    = CR_FROM_QTY
FROM    COMMISSION_RATE
ORDER   BY CR_C_TIER    DESC,
        CR_TT_ID        DESC,
        CR_EX_ID        DESC,
        CR_FROM_QTY     DESC

PRINT   ' '
PRINT   'Two-Thirds Through COMMISSION_RATE'
SELECT  CR_C_TIER,
        CR_TT_ID,
        CR_EX_ID,
        CR_FROM_QTY
FROM    COMMISSION_RATE
WHERE   CR_C_TIER      = @CR_C_TIER AND
        CR_TT_ID       = @CR_TT_ID AND
        CR_EX_ID       = @CR_EX_ID AND
        CR_FROM_QTY    = @CR_FROM_QTY

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From COMMISSION_RATE'
SELECT  TOP (1) CR_C_TIER,
        CR_TT_ID,
        CR_EX_ID,
        CR_FROM_QTY
FROM    COMMISSION_RATE
ORDER   BY CR_C_TIER    DESC,
        CR_TT_ID        DESC,
        CR_EX_ID        DESC,
        CR_FROM_QTY     DESC

----------------
--- EXCHANGE ---
----------------
PRINT   ' '
PRINT   '****************'
PRINT   '*** EXCHANGE ***'
PRINT   '****************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From EXCHANGE'
SELECT  TOP (1) EX_ID
FROM    EXCHANGE
ORDER   BY EX_ID    ASC

SELECT  @VAL    = ( (SELECT NUM_EXCHANGE_ROWS
                     FROM   TPCE_FIXED_TABLES)
                    + 1) / 3 + 1   
	
SET     ROWCOUNT    @VAL

SELECT  @EX_ID  = EX_ID
FROM    EXCHANGE
ORDER   BY EX_ID    ASC

PRINT   ' '
PRINT   'One-Third Through EXCHANGE'
SELECT  EX_ID
FROM    EXCHANGE
WHERE   EX_ID   = @EX_ID

SET     ROWCOUNT    @VAL

SELECT  @EX_ID  = EX_ID
FROM    EXCHANGE
ORDER   BY EX_ID    DESC

PRINT   ' '
PRINT   'Two-Thirds Through EXCHANGE'
SELECT  EX_ID
FROM    EXCHANGE
WHERE   EX_ID   = @EX_ID

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From EXCHANGE'
SELECT  TOP (1) EX_ID
FROM    EXCHANGE
ORDER   BY EX_ID    DESC

----------------
--- INDUSTRY ---
----------------
PRINT   ' '
PRINT   '****************'
PRINT   '*** INDUSTRY ***'
PRINT   '****************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From INDUSTRY'
SELECT  TOP (1) IN_ID
FROM    INDUSTRY
ORDER   BY IN_ID    ASC

SELECT  @VAL    = ( (SELECT NUM_INDUSTRY_ROWS
                     FROM   TPCE_FIXED_TABLES)
                    + 1) / 3    
	
SET     ROWCOUNT    @VAL

SELECT  @IN_ID  = IN_ID
FROM    INDUSTRY
ORDER   BY IN_ID    ASC

PRINT   ' '
PRINT   'One-Third Through INDUSTRY'
SELECT  IN_ID
FROM    INDUSTRY
WHERE   @IN_ID  = IN_ID

SET     ROWCOUNT    @VAL

SELECT  @IN_ID  = IN_ID
FROM    INDUSTRY
ORDER   BY IN_ID    DESC

PRINT   ' '
PRINT   'Two-Thirds Through INDUSTRY'
SELECT  IN_ID
FROM    INDUSTRY
WHERE   @IN_ID  = IN_ID

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From INDUSTRY'
SELECT  TOP (1) IN_ID
FROM    INDUSTRY
ORDER   BY IN_ID    DESC

--------------
--- SECTOR ---
--------------
PRINT   ' '
PRINT   '**************'
PRINT   '*** SECTOR ***'
PRINT   '**************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From SECTOR'
SELECT  TOP (1) SC_ID
FROM    SECTOR
ORDER   BY SC_ID    ASC

SELECT  @VAL    = ( (SELECT NUM_SECTOR_ROWS
                     FROM   TPCE_FIXED_TABLES)
                    + 1) / 3    
	
SET     ROWCOUNT    @VAL

SELECT  @SC_ID  = SC_ID
FROM    SECTOR
ORDER   BY SC_ID    ASC

PRINT   ' '
PRINT   'One-Third Through SECTOR'
SELECT  SC_ID
FROM    SECTOR
WHERE   @SC_ID  = SC_ID

SET     ROWCOUNT    @VAL

SELECT  @SC_ID  = SC_ID
FROM    SECTOR
ORDER   BY SC_ID    DESC

PRINT   ' '
PRINT   'Two-Thirds Through SECTOR'
SELECT  SC_ID
FROM    SECTOR
WHERE   @SC_ID  = SC_ID

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From SECTOR'
SELECT  TOP (1) SC_ID
FROM    SECTOR
ORDER   BY SC_ID    DESC

-------------------
--- STATUS_TYPE ---
-------------------
PRINT   ' '
PRINT   '*******************'
PRINT   '*** STATUS_TYPE ***'
PRINT   '*******************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From STATUS_TYPE'
SELECT  TOP (1) ST_ID
FROM    STATUS_TYPE

SELECT  @VAL    = ( (SELECT NUM_STATUS_TYPE_ROWS
                     FROM   TPCE_FIXED_TABLES)
                    + 1) / 3    
	
SET     ROWCOUNT    @VAL

SELECT  @ST_ID  = ST_ID
FROM    STATUS_TYPE

PRINT   ' '
PRINT   'One-Third Through STATUS_TYPE'
SELECT  ST_ID
FROM    STATUS_TYPE
WHERE   @ST_ID  = ST_ID

SET     @VAL    = @VAL * 2

SET     ROWCOUNT    @VAL

SELECT  @ST_ID  = ST_ID
FROM    STATUS_TYPE

PRINT   ' '
PRINT   'Two-Thirds Through STATUS_TYPE'
SELECT  ST_ID
FROM    STATUS_TYPE
WHERE   @ST_ID  = ST_ID

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From STATUS_TYPE'
SELECT  TOP (1) ST_ID
FROM    STATUS_TYPE
ORDER   BY ST_ID    DESC

---------------
--- TAXRATE ---
---------------
PRINT   ' '
PRINT   '***************'
PRINT   '*** TAXRATE ***'
PRINT   '***************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From TAXRATE'
SELECT  TOP (1) TX_ID
FROM    TAXRATE
ORDER   BY TX_ID    ASC

SELECT  @VAL    = ( (SELECT NUM_TAXRATE_ROWS
                     FROM   TPCE_FIXED_TABLES)
                    + 1) / 3    
	
SET     ROWCOUNT    @VAL

SELECT  @TX_ID  = TX_ID
FROM    TAXRATE
ORDER   BY TX_ID    ASC

PRINT   ' '
PRINT   'One-Third Through TAXRATE'
SELECT  TX_ID
FROM    TAXRATE
WHERE   @TX_ID  = TX_ID

SET     ROWCOUNT    @VAL

SELECT  @TX_ID  = TX_ID
FROM    TAXRATE
ORDER   BY TX_ID    DESC

PRINT   ' '
PRINT   'Two-Thirds Through TAXRATE'
SELECT  TX_ID
FROM    TAXRATE
WHERE   @TX_ID  = TX_ID

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From TAXRATE'
SELECT  TOP (1) TX_ID
FROM    TAXRATE
ORDER   BY TX_ID    DESC

------------------
--- TRADE_TYPE ---
------------------
PRINT   ' '
PRINT   '******************'
PRINT   '*** TRADE_TYPE ***'
PRINT   '******************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From TRADE_TYPE'
SELECT  TOP (1) TT_ID
FROM    TRADE_TYPE

SELECT  @VAL    = ( (SELECT NUM_TRADE_TYPE_ROWS
                     FROM   TPCE_FIXED_TABLES)
                    + 1) / 3    
	
SET     ROWCOUNT    @VAL

SELECT  @TT_ID  = TT_ID
FROM    TRADE_TYPE

PRINT   ' '
PRINT   'One-Third Through TRADE_TYPE'
SELECT  TT_ID
FROM    TRADE_TYPE
WHERE   @TT_ID  = TT_ID

SET     @VAL    = @VAL * 2

SET     ROWCOUNT    @VAL

SELECT  @TT_ID  = TT_ID
FROM    TRADE_TYPE

PRINT   ' '
PRINT   'Two-Thirds Through TRADE_TYPE'
SELECT  TT_ID
FROM    TRADE_TYPE
WHERE   @TT_ID  = TT_ID

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From TRADE_TYPE'
SELECT  TOP (1) TT_ID
FROM    TRADE_TYPE
ORDER   BY TT_ID    DESC

----------------
--- ZIP_CODE ---
----------------
PRINT   ' '
PRINT   '****************'
PRINT   '*** ZIP_CODE ***'
PRINT   '****************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From ZIP_CODE'
SELECT  TOP (1) ZC_CODE
FROM    ZIP_CODE
ORDER   BY ZC_CODE  ASC

SELECT  @VAL    = ( (SELECT NUM_ZIP_CODE_ROWS
                     FROM   TPCE_FIXED_TABLES)
                    + 1) / 3    
	
SET     ROWCOUNT    @VAL

SELECT  @ZC_CODE  = ZC_CODE
FROM    ZIP_CODE
ORDER   BY ZC_CODE  ASC

PRINT   ' '
PRINT   'One-Third Through ZIP_CODE'
SELECT  ZC_CODE
FROM    ZIP_CODE
WHERE   @ZC_CODE  = ZC_CODE

SET     ROWCOUNT    @VAL

SELECT  @ZC_CODE  = ZC_CODE
FROM    ZIP_CODE
ORDER   BY ZC_CODE  DESC

PRINT   ' '
PRINT   'Two-Thirds Through ZIP_CODE'
SELECT  ZC_CODE
FROM    ZIP_CODE
WHERE   @ZC_CODE  = ZC_CODE

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From ZIP_CODE'
SELECT  TOP (1) ZC_CODE
FROM    ZIP_CODE
ORDER   BY ZC_CODE  DESC

PRINT   ' '
PRINT   'TPC-E Fixed Tables End'
SELECT  CONVERT(CHAR(30), GETDATE(), 21)

PRINT   ' '
PRINT   'TPC-E Scaling Tables Start'
SELECT  CONVERT(CHAR(30), GETDATE(), 21)
PRINT   ' '

-- Total Customers in Database
SELECT  @num_custs = (SELECT NUM_CUST_ROWS
                      FROM   TPCE_SCALING_TABLES)
-- 1/3rd and 2/3rds Customer Ids
SET     @cust_id1 = (  @num_custs/3)+4300000001
SET     @cust_id2 = (2*@num_custs/3)+4300000001
-- 1/3rd and approximate 2/3rds Account Ids
SET     @acct_id1 = 10*(  @num_custs/3)+43000000001
SET     @acct_id2 = 10*(2*@num_custs/3)+43000000010

--------------------------
--- ACCOUNT_PERMISSION ---
--------------------------
PRINT   ' '
PRINT   '**************************'
PRINT   '*** ACCOUNT_PERMISSION ***'
PRINT   '**************************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From ACCOUNT_PERMISSION'
SELECT  TOP (1) AP_CA_ID,
        AP_TAX_ID
FROM    ACCOUNT_PERMISSION
ORDER   BY AP_CA_ID     ASC,
           AP_TAX_ID    ASC

PRINT   ' '
PRINT   'One-Third Through ACCOUNT_PERMISSION'
SELECT  TOP (1) AP_CA_ID,
        AP_TAX_ID
FROM    ACCOUNT_PERMISSION
WHERE   AP_CA_ID >= @acct_id1
ORDER   BY AP_CA_ID     ASC,
           AP_TAX_ID    ASC

PRINT   ' '
PRINT   'Two-Thirds Through ACCOUNT_PERMISSION'
SELECT  TOP (1) AP_CA_ID,
        AP_TAX_ID
FROM    ACCOUNT_PERMISSION
WHERE   AP_CA_ID <= @acct_id2
ORDER   BY AP_CA_ID     DESC,
           AP_TAX_ID    DESC

PRINT   ' '
PRINT   'Maximum Primary Key ID From ACCOUNT_PERMISSION'
SELECT  TOP (1) AP_CA_ID,
        AP_TAX_ID
FROM    ACCOUNT_PERMISSION
ORDER   BY AP_CA_ID     DESC,
           AP_TAX_ID    DESC

---------------
--- ADDRESS ---
---------------
PRINT   ' '
PRINT   '***************'
PRINT   '*** ADDRESS ***'
PRINT   '***************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From ADDRESS'
SELECT  TOP (1) AD_ID
FROM    ADDRESS
ORDER   BY AD_ID    ASC

PRINT   ' '
PRINT   'One-Third Through ADDRESS'
SET     @id1 = (@num_custs/2)+4300000004
SELECT  AD_ID
FROM    ADDRESS
WHERE   AD_ID = @id1

PRINT   ' '
PRINT   'Two-Thirds Through ADDRESS'
SET     @id2 = (@num_custs)+4300000004
SELECT  AD_ID
FROM    ADDRESS
WHERE   AD_ID = @id2

PRINT   ' '
PRINT   'Maximum Primary Key ID From ADDRESS'
SELECT  TOP (1) AD_ID
FROM    ADDRESS
ORDER   BY AD_ID    DESC

---------------
--- COMPANY ---
---------------
PRINT   ' '
PRINT   '***************'
PRINT   '*** COMPANY ***'
PRINT   '***************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From COMPANY'
SELECT  TOP (1) CO_ID
FROM    COMPANY
ORDER   BY CO_ID    ASC

PRINT   ' '
PRINT   'One-Third Through COMPANY'
SET     @id1 = (@num_custs/6)+4300000001
SELECT  CO_ID
FROM    COMPANY
WHERE   CO_ID  = @id1

PRINT   ' '
PRINT   'Two-Thirds Through COMPANY'
SET     @id2 = (@num_custs/3)+4300000001
SELECT  CO_ID
FROM    COMPANY
WHERE   CO_ID  = @id2

PRINT   ' '
PRINT   'Maximum Primary Key ID From COMPANY'
SELECT  TOP (1) CO_ID
FROM    COMPANY
ORDER   BY CO_ID    DESC

--------------------------
--- COMPANY_COMPETITOR ---
--------------------------
PRINT   ' '
PRINT   '**************************'
PRINT   '*** COMPANY_COMPETITOR ***'
PRINT   '**************************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From COMPANY_COMPETITOR'
SELECT  TOP (1) CP_CO_ID,
        CP_COMP_CO_ID,
        CP_IN_ID
FROM    COMPANY_COMPETITOR
ORDER   BY CP_CO_ID         ASC,
           CP_COMP_CO_ID    ASC

PRINT   ' '
PRINT   'One-Third Through COMPANY_COMPETITOR'
SELECT  TOP (1) CP_CO_ID,
        CP_COMP_CO_ID,
        CP_IN_ID
FROM    COMPANY_COMPETITOR
WHERE   CP_CO_ID = @id1
ORDER   BY CP_CO_ID         ASC,
           CP_COMP_CO_ID    ASC

PRINT   ' '
PRINT   'Two-Thirds Through COMPANY_COMPETITOR'
SELECT  TOP (1) CP_CO_ID,
        CP_COMP_CO_ID,
        CP_IN_ID
FROM    COMPANY_COMPETITOR
WHERE   CP_CO_ID = @id2
ORDER   BY CP_CO_ID         DESC,
           CP_COMP_CO_ID    DESC

PRINT   ' '
PRINT   'Maximum Primary Key ID From COMPANY_COMPETITOR'
SELECT  TOP (1) CP_CO_ID,
        CP_COMP_CO_ID,
        CP_IN_ID
FROM    COMPANY_COMPETITOR
ORDER   BY CP_CO_ID         DESC,
           CP_COMP_CO_ID    DESC

----------------
--- CUSTOMER ---
----------------
PRINT   ' '
PRINT   '****************'
PRINT   '*** CUSTOMER ***'
PRINT   '****************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From CUSTOMER'
SELECT  TOP (1) C_ID
FROM    CUSTOMER
ORDER   BY C_ID    ASC

PRINT   ' '
PRINT   'One-Third Through CUSTOMER'
SELECT  C_ID
FROM    CUSTOMER
WHERE   C_ID = @cust_id1

PRINT   ' '
PRINT   'Two-Thirds Through CUSTOMER'
SELECT  C_ID
FROM    CUSTOMER
WHERE   C_ID = @cust_id2

PRINT   ' '
PRINT   'Maximum Primary Key ID From CUSTOMER'
SELECT  TOP (1) C_ID
FROM    CUSTOMER
ORDER   BY C_ID DESC

------------------------
--- CUSTOMER_ACCOUNT ---
------------------------
PRINT   ' '
PRINT   '************************'
PRINT   '*** CUSTOMER_ACCOUNT ***'
PRINT   '************************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From CUSTOMER_ACCOUNT'
SELECT  TOP (1) CA_ID
FROM    CUSTOMER_ACCOUNT
ORDER   BY CA_ID    ASC

PRINT   ' '
PRINT   'One-Third Through CUSTOMER_ACCOUNT'
SELECT  TOP (1) CA_ID
FROM    CUSTOMER_ACCOUNT
WHERE   CA_ID >= @acct_id1
ORDER   BY CA_ID    ASC

PRINT   ' '
PRINT   'Two-Thirds Through CUSTOMER_ACCOUNT'
SELECT  TOP (1) CA_ID
FROM    CUSTOMER_ACCOUNT
WHERE   CA_ID <= @acct_id2
ORDER   BY CA_ID    DESC

PRINT   ' '
PRINT   'Maximum Primary Key ID From CUSTOMER_ACCOUNT'
SELECT  TOP (1) CA_ID
FROM    CUSTOMER_ACCOUNT
ORDER   BY CA_ID    DESC

------------------------
--- CUSTOMER_TAXRATE ---
------------------------
PRINT   ' '
PRINT   '************************'
PRINT   '*** CUSTOMER_TAXRATE ***'
PRINT   '************************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From CUSTOMER_TAXRATE'
SELECT  TOP (1) CX_C_ID,
        CX_TX_ID
FROM    CUSTOMER_TAXRATE

SELECT  @VAL    = (@num_custs + 1) / 3    
		
SET     ROWCOUNT    @VAL

SELECT  @CX_C_ID    = CX_C_ID,
        @CX_TX_ID   = CX_TX_ID
FROM    CUSTOMER_TAXRATE
ORDER   BY CX_C_ID  ASC,
           CX_TX_ID ASC

PRINT   ' '
PRINT   'One-Third Through CUSTOMER_TAXRATE'
SELECT  CX_C_ID,
        CX_TX_ID
FROM    CUSTOMER_TAXRATE
WHERE   @CX_C_ID    = CX_C_ID AND
        @CX_TX_ID   = CX_TX_ID
ORDER   BY CX_C_ID  ASC,
           CX_TX_ID ASC

--SET     @VAL    = @VAL * 2
SET     ROWCOUNT    @VAL

SELECT  @CX_C_ID    = CX_C_ID,
        @CX_TX_ID   = CX_TX_ID
FROM    CUSTOMER_TAXRATE
ORDER   BY CX_C_ID  DESC,
           CX_TX_ID DESC

PRINT   ' '
PRINT   'Two-Thirds Through CUSTOMER_TAXRATE'
SELECT  CX_C_ID,
        CX_TX_ID
FROM    CUSTOMER_TAXRATE
WHERE   @CX_C_ID    = CX_C_ID AND
        @CX_TX_ID   = CX_TX_ID

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From CUSTOMER_TAXRATE'
SELECT  TOP (1) CX_C_ID,
        CX_TX_ID
FROM    CUSTOMER_TAXRATE
ORDER   BY CX_C_ID  DESC,
           CX_TX_ID DESC

--------------------
--- DAILY_MARKET ---
--------------------
PRINT   ' '
PRINT   '********************'
PRINT   '*** DAILY_MARKET ***'
PRINT   '********************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From DAILY_MARKET'
SELECT  TOP (1) DM_S_SYMB,
        DM_DATE
FROM    DAILY_MARKET
ORDER   BY DM_S_SYMB    ASC,
           DM_DATE      ASC

SELECT  @VAL    = ( (SELECT NUM_SECURITY_ROWS
                     FROM   TPCE_SCALING_TABLES)
                    + 1) / 3
                        
SET     ROWCOUNT    @VAL

SELECT  @DM_S_SYMB  = S_SYMB
FROM    SECURITY
ORDER   BY S_SYMB   ASC

SET		ROWCOUNT	435		-- 1/3rd of 1305 Days per Security

SELECT  @DM_DATE    = DM_DATE
FROM    DAILY_MARKET
WHERE   DM_S_SYMB   = @DM_S_SYMB
ORDER   BY DM_DATE  ASC

PRINT   ' '
PRINT   'One-Third Through DAILY_MARKET'
SELECT  DM_S_SYMB,
        DM_DATE
FROM    DAILY_MARKET
WHERE   @DM_S_SYMB  = DM_S_SYMB AND
        @DM_DATE    = DM_DATE

SET     ROWCOUNT    @VAL

SELECT  @DM_S_SYMB  = S_SYMB
FROM    SECURITY
ORDER   BY S_SYMB   DESC

SET		ROWCOUNT	435		-- 1/3rd of 1305 Days per Security

SELECT  @DM_DATE    = DM_DATE
FROM    DAILY_MARKET
WHERE   DM_S_SYMB   = @DM_S_SYMB
ORDER   BY DM_DATE  DESC

PRINT   ' '
PRINT   'Two-Thirds Through DAILY_MARKET'
SELECT  DM_S_SYMB,
        DM_DATE
FROM    DAILY_MARKET
WHERE   @DM_S_SYMB  = DM_S_SYMB AND
        @DM_DATE    = DM_DATE

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From DAILY_MARKET'
SELECT  TOP (1) DM_S_SYMB,
        DM_DATE
FROM    DAILY_MARKET
ORDER   BY DM_S_SYMB    DESC,
           DM_DATE      DESC

-----------------
--- FINANCIAL ---
-----------------
PRINT   ' '
PRINT   '*****************'
PRINT   '*** FINANCIAL ***'
PRINT   '*****************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From FINANCIAL'
SELECT  TOP (1) FI_CO_ID,
        FI_YEAR,
        FI_QTR
FROM    FINANCIAL
ORDER   BY FI_CO_ID ASC,
           FI_YEAR  ASC,
           FI_QTR   ASC

SELECT  @VAL    = ( (SELECT NUM_FINANCIAL_ROWS
                     FROM   TPCE_SCALING_TABLES)
                    + 1) / 3 
                       
SET     ROWCOUNT    @VAL

SELECT  @FI_CO_ID   = FI_CO_ID,
        @FI_YEAR    = FI_YEAR,
        @FI_QTR     = FI_QTR
FROM    FINANCIAL
ORDER   BY FI_CO_ID ASC,
           FI_YEAR  ASC,
           FI_QTR   ASC

PRINT   ' '
PRINT   'One-Third Through FINANCIAL'
SELECT  FI_CO_ID,
        FI_YEAR,
        FI_QTR
FROM    FINANCIAL
WHERE   @FI_CO_ID   = FI_CO_ID AND
        @FI_YEAR    = FI_YEAR AND
        @FI_QTR     = FI_QTR

--SET     @VAL    = @VAL * 2
SET     ROWCOUNT    @VAL

SELECT  @FI_CO_ID   = FI_CO_ID,
        @FI_YEAR    = FI_YEAR,
        @FI_QTR     = FI_QTR
FROM    FINANCIAL
ORDER   BY FI_CO_ID DESC,
           FI_YEAR  DESC,
           FI_QTR   DESC

PRINT   ' '
PRINT   'Two-Thirds Through FINANCIAL'
SELECT  FI_CO_ID,
        FI_YEAR,
        FI_QTR
FROM    FINANCIAL
WHERE   @FI_CO_ID   = FI_CO_ID AND
        @FI_YEAR    = FI_YEAR AND
        @FI_QTR     = FI_QTR

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From FINANCIAL'
SELECT  TOP (1) FI_CO_ID,
        FI_YEAR,
        FI_QTR
FROM    FINANCIAL
ORDER   BY FI_CO_ID DESC,
           FI_YEAR  DESC,
           FI_QTR   DESC

------------------
--- LAST_TRADE ---
------------------
PRINT   ' '
PRINT   '******************'
PRINT   '*** LAST_TRADE ***'
PRINT   '******************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From LAST_TRADE'
SELECT  TOP (1) LT_S_SYMB
FROM    LAST_TRADE
ORDER   BY LT_S_SYMB    ASC

SELECT  @VAL    = ( (SELECT NUM_LAST_TRADE_ROWS
                     FROM   TPCE_SCALING_TABLES)
                    + 1) / 3  
                      
SET     ROWCOUNT    @VAL

SELECT  @LT_S_SYMB  = LT_S_SYMB
FROM    LAST_TRADE
ORDER   BY LT_S_SYMB    ASC

PRINT   ' '
PRINT   'One-Third Through LAST_TRADE'
SELECT  LT_S_SYMB
FROM    LAST_TRADE
WHERE   @LT_S_SYMB  = LT_S_SYMB

--SET     @VAL    = @VAL * 2
SET     ROWCOUNT    @VAL

SELECT  @LT_S_SYMB  = LT_S_SYMB
FROM    LAST_TRADE
ORDER   BY LT_S_SYMB    DESC

PRINT   ' '
PRINT   'Two-Thirds Through LAST_TRADE'
SELECT  LT_S_SYMB
FROM    LAST_TRADE
WHERE   @LT_S_SYMB  = LT_S_SYMB

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From LAST_TRADE'
SELECT  TOP (1) LT_S_SYMB
FROM    LAST_TRADE
ORDER   BY LT_S_SYMB    DESC

-----------------
--- NEWS_ITEM ---
-----------------
PRINT   ' '
PRINT   '*****************'
PRINT   '*** NEWS_ITEM ***'
PRINT   '*****************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From NEWS_ITEM'
SELECT  TOP (1) NI_ID
FROM    NEWS_ITEM
ORDER   BY NI_ID	ASC

SELECT  @VAL    = ( (SELECT NUM_NEWS_ITEM_ROWS
                     FROM   TPCE_SCALING_TABLES)
                    + 1) / 3    
		
SET     ROWCOUNT    @VAL

SELECT  @NI_ID  = NI_ID
FROM    NEWS_ITEM
ORDER   BY NI_ID	ASC

PRINT   ' '
PRINT   'One-Third Through NEWS_ITEM'
SELECT  NI_ID
FROM    NEWS_ITEM
WHERE   @NI_ID  = NI_ID

--SET     @VAL    = @VAL * 2

SET     ROWCOUNT    @VAL

SELECT  @NI_ID  = NI_ID
FROM    NEWS_ITEM
ORDER   BY NI_ID	DESC

PRINT   ' '
PRINT   'Two-Thirds Through NEWS_ITEM'
SELECT  NI_ID
FROM    NEWS_ITEM
WHERE   @NI_ID  = NI_ID

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From NEWS_ITEM'
SELECT  TOP (1) NI_ID
FROM    NEWS_ITEM
ORDER   BY NI_ID    DESC

-----------------
--- NEWS_XREF ---
-----------------
PRINT   ' '
PRINT   '*****************'
PRINT   '*** NEWS_XREF ***'
PRINT   '*****************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From NEWS_XREF'
SELECT  TOP (1) NX_CO_ID,
        NX_NI_ID
FROM    NEWS_XREF
ORDER   BY NX_CO_ID	ASC,
           NX_NI_ID ASC

SELECT  @VAL    = ( (SELECT NUM_NEWS_XREF_ROWS
                     FROM   TPCE_SCALING_TABLES)
                    + 1) / 3    
		
SET     ROWCOUNT    @VAL

SELECT  @NX_CO_ID   = NX_CO_ID,
        @NX_NI_ID   = NX_NI_ID
FROM    NEWS_XREF
ORDER   BY NX_CO_ID ASC,
           NX_NI_ID ASC

PRINT   ' '
PRINT   'One-Third Through NEWS_XREF'
SELECT  NX_CO_ID,
        NX_NI_ID
FROM    NEWS_XREF
WHERE   @NX_CO_ID   = NX_CO_ID AND
        @NX_NI_ID   = NX_NI_ID

--SET     @VAL    = @VAL * 2

SET     ROWCOUNT    @VAL

SELECT  @NX_CO_ID   = NX_CO_ID,
        @NX_NI_ID   = NX_NI_ID
FROM    NEWS_XREF
ORDER   BY NX_CO_ID DESC,
           NX_NI_ID DESC

PRINT   ' '
PRINT   'Two-Thirds Through NEWS_XREF'
SELECT  NX_CO_ID,
        NX_NI_ID
FROM    NEWS_XREF
WHERE   @NX_CO_ID   = NX_CO_ID AND
        @NX_NI_ID   = NX_NI_ID

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From NEWS_XREF'
SELECT  TOP (1) NX_CO_ID,
        NX_NI_ID
FROM    NEWS_XREF
ORDER   BY NX_CO_ID DESC,
           NX_NI_ID DESC

----------------
--- SECURITY ---
----------------
PRINT   ' '
PRINT   '****************'
PRINT   '*** SECURITY ***'
PRINT   '****************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From SECURITY'
SELECT  TOP (1) S_SYMB
FROM    SECURITY
ORDER   BY S_SYMB ASC

SELECT  @VAL    = ( (SELECT NUM_SECURITY_ROWS
                     FROM   TPCE_SCALING_TABLES)
                    + 1) / 3    

SET     ROWCOUNT    @VAL

SELECT  @S_SYMB = S_SYMB
FROM    SECURITY
ORDER   BY S_SYMB ASC

PRINT   ' '
PRINT   'One-Third Through SECURITY'
SELECT  S_SYMB
FROM    SECURITY
WHERE   @S_SYMB = S_SYMB

--SET     @VAL    = @VAL * 2

SET     ROWCOUNT    @VAL

SELECT  @S_SYMB = S_SYMB
FROM    SECURITY
ORDER   BY S_SYMB DESC

PRINT   ' '
PRINT   'Two-Thirds Through SECURITY'
SELECT  S_SYMB
FROM    SECURITY
WHERE   @S_SYMB = S_SYMB

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From SECURITY'
SELECT  TOP (1) S_SYMB
FROM    SECURITY
ORDER   BY S_SYMB DESC

------------------
--- WATCH_ITEM ---
------------------
PRINT   ' '
PRINT   '******************'
PRINT   '*** WATCH_ITEM ***'
PRINT   '******************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From WATCH_ITEM'
SELECT  TOP (1) WI_WL_ID,
        WI_S_SYMB
FROM    WATCH_ITEM
ORDER   BY WI_WL_ID     ASC,
           WI_S_SYMB    ASC

SELECT  @VAL    = ( (SELECT NUM_WATCH_ITEM_ROWS
                     FROM   TPCE_SCALING_TABLES)
                    + 1) / 3    

SET     ROWCOUNT    @VAL

SELECT  @WI_WL_ID   = WI_WL_ID,
        @WI_S_SYMB  = WI_S_SYMB
FROM    WATCH_ITEM
ORDER   BY WI_WL_ID     ASC,
           WI_S_SYMB    ASC

PRINT   ' '
PRINT   'One-Third Through WATCH_ITEM'
SELECT  WI_WL_ID,
        WI_S_SYMB
FROM    WATCH_ITEM
WHERE   @WI_WL_ID   = WI_WL_ID AND
        @WI_S_SYMB  = WI_S_SYMB

--SET     @VAL    = @VAL * 2

SET     ROWCOUNT    @VAL

SELECT  @WI_WL_ID   = WI_WL_ID,
        @WI_S_SYMB  = WI_S_SYMB
FROM    WATCH_ITEM
ORDER   BY WI_WL_ID     DESC,
           WI_S_SYMB    DESC

PRINT   ' '
PRINT   'Two-Thirds Through WATCH_ITEM'
SELECT  WI_WL_ID,
        WI_S_SYMB
FROM    WATCH_ITEM
WHERE   @WI_WL_ID   = WI_WL_ID AND
        @WI_S_SYMB  = WI_S_SYMB

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From WATCH_ITEM'
SELECT  TOP (1) WI_WL_ID,
        WI_S_SYMB
FROM    WATCH_ITEM
ORDER   BY WI_WL_ID     DESC,
           WI_S_SYMB    DESC

------------------
--- WATCH_LIST ---
------------------
PRINT   ' '
PRINT   '******************'
PRINT   '*** WATCH_LIST ***'
PRINT   '******************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From WATCH_LIST'
SELECT  TOP (1) WL_ID
FROM    WATCH_LIST
ORDER   BY WL_ID    ASC

SELECT  @VAL    = ( (SELECT NUM_WATCH_LIST_ROWS
                     FROM   TPCE_SCALING_TABLES)
                    + 1) / 3    

SET     ROWCOUNT    @VAL

SELECT  @WL_ID  = WL_ID
FROM    WATCH_LIST
ORDER   BY WL_ID    ASC

PRINT   ' '
PRINT   'One-Third Through WATCH_LIST'
SELECT  WL_ID
FROM    WATCH_LIST
WHERE   @WL_ID  = WL_ID

--SET     @VAL    = @VAL * 2

SET     ROWCOUNT    @VAL

SELECT  @WL_ID  = WL_ID
FROM    WATCH_LIST
ORDER   BY WL_ID    DESC

PRINT   ' '
PRINT   'Two-Thirds Through WATCH_LIST'
SELECT  WL_ID
FROM    WATCH_LIST
WHERE   @WL_ID  = WL_ID

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From WATCH_LIST'
SELECT  TOP (1) WL_ID
FROM    WATCH_LIST
ORDER   BY WL_ID    DESC

PRINT   ' '
PRINT   'TPC-E Scaling Tables End'
SELECT  CONVERT(CHAR(30), GETDATE(), 21)
PRINT   ' '

PRINT   'TPC-E Growing Tables Start'
SELECT  CONVERT(CHAR(30), GETDATE(), 21)
PRINT   ' '
SELECT  @id1    = ( (  (SELECT (NUM_TRADE_ROWS/100)*101
                        FROM   TPCE_GROWING_TABLES)
                       + 1) / 3) + 200000000000000  
SELECT  @id2    = ( (2*(SELECT (NUM_TRADE_ROWS/100)*101
                        FROM   TPCE_GROWING_TABLES)
                       + 1) / 3) + 200000000000000  

--------------
--- BROKER ---
--------------
PRINT   ' '
PRINT   '**************'
PRINT   '*** BROKER ***'
PRINT   '**************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From BROKER'
SELECT  TOP (1) B_ID
FROM    BROKER
ORDER   BY B_ID	ASC

SELECT  @VAL    = ( (SELECT NUM_BROKER_ROWS
                     FROM   TPCE_SCALING_TABLES)
                    + 1) / 3    
		
SET     ROWCOUNT    @VAL

SELECT  @B_ID   = B_ID
FROM    BROKER
ORDER   BY B_ID	ASC

PRINT   ' '
PRINT   'One-Third Through BROKER'
SELECT  B_ID
FROM    BROKER
WHERE   @B_ID   = B_ID

--SET     @VAL    = @VAL * 2

SET     ROWCOUNT    @VAL

SELECT  @B_ID   = B_ID
FROM    BROKER
ORDER   BY B_ID	DESC

PRINT   ' '
PRINT   'Two-Thirds Through BROKER'
SELECT  B_ID
FROM    BROKER
WHERE   @B_ID   = B_ID

SET     ROWCOUNT    0

PRINT   ' '
PRINT   'Maximum Primary Key ID From BROKER'
SELECT  TOP (1) B_ID
FROM    BROKER
ORDER   BY B_ID DESC

---------------------
--- TRADE_HISTORY ---
---------------------
PRINT   ' '
PRINT   '*********************'
PRINT   '*** TRADE_HISTORY ***'
PRINT   '*********************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From TRADE_HISTORY'
SELECT  TOP (1) TH_T_ID,
        TH_ST_ID
FROM    TRADE_HISTORY
ORDER   BY TH_T_ID  ASC,
           TH_ST_ID ASC

PRINT   ' '
PRINT   'One-Third Through TRADE_HISTORY'
SELECT  TOP (1) TH_T_ID,
        TH_ST_ID
FROM    TRADE_HISTORY
WHERE   TH_T_ID    >= @id1
ORDER   BY TH_T_ID  ASC,
           TH_ST_ID ASC

PRINT   ' '
PRINT   'Two-Thirds Through TRADE_HISTORY'
SELECT  TOP (1) TH_T_ID,
        TH_ST_ID
FROM    TRADE_HISTORY
WHERE   TH_T_ID    <= @id2
ORDER   BY TH_T_ID  DESC,
           TH_ST_ID DESC

PRINT   ' '
PRINT   'Maximum Primary Key ID From TRADE_HISTORY'
SELECT  TOP (1) TH_T_ID,
        TH_ST_ID
FROM    TRADE_HISTORY
ORDER   BY TH_T_ID  DESC,
           TH_ST_ID DESC

------------------------
--- CASH_TRANSACTION ---
------------------------
PRINT   ' '
PRINT   '************************'
PRINT   '*** CASH_TRANSACTION ***'
PRINT   '************************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From CASH_TRANSACTION'
SELECT  TOP (1) CT_T_ID
FROM    CASH_TRANSACTION
ORDER   BY CT_T_ID	ASC

PRINT   ' '
PRINT   'One-Third Through CASH_TRANSACTION'
SELECT  TOP (1) CT_T_ID
FROM    CASH_TRANSACTION
WHERE   CT_T_ID     >= @id1
ORDER   BY CT_T_ID	ASC

PRINT   ' '
PRINT   'Two-Thirds Through CASH_TRANSACTION'
SELECT  TOP (1) CT_T_ID
FROM    CASH_TRANSACTION
WHERE   CT_T_ID     <= @id2
ORDER   BY CT_T_ID	DESC

PRINT   ' '
PRINT   'Maximum Primary Key ID From CASH_TRANSACTION'
SELECT  TOP (1) CT_T_ID
FROM    CASH_TRANSACTION
ORDER   BY CT_T_ID  DESC

------------------
--- SETTLEMENT ---
------------------
PRINT   ' '
PRINT   '******************'
PRINT   '*** SETTLEMENT ***'
PRINT   '******************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From SETTLEMENT'
SELECT  TOP (1) SE_T_ID
FROM    SETTLEMENT
ORDER   BY SE_T_ID	ASC

PRINT   ' '
PRINT   'One-Third Through SETTLEMENT'
SELECT  TOP (1) SE_T_ID
FROM    SETTLEMENT
WHERE   SE_T_ID     >= @id1
ORDER   BY SE_T_ID	ASC

PRINT   ' '
PRINT   'Two-Thirds Through SETTLEMENT'
SELECT  TOP (1) SE_T_ID
FROM    SETTLEMENT
WHERE   SE_T_ID     <= @id2
ORDER   BY SE_T_ID	DESC

PRINT   ' '
PRINT   'Maximum Primary Key ID From SETTLEMENT'
SELECT  TOP (1) SE_T_ID
FROM    SETTLEMENT
ORDER   BY SE_T_ID  DESC

---------------
--- HOLDING ---
---------------
PRINT   ' '
PRINT   '***************'
PRINT   '*** HOLDING ***'
PRINT   '***************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From HOLDING'
SELECT  TOP (1) H_T_ID
FROM    HOLDING
ORDER   BY H_T_ID	ASC

PRINT   ' '
PRINT   'One-Third Through HOLDING'
SELECT  TOP (1) H_T_ID
FROM    HOLDING
WHERE   H_T_ID		>= @id1 
ORDER   BY H_T_ID	ASC

PRINT   ' '
PRINT   'Two-Thirds Through HOLDING'
SELECT  TOP (1) H_T_ID
FROM    HOLDING
WHERE   H_T_ID		<= @id2 
ORDER   BY H_T_ID	DESC

PRINT   ' '
PRINT   'Maximum Primary Key ID From HOLDING'
SELECT  TOP (1) H_T_ID
FROM    HOLDING
ORDER   BY H_T_ID   DESC

-----------------------
--- HOLDING_HISTORY ---
-----------------------
PRINT   ' '
PRINT   '***********************'
PRINT   '*** HOLDING_HISTORY ***'
PRINT   '***********************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From HOLDING_HISTORY'
SELECT  TOP (1) HH_H_T_ID,
        HH_T_ID
FROM    HOLDING_HISTORY
ORDER   BY HH_H_T_ID    ASC,
           HH_T_ID      ASC

PRINT   ' '
PRINT   'One-Third Through HOLDING_HISTORY'
SELECT  TOP (1) HH_H_T_ID,
        HH_T_ID
FROM    HOLDING_HISTORY
WHERE   HH_H_T_ID       >= @id1
ORDER   BY HH_H_T_ID    ASC,
           HH_T_ID      ASC

PRINT   ' '
PRINT   'Two-Thirds Through HOLDING_HISTORY'
SELECT  TOP (1) HH_H_T_ID,
        HH_T_ID
FROM    HOLDING_HISTORY
WHERE   HH_H_T_ID       <= @id2
ORDER   BY HH_H_T_ID    DESC,
           HH_T_ID      DESC

PRINT   ' '
PRINT   'Maximum Primary Key ID From HOLDING_HISTORY'
SELECT  TOP (1) HH_H_T_ID,
        HH_T_ID
FROM    HOLDING_HISTORY
ORDER   BY HH_H_T_ID    DESC,
           HH_T_ID      DESC

-----------------------
--- HOLDING_SUMMARY ---
-----------------------
PRINT   ' '
PRINT   '***********************'
PRINT   '*** HOLDING_SUMMARY ***'
PRINT   '***********************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From HOLDING_SUMMARY'
SELECT  TOP (1) HS_CA_ID,
        HS_S_SYMB
FROM    HOLDING_SUMMARY
ORDER   BY HS_CA_ID     ASC,
           HS_S_SYMB    ASC

PRINT   ' '
PRINT   'One-Third Through HOLDING_SUMMARY'
SELECT  TOP (1) HS_CA_ID,
        HS_S_SYMB
FROM    HOLDING_SUMMARY
WHERE   HS_CA_ID        >= @acct_id1
ORDER   BY HS_CA_ID     ASC,
           HS_S_SYMB    ASC

PRINT   ' '
PRINT   'Two-Thirds Through HOLDING_SUMMARY'
SELECT  TOP (1) HS_CA_ID,
        HS_S_SYMB
FROM    HOLDING_SUMMARY
WHERE   HS_CA_ID        <= @acct_id2
ORDER   BY HS_CA_ID     DESC,
           HS_S_SYMB    DESC

PRINT   ' '
PRINT   'Maximum Primary Key ID From HOLDING_SUMMARY'
SELECT  TOP (1) HS_CA_ID,
        HS_S_SYMB
FROM    HOLDING_SUMMARY
ORDER   BY HS_CA_ID     DESC,
           HS_S_SYMB    DESC

-------------
--- TRADE ---
-------------
PRINT   ' '
PRINT   '*************'
PRINT   '*** TRADE ***'
PRINT   '*************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From TRADE'
SELECT  TOP (1) T_ID
FROM    TRADE
ORDER   BY T_ID	ASC

PRINT   ' '
PRINT   'One-Third Through TRADE'
SELECT  TOP (1) T_ID
FROM    TRADE
WHERE   T_ID    >= @id1
ORDER   BY T_ID	ASC

PRINT   ' '
PRINT   'Two-Thirds Through TRADE'
SELECT  TOP (1) T_ID
FROM    TRADE
WHERE   T_ID    <= @id2
ORDER   BY T_ID	DESC

PRINT   ' '
PRINT   'Maximum Primary Key ID From TRADE'
SELECT  TOP (1) T_ID
FROM    TRADE
ORDER   BY T_ID DESC

---------------------
--- TRADE_REQUEST ---
---------------------
PRINT   ' '
PRINT   '*********************'
PRINT   '*** TRADE_REQUEST ***'
PRINT   '*********************'
PRINT   ' '
PRINT   'Minimum Primary Key ID From TRADE_REQUEST'
SELECT  TOP (1) TR_T_ID
FROM    TRADE_REQUEST
ORDER   BY TR_T_ID  ASC

PRINT   ' '
PRINT   'One-Third Through TRADE_REQUEST'
SELECT  TOP (1) TR_T_ID
FROM    TRADE_REQUEST
WHERE   TR_T_ID     >= @id1
ORDER   BY TR_T_ID  ASC

PRINT   ' '
PRINT   'Two-Thirds Through TRADE_REQUEST'
SELECT  TOP (1) TR_T_ID
FROM    TRADE_REQUEST
WHERE   TR_T_ID     <= @id2
ORDER   BY TR_T_ID  DESC

PRINT   ' '
PRINT   'Maximum Primary Key ID From TRADE_REQUEST'
SELECT  TOP (1) TR_T_ID
FROM    TRADE_REQUEST
ORDER   BY TR_T_ID  DESC
GO

PRINT   ' '
PRINT   'TPC-E Growing Tables End'
SELECT  CONVERT(CHAR(30), GETDATE(), 21)
PRINT   ' '
PRINT   ''
PRINT   '---------------------------------'
PRINT   '|  DB Primary Key Check - End   |'
PRINT   '---------------------------------'
PRINT   ' '
SELECT  CONVERT(CHAR(30), GETDATE(), 21)
GO

-- set the MAX Degree of Parallelism to 1 for this runtime
sp_configure    'max degree of parallelism',1
GO

-- reconfigure the server so the MAXDOP will take effect
RECONFIGURE WITH OVERRIDE
GO

