if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_CatBrand_Brand]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[CatBrand] DROP CONSTRAINT FK_CatBrand_Brand
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_CatBrand_Category]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[CatBrand] DROP CONSTRAINT FK_CatBrand_Category
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_CatProduct_Category]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[CatProduct] DROP CONSTRAINT FK_CatProduct_Category
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_ProductField_CategoryField]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[ProductField] DROP CONSTRAINT FK_ProductField_CategoryField
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_CouponMember_Coupon]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[CouponMember] DROP CONSTRAINT FK_CouponMember_Coupon
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_CouponMember_Member]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[CouponMember] DROP CONSTRAINT FK_CouponMember_Member
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_News_Article_News_Category]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[News_Article] DROP CONSTRAINT FK_News_Article_News_Category
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_OrderProduct_Orders]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[OrderProduct] DROP CONSTRAINT FK_OrderProduct_Orders
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_CatProduct_Product]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[CatProduct] DROP CONSTRAINT FK_CatProduct_Product
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[T_Update_Member_Finance]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[T_Update_Member_Finance]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[T_Delete_Agent]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[T_Delete_Agent]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[T_Update_Agent_Status]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[T_Update_Agent_Status]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[T_Update_Product]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[T_Update_Product]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[T_Update_CatProduct_CatBrand]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[T_Update_CatProduct_CatBrand]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[NewProductDelete]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[NewProductDelete]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[T_Delete_CatProduct]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[T_Delete_CatProduct]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[T_Update_Product_Storage]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[T_Update_Product_Storage]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[T_Update_Product_StorageCheck]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[T_Update_Product_StorageCheck]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Pr_RunSQL]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Pr_RunSQL]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[StoredProcedureconfig]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[StoredProcedureconfig]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[listpagetext]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[listpagetext]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AgencyIDFinance_1]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[AgencyIDFinance_1]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AgencyIDFinance_2]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[AgencyIDFinance_2]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AgencyIDFinance]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[AgencyIDFinance]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Non_Payment]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[Non_Payment]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AD]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ADCategory]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ADCategory]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Admin]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Admin]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AdvancePayment]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AdvancePayment]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AgencyDrawing]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AgencyDrawing]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AgencyFinance]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AgencyFinance]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Agent]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Agent]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AgentDiscount]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AgentDiscount]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Article]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Article]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ArticleCategory]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ArticleCategory]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Brand]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Brand]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Bulletin]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Bulletin]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CardContent]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CardContent]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CatBrand]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CatBrand]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CatProduct]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CatProduct]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Catalogue]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Catalogue]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CatalogueVersion]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CatalogueVersion]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Category]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Category]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CategoryField]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CategoryField]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Config]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Config]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Coupon]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Coupon]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CouponMember]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CouponMember]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Currency]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Currency]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CustomFieldItem]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CustomFieldItem]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Email]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Email]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Favorite]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Favorite]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FiltrateIP]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[FiltrateIP]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FlashAD]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[FlashAD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Gift]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Gift]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GiftOrder]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[GiftOrder]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GiftOrderItem]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[GiftOrderItem]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Link]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Link]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Member]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Member]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MemberGroup]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[MemberGroup]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[NavBar]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[NavBar]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[NewBid]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[NewBid]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[NewBuy]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[NewBuy]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[NewNumber]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[NewNumber]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[NewProduct]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[NewProduct]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[News_Article]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[News_Article]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[News_Category]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[News_Category]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[OrderProduct]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[OrderProduct]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[OrderProductItem]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[OrderProductItem]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[OrderReview]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[OrderReview]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Orders]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Orders]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Payment]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Payment]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Poll]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Poll]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Product]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Product]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProductCustomField]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ProductCustomField]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProductField]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ProductField]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ReceiverAddress]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ReceiverAddress]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Review]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Review]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Shipping]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Shipping]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ShippingArea]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ShippingArea]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ShippingExpression]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ShippingExpression]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ShippingFree]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ShippingFree]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ShippingPrice]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ShippingPrice]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ShoppingCart]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ShoppingCart]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ShoppingCartProductItems]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ShoppingCartProductItems]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Storage]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Storage]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[StorageCheck]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[StorageCheck]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Template]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Template]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Union]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Union]