I have a database that I need to delete all the records that exist in it, except a user who is in the User table with a link to another table ( AspNetUsers ). I have already made a few attempts at SSMS , but I always encounter references and conflicts.
For example, I ran the following command:
USE [dbTeste]
GO
DELETE FROM [dbo].[AspNetUsers]
WHERE Id !='52252ba2-8312-4650-b829-c611e2c3cfdb'
GO
Message 547, Level 16, State 0, Line 4 The DELETE statement conflicted with the REFERENCE constraint "FK_dbo.Usuario_dbo.AspNetUsers_ApplicationUser_Id". The conflict occurred in database "matina", table "dbo.Usuario", column 'ApplicationUser_Id'. The statement has been terminated.
I just need to keep this user, which I use to login and delete all the records from the other tables.