Created
May 11, 2019 01:29
-
-
Save emregulcan/fff9ea06c263723d5c10ec55fdaf126f to your computer and use it in GitHub Desktop.
Dynamics 365 CE (CRM) Data Export Service - Azure SQL Database Delete All Items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----------------------------------------------------------------- | |
-- Provide the value for the following parameters | |
DECLARE @prefix nvarchar(32) ='' | |
DECLARE @schema nvarchar(32) ='dbo' | |
----------------------------------------------------------------- | |
DECLARE @sql nvarchar(max) = ''; | |
SELECT @sql += 'DROP TABLE ' + QUOTENAME([TABLE_SCHEMA]) + '.' + QUOTENAME([TABLE_NAME]) + ';' | |
FROM [INFORMATION_SCHEMA].[TABLES] | |
WHERE [TABLE_TYPE] = 'BASE TABLE' AND [TABLE_NAME] like @prefix + '_%' AND [TABLE_SCHEMA]= @schema; | |
PRINT @sql | |
EXEC SP_EXECUTESQL @sql; | |
PRINT 'Finished dropping all tables. Starting to drop all stored procedures now.' | |
SELECT @sql=''; | |
SELECT @sql += 'DROP PROCEDURE ' + QUOTENAME([ROUTINE_SCHEMA]) + '.' + QUOTENAME([ROUTINE_NAME]) + ';' | |
FROM [INFORMATION_SCHEMA].[ROUTINES] | |
WHERE [ROUTINE_TYPE] = 'PROCEDURE' AND [ROUTINE_NAME] like @prefix + '_%' AND [ROUTINE_SCHEMA]= @schema; | |
PRINT @sql | |
EXEC SP_EXECUTESQL @sql; | |
PRINT 'Finished dropping all stored procedures. Starting to drop all types now.' | |
SELECT @sql=''; | |
SELECT @sql += 'DROP TYPE ' + QUOTENAME(SCHEMA_NAME([SCHEMA_ID])) + '.' + QUOTENAME([NAME]) + ';' | |
FROM SYS.TYPES | |
WHERE is_user_defined = 1 AND [NAME] LIKE @prefix + '_%' AND [SCHEMA_ID]=SCHEMA_ID(@schema); | |
PRINT @sql | |
EXEC SP_EXECUTESQL @sql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IMPORTANT
This SQL script copied from Microsoft official documentation on 2019-05-10 , please check and validate before use, https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/administering-dynamics-365/mt744592(v=crm.8)#how-to-delete-all-data-export-profile-tables-and-stored-procedures