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

---
--- Set connection attributes
---
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
GO

-- ************************************
-- *** DROP FOREIGN KEY CONSTRAINTS ***
-- ************************************

-- *** ACCOUNT_PERMISSION ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_ACCOUNT_PERMISSION_CUSTOMER_ACCOUNT' )
	ALTER TABLE ACCOUNT_PERMISSION DROP CONSTRAINT FK_ACCOUNT_PERMISSION_CUSTOMER_ACCOUNT
GO

-- *** ADDRESS ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_ADDRESS_ZIP_CODE' )
    ALTER TABLE ADDRESS DROP CONSTRAINT FK_ADDRESS_ZIP_CODE
GO

-- *** BROKER ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_BROKER_STATUS' )
    ALTER TABLE BROKER DROP CONSTRAINT FK_BROKER_STATUS
GO

-- *** CASH_TRANSACTION ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_CASH_TRANSACTION_TRADE' )
    ALTER TABLE CASH_TRANSACTION DROP CONSTRAINT FK_CASH_TRANSACTION_TRADE
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_CASH_TRANSACTION_ACCOUNT' )
    ALTER TABLE CASH_TRANSACTION DROP CONSTRAINT FK_CASH_TRANSACTION_ACCOUNT
GO

-- *** CHARGE ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_CHARGE_TRADETYPE' )
    ALTER TABLE CHARGE DROP CONSTRAINT FK_CHARGE_TRADETYPE
GO

-- *** COMMISSION_RATE ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_COMMISSION_RATE_TRADETYPE' )
    ALTER TABLE COMMISSION_RATE DROP CONSTRAINT FK_COMMISSION_RATE_TRADETYPE
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_COMMISSION_RATE_EXCHANGE' )
    ALTER TABLE COMMISSION_RATE DROP CONSTRAINT FK_COMMISSION_RATE_EXCHANGE
GO

-- *** COMPANY ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_COMPANY_STATUS' )
    ALTER TABLE COMPANY DROP CONSTRAINT FK_COMPANY_STATUS
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_COMPANY_ADDRESS' )
    ALTER TABLE COMPANY DROP CONSTRAINT FK_COMPANY_ADDRESS
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_COMPANY_INDUSTRY' )
    ALTER TABLE COMPANY DROP CONSTRAINT FK_COMPANY_INDUSTRY
GO

-- *** COMPANY_COMPETITOR ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_COMPANY_COMP_COMPANY1' )
    ALTER TABLE COMPANY_COMPETITOR DROP CONSTRAINT FK_COMPANY_COMP_COMPANY1
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_COMPANY_COMP_COMPANY2' )
    ALTER TABLE COMPANY_COMPETITOR DROP CONSTRAINT FK_COMPANY_COMP_COMPANY2
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_COMPANY_COMP_INDUSTRY' )
    ALTER TABLE COMPANY_COMPETITOR DROP CONSTRAINT FK_COMPANY_COMP_INDUSTRY
GO

-- *** CUSTOMER ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_CUSTOMER_STATUS_TYPE' )
    ALTER TABLE CUSTOMER DROP CONSTRAINT FK_CUSTOMER_STATUS_TYPE
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_CUSTOMER_ADDRESS' )
    ALTER TABLE CUSTOMER DROP CONSTRAINT FK_CUSTOMER_ADDRESS
GO

-- *** CUSTOMER_ACCOUNT ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_CUSTOMER_ACCOUNT_BROKER' )
    ALTER TABLE CUSTOMER_ACCOUNT DROP CONSTRAINT FK_CUSTOMER_ACCOUNT_BROKER
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_CUSTOMER_ACCOUNT_CUSTOMER' )
    ALTER TABLE CUSTOMER_ACCOUNT DROP CONSTRAINT FK_CUSTOMER_ACCOUNT_CUSTOMER
GO

-- *** CUSTOMER_TAXRATE ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_CUSTOMER_TAXRATE_TAX' )
    ALTER TABLE CUSTOMER_TAXRATE DROP CONSTRAINT FK_CUSTOMER_TAXRATE_TAX
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_CUSTOMER_TAXRATE_CUSTOMER' )
    ALTER TABLE CUSTOMER_TAXRATE DROP CONSTRAINT FK_CUSTOMER_TAXRATE_CUSTOMER
GO

-- *** DAILY_MARKET ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_DAILY_MARKET_SECURITY' )
    ALTER TABLE DAILY_MARKET DROP CONSTRAINT FK_DAILY_MARKET_SECURITY
GO

-- *** EXCHANGE ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_EXCHANGE_ADDRESS' )
    ALTER TABLE EXCHANGE DROP CONSTRAINT FK_EXCHANGE_ADDRESS
GO

-- *** FINANCIAL ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_FINANCIAL_COMPANY' )
    ALTER TABLE FINANCIAL DROP CONSTRAINT FK_FINANCIAL_COMPANY
GO

-- *** HOLDING ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_HOLDING_TRADE' )
    ALTER TABLE HOLDING DROP CONSTRAINT FK_HOLDING_TRADE
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_HOLDING_HOLDING_SUMMARY' )
    ALTER TABLE HOLDING DROP CONSTRAINT FK_HOLDING_HOLDING_SUMMARY
GO

-- *** HOLDING_HISTORY ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_HOLDING_HISTORY_TRADE1' )
    ALTER TABLE HOLDING_HISTORY DROP CONSTRAINT FK_HOLDING_HISTORY_TRADE1
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_HOLDING_HISTORY_TRADE2' )
    ALTER TABLE HOLDING_HISTORY DROP CONSTRAINT FK_HOLDING_HISTORY_TRADE2
GO

-- *** HOLDING_SUMMARY ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_HOLDING_SUMMARY_ACCOUNT' )
    ALTER TABLE HOLDING_SUMMARY DROP CONSTRAINT FK_HOLDING_SUMMARY_ACCOUNT
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_HOLDING_SUMMARY_SECURITY' )
    ALTER TABLE HOLDING_SUMMARY DROP CONSTRAINT FK_HOLDING_SUMMARY_SECURITY
GO

-- *** INDUSTRY ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_INDUSTRY_SECTOR' )
    ALTER TABLE INDUSTRY DROP CONSTRAINT FK_INDUSTRY_SECTOR
GO

-- *** LAST_TRADE ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_LAST_TRADE_SECURITY' )
    ALTER TABLE LAST_TRADE DROP CONSTRAINT FK_LAST_TRADE_SECURITY
GO

-- *** NEWS_XREF ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_NEWS_XREF_NEWS_ITEM' )
    ALTER TABLE NEWS_XREF DROP CONSTRAINT FK_NEWS_XREF_NEWS_ITEM
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_NEWS_XREF_COMPANY' )
    ALTER TABLE NEWS_XREF DROP CONSTRAINT FK_NEWS_XREF_COMPANY
GO

-- *** SECURITY ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_SECURITY_STATUS' )
    ALTER TABLE SECURITY DROP CONSTRAINT FK_SECURITY_STATUS
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_SECURITY_EXCHANGE' )
    ALTER TABLE SECURITY DROP CONSTRAINT FK_SECURITY_EXCHANGE
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_SECURITY_COMPANY' )
    ALTER TABLE SECURITY DROP CONSTRAINT FK_SECURITY_COMPANY
GO

-- *** SETTLEMENT ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_SETTLEMENT_TRADE' )
    ALTER TABLE SETTLEMENT DROP CONSTRAINT FK_SETTLEMENT_TRADE
GO

-- *** TRADE ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_TRADE_STATUS' )
    ALTER TABLE TRADE DROP CONSTRAINT FK_TRADE_STATUS
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_TRADE_TRADETYPE' )
    ALTER TABLE TRADE DROP CONSTRAINT FK_TRADE_TRADETYPE
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_TRADE_SECURITY' )
    ALTER TABLE TRADE DROP CONSTRAINT FK_TRADE_SECURITY
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_TRADE_CUSTOMER_ACCOUNT' )
    ALTER TABLE TRADE DROP CONSTRAINT FK_TRADE_CUSTOMER_ACCOUNT
GO

-- *** TRADE_HISTORY ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_TRADE_HISTORY_TRADE' )
    ALTER TABLE TRADE_HISTORY DROP CONSTRAINT FK_TRADE_HISTORY_TRADE 
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_TRADE_HISTORY_STATUS' )
    ALTER TABLE TRADE_HISTORY DROP CONSTRAINT FK_TRADE_HISTORY_STATUS 
GO

-- *** TRADE_REQUEST ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_TRADE_REQUEST_TRADE' )
    ALTER TABLE TRADE_REQUEST DROP CONSTRAINT FK_TRADE_REQUEST_TRADE 
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_TRADE_REQUEST_TRADETYPE' )
    ALTER TABLE TRADE_REQUEST DROP CONSTRAINT FK_TRADE_REQUEST_TRADETYPE 
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_TRADE_REQUEST_SECURITY' )
    ALTER TABLE TRADE_REQUEST DROP CONSTRAINT FK_TRADE_REQUEST_SECURITY 
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_TRADE_REQUEST_BROKER' )
    ALTER TABLE TRADE_REQUEST DROP CONSTRAINT FK_TRADE_REQUEST_BROKER
GO

-- *** WATCH_ITEM ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_WATCH_ITEM_WATCHLIST' )
    ALTER TABLE WATCH_ITEM DROP CONSTRAINT FK_WATCH_ITEM_WATCHLIST
GO
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_WATCH_ITEM_SECURITY' )
    ALTER TABLE WATCH_ITEM DROP CONSTRAINT FK_WATCH_ITEM_SECURITY
GO

-- *** WATCH_LIST ***
IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'FK_WATCH_LIST_CUSTOMER' )
    ALTER TABLE WATCH_LIST DROP CONSTRAINT FK_WATCH_LIST_CUSTOMER
GO
