Restarurar DataBase Data NOT Pre-Existing SQL

0

I have current records in a database called A_Restaurate I have Pedro, Jose, saul, Mengano, So and so in order over a thousand Old Accounts records I want to restore all that data to a New Data Base called EN_USO but this has some records with the same User, I do not want to copy the same record twice. How can I do this without repeating the same record?

INSERT [DASEDATOS_En USO].[dbo].[EN_USO](       
        [UserID],[Pw],[JoinDate],[Admin],[AdminLevel],[UseQueue],[Status],[Leave],[LeaveDate],[UserType],[UserIp],[ModiIp],[ModiDate],[Point],[Enpassword],[Birth],[email],[Activation],[pais],[mes],[dia],[anio],[nombre],[apellido],[MotivoBan],[GS],[Contador],[Activo],[FechaDuper],[FinBan],[Verifi],[Protector],[Staff],[DEV],[Email_viejo],[UserID_Viejo],[Point2])
SELECT  [UserID],[Pw],[JoinDate],[Admin],[AdminLevel],[UseQueue],[Status],[Leave],[LeaveDate],[UserType],[UserIp],[ModiIp],[ModiDate],150000 ,[Enpassword],[Birth],[email],[Activation],[pais],[mes],[dia],[anio],[nombre],[apellido],[MotivoBan],[GS],[Contador],[Activo],[FechaDuper],[FinBan],[Verifi],[Protector],[Staff],[DEV],[Email_viejo],[UserID_Viejo],15000 
FROM [DASEDATOS_Arestaurar].[dbo].[A_Restaurar]
    
asked by Juan Carlos Villamizar Alvarez 20.10.2018 в 23:27
source

1 answer

1

The Where with the clause NOT EXISTS will only make the entry of the data if the UserId does not exist in the table where you will do the Insert . (When answering I was assuming that the UserId is the only key of the table)

INSERT [DASEDATOS_En USO].[dbo].[EN_USO](       
        [UserID],[Pw],[JoinDate],[Admin],[AdminLevel],[UseQueue],[Status],[Leave],[LeaveDate],[UserType],[UserIp],[ModiIp],[ModiDate],[Point],[Enpassword],[Birth],[email],[Activation],[pais],[mes],[dia],[anio],[nombre],[apellido],[MotivoBan],[GS],[Contador],[Activo],[FechaDuper],[FinBan],[Verifi],[Protector],[Staff],[DEV],[Email_viejo],[UserID_Viejo],[Point2])
SELECT  [UserID],[Pw],[JoinDate],[Admin],[AdminLevel],[UseQueue],[Status],[Leave],[LeaveDate],[UserType],[UserIp],[ModiIp],[ModiDate],150000 ,[Enpassword],[Birth],[email],[Activation],[pais],[mes],[dia],[anio],[nombre],[apellido],[MotivoBan],[GS],[Contador],[Activo],[FechaDuper],[FinBan],[Verifi],[Protector],[Staff],[DEV],[Email_viejo],[UserID_Viejo],15000 
FROM [DASEDATOS_Arestaurar].[dbo].[A_Restaurar]

where NOT EXISTS (select userid 
from [DASEDATOS_En USO].[dbo].[EN_USO] a 
where a.userid = [DASEDATOS_Arestaurar].[dbo].[A_Restaurar].userid
)
    
answered by 21.10.2018 / 00:29
source