Skip to main content

Delete Tables

Run this on the database to clear the tables.

DECLARE @DropFKSQL NVARCHAR(MAX) = '';

-- Find foreign keys referencing the tables we want to drop

SELECT @DropFKSQL += 'ALTER TABLE ' + QUOTENAME(OBJECT\_NAME(fk.parent\_object\_id)) +

' DROP CONSTRAINT ' + QUOTENAME(fk.name) + '; '

FROM sys.foreign_keys AS fk

WHERE fk.referenced_object_id IN (

SELECT object\_id

FROM sys.objects

WHERE name IN (

'PS_BrandDiscounts', 'PS_CategoryDiscounts', 'PS_ClientTypes',

'PS_DateFrames', 'PS_ItemDiscounts', 'PS_ItemTypeDiscounts',

'PS_MenuGroupItem', 'PS_OrderTypes', 'PS_PriceSchedule',

'PS_RequiredBrands', 'PS_RequiredCategories', 'PS_RequiredItems',

'PS_RequiredItemTypes', 'PS_TimeFrames', 'PS_WeekDays',

'tblProducts', 'PG_PromptGroups', 'PG_PromptMenuItems',

'PG_PromptSubGroups', 'PG_Selected_PromptSubGroups',

'tblProductPricing', 'tblProductPriceCategory',

'tblUnitType', 'tblUnitConversion', 'tblUnitAmountType',

'tblTax', 'tblShortInventory', 'PB_Main',

'PB_Main_Associations', 'Menu_ClientTypes', 'Menu_DateFrames',

'Menu_MenuItems', 'Menu_OrderTypes', 'Menu_TimeFrames',

'Menu_WeekDays', 'ItemType', 'ItemType_Categories',

'ItemType_DisplayAssignment', 'DisplayMenu', 'Stores' -- Added Stores

)

);

-- Execute the drop foreign key constraints

IF @DropFKSQL <> ''

BEGIN

EXEC sp\_executesql @DropFKSQL;

END

-- Step 3: Drop the existing tables

DECLARE @DropSQL NVARCHAR(MAX) = '';

DECLARE @TableName NVARCHAR(128);