How do I do the following copy a column of a table to another table

0

I explain in database how I do if in the database users.dbo.Users_Master I have 18,000 accounts or more and made the mistake of adding 2,000,000 points in the points column but before I had a backup which shows that the maximum of any user was 63,000 points now I need to rollback the column specifies Points if I do restore I will put the backup copy as: Backup.dbo.Users_Master

I imagine that it will be an UPDATE through a select so that only this column will pass, try this but it does not work. I REPEAT I DO NOT WANT TO DO SUMAS OR REMAINS I just want to Copy through an UPDATE the Column SELECTED I thought so:

UPDATE b
SET b.point = o.point
FROM Usuarios.dbo.Users_Master  
INNER JOIN Respaldo.dbo.Users_Master 

But what I want to do is if the User No. 1 in Backup.dbo.Users_Master has 2 points this update the Users.dbo.Users_Master User No. 1 that has 20,000 Points so in all the records that have the database with a single script I had to do this step by step to be able to update all the columns of Users

SELECT Point, Usuario FROM Respaldo.dbo.Users_Master WHERE Point > 10000

Copy the result column by column with MauseRecorder so that Automatico Calro no human could with so much record

Then launch this UPDATE

UPDATE Usuarios.dbo.Users_Master SET Point = 'PEGUE uno x uno los resutados del Setect respaldo' WHERE Usuario = 'Pegue 1x1 cada Usuario Corespondiente a su puntos de respaldo'

There must be some shorter way to do this without copying or pasting 1 x One

The friend who gave me this Script did not work for me

UPDATE PS_GameData.dbo.Chars
    SET Family = PS_Restore.dbo.Chars.Family
    FROM PS_GameData.dbo.Chars
INNER JOIN PS_Restore.dbo.Chars
    ON PS_Restore.dbo.Chars.UserUID=PS_GameData.dbo.Chars.UserUID;

I get this error which I do not understand

Msg 1013, Level 16, State 1, Line 1
The objects "PS_Restore.dbo.Chars" and "PS_GameData.dbo.Chars" in the FROM clause have the same exposed names. Use correlation names to distinguish them.

Try this Other but I get an error because I want to copy ALL the record

UPDATE PS_GameData.dbo.Chars
    SET Family = (SELECT Family FROM PS_Restore.dbo.Chars),
        Job = (SELECT Job FROM PS_Restore.dbo.Chars)

The error it gives me is:

Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.

Success I found this Script works perfectly for me now I would like to know why the Iner Join never worked for me

UPDATE PS_GameData.dbo.Chars
    SET Family = b.Family,
        Job = b.Job
    FROM    PS_Restore.dbo.Chars b
WHERE PS_GameData.dbo.Chars.CharID = b.CharID;  
    
asked by Juan Carlos Villamizar Alvarez 14.08.2016 в 23:54
source

2 answers

0

The JOIN did not work for you because the database manager does not know if the Family column is from the database PS_Restore.dbo.Chars or PS_GameData.dbo.Chars

To solve this and make your sentence of UPDATE in conjunction with the INNER JOIN you must alias each table:

UPDATE PS_GameData.dbo.Chars
    SET PS_GameData.dbo.Chars.Family = B.Family
FROM PS_GameData.dbo.Chars A
    INNER JOIN PS_Restore.dbo.Chars B
        ON B.UserUID = A.Chars.UserUID;
    
answered by 12.12.2016 / 06:38
source
0

In the JOIN you lack the condition of relationship between the tables:

UPDATE Usuarios.dbo.Users_Master
    SET Point = Respaldo.dbo.Users_Master.Point
    FROM Usuarios.dbo.Users_Master
INNER JOIN Respaldo.dbo.Users_Master
    ON Respaldo.dbo.Users_Master.Usuario=Usuarios.dbo.Users_Master.Usuario;
    
answered by 16.08.2016 в 16:21