1
I have a database that I need to delete all records that exist in it, except one user that is in the table User linked to another table (Aspnetusers). I’ve made a few attempts to SSMS, but always run into problems of reference and conflicts.
For example, I’ve run the following command:
USE [dbTeste]
GO
DELETE FROM [dbo].[AspNetUsers]
WHERE Id !='52252ba2-8312-4650-b829-c611e2c3cfdb'
GO
Message 547, Level 16, Status 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 log in and delete all records from the other tables.
Friend, this error refers to other tables that receive the PK of this user, to erase the users, it will need to erase the PK records of the users.
– Gabriel Leme