hi guys,i have been supplied with a sql database and sql scripts from another company and one of those scripts is to clean out the database, however when the script is run it produces an errorServer: Msg 547, Level 16, State 1, Line 1DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_AppRespondantFiles_AppRespondants'. The conflict occurred in database 'CMS(vanilla)', table 'AppRespondantFiles', column 'AppRespondantsID'.The statement has been terminated.
Ive tried contacting the other developer many times and they never get back to me. I have no idea why it does - so im hoping that some gurus will come and help me out please
Thanks in advance guysandy /**************************************************************************************************** ********* Purpose: This script will clear and reset the CMS tables**************************************************************************************************** *********/-- Instance ID of the Home InstanceDECLARE @intHomeInstanceID intSET @intHomeInstanceID = 1 -- Start ID from which to begin deleting auto-generated Secuirty ItemsDECLARE @intSecurityItemID intSET @intSecurityItemID = 102 -- Start ID from which to begin deleting auto-generated Secuirty ItemsDECLARE @intNavMenuItemID intSET @intNavMenuItemID = 102 -- Delete Logs & Security DELETE FROM SecurityUsers_SecurityRoles WHERE SecurityUsersID <> 1 DELETE FROM LogEvents DELETE FROM SecurityUsers WHERE ID <> 1 -- Delete Versions except home DELETE FROM CMVersionRelationships DELETE FROM CMVersionAttributeFIlesWHERE CMVersionAttributeID IN ( SELECT ID FROM CMVersionAttributes WHERE CMVersionID NOT IN ( SELECT ID FROM CMVersions WHERE CMInstanceID=@intHomeInstanceID ) ) DELETE FROM CMVersionAttributeValuesWHERE CMVersionAttributeID IN ( SELECT ID FROM CMVersionAttributes WHERE CMVersionID NOT IN ( SELECT ID FROM CMVersions WHERE CMInstanceID=@intHomeInstanceID ) ) DELETE FROM CMVersionAttributesWHERE CMVersionID NOT IN ( SELECT ID FROM CMVersions WHERE CMInstanceID=@intHomeInstanceID ) DELETE FROM CMVersionFriendlyURLWHERE CMVersionID NOT IN ( SELECT ID FROM CMVersions WHERE CMInstanceID=@intHomeInstanceID ) DELETE FROM CMVersionMetaTagsWHERE CMVersionID NOT IN ( SELECT ID FROM CMVersions WHERE CMInstanceID=@intHomeInstanceID ) DELETE FROM CMVersions WHERE CMInstanceID<>@intHomeInstanceID -- Delete CMFiles and Folders DELETE FROM CMFileImages DELETE FROM CMFilesWHERE ID NOT IN ( SELECT DISTINCT CMFileID FROM CMVersionAttributeFiles ) DELETE FROM CMFoldersWHERE ID NOT IN ( SELECT DISTINCT CMFolderID FROM CMFiles ) -- Delete Applications DELETE FROM AppResponses DELETE FROM AppRespondants --DELETE FROM AppQuestionsOptions DELETE FROM AppQuestions DELETE FROM AppQuestionSections DELETE FROM AppApplications -- Delete Instances / Security / Navigation DELETE FROM NavMenuItems_SecurityItems WHERE SecurityItemsID > @intSecurityItemID DELETE FROM CMInstances WHERE SecurityItemID > @intSecurityItemID OR SecurityItemID IS NULL AND ID <> @intHomeInstanceID DELETE FROM SecurityItems_SecurityAreas WHERE SecurityItemsID > @intSecurityItemID DELETE FROM SecurityItems WHERE ID > @intSecurityItemID DELETE FROM NavMenuItems WHERE ID > @intNavMenuItemID -- Delete Objects DELETE FROM CMObjectAttributeValuesWHERE CMObjectsAttributeID IN ( SELECT ID FROM CMObjectAttributes WHERE CMObjectID NOT IN ( SELECT CMObjectID FROM CMInstances ) ) DELETE FROM CMObjectRelationshipAttributes DELETE FROM CMObjectRelationshipObjects DELETE FROM CMObjectRelationships DELETE FROM CMObjectAttributes WHERE CMObjectID NOT IN ( SELECT CMObjectID FROM CMInstances ) DELETE FROM CMObjectTemplates WHERE CMObjectID NOT IN ( SELECT CMObjectID FROM CMInstances ) DELETE FROM CMObjects WHERE ID NOT IN ( SELECT CMObjectID FROM CMInstances ) -- Re-generate Security Lookups exec spxSecurityPopulateLookups -- Re-seed tables /* * Resets the identity columns on all tables in the database (handy after you've cleared out a load of data * and you want to reuse the old IDs). * Note that this script doesnt bother checking whether a table actually has an identity column - it'll just * throw an error and move on if there isn't one. */ DECLARE @table VARCHAR(255) DECLARE tablelist CURSOR FOR SELECT [name] FROM dbo.sysobjects where type = 'U' OPEN tablelistFETCH NEXT FROM tablelist INTO @table WHILE @@FETCH_STATUS = 0BEGIN DBCC CHECKIDENT (@table, RESEED, 1) DBCC CHECKIDENT (@table, RESEED) FETCH NEXT FROM tablelist INTO @tableEND CLOSE tablelistDEALLOCATE tablelist